mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Tests for stock serialization form
This commit is contained in:
parent
34bfdea4b5
commit
6f8c3454f3
@ -4,6 +4,8 @@ from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
import json
|
||||
|
||||
|
||||
class StockViewTestCase(TestCase):
|
||||
|
||||
@ -128,3 +130,36 @@ class StockItemTest(StockViewTestCase):
|
||||
# Copy from an invalid item, invalid location
|
||||
response = self.client.get(reverse('stock-item-create'), {'location': 999, 'copy': 9999}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_serialize_item(self):
|
||||
# Test the serialization view
|
||||
|
||||
url = reverse('stock-item-serialize', args=(100,))
|
||||
|
||||
# GET the form
|
||||
response = self.client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
data_valid = {
|
||||
'quantity': 5,
|
||||
'serial_numbers': '1-5',
|
||||
'destination': 4,
|
||||
'notes': 'Serializing stock test'
|
||||
}
|
||||
|
||||
data_invalid = {
|
||||
'quantity': 4,
|
||||
'serial_numbers': 'dd-23-adf',
|
||||
'destination': 'blorg'
|
||||
}
|
||||
|
||||
# POST
|
||||
response = self.client.post(url, data_valid, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
data = json.loads(response.content)
|
||||
self.assertTrue(data['form_valid'])
|
||||
|
||||
response = self.client.post(url, data_invalid, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
data = json.loads(response.content)
|
||||
self.assertFalse(data['form_valid'])
|
||||
|
@ -491,10 +491,10 @@ class StockItemSerialize(AjaxUpdateView):
|
||||
|
||||
item = self.get_object()
|
||||
|
||||
quantity = request.POST.get('quantity', None)
|
||||
quantity = request.POST.get('quantity', 0)
|
||||
serials = request.POST.get('serial_numbers', '')
|
||||
dest_id = request.POST.get('destination', None)
|
||||
notes = request.POST.get('note', None)
|
||||
notes = request.POST.get('note', '')
|
||||
user = request.user
|
||||
|
||||
valid = True
|
||||
@ -509,6 +509,7 @@ class StockItemSerialize(AjaxUpdateView):
|
||||
except ValidationError as e:
|
||||
form.errors['serial_numbers'] = e.messages
|
||||
valid = False
|
||||
numbers = []
|
||||
|
||||
if valid:
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user