mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
d319c79abb
@ -152,7 +152,8 @@ REST_FRAMEWORK = {
|
|||||||
'rest_framework.authentication.BasicAuthentication',
|
'rest_framework.authentication.BasicAuthentication',
|
||||||
'rest_framework.authentication.SessionAuthentication',
|
'rest_framework.authentication.SessionAuthentication',
|
||||||
'rest_framework.authentication.TokenAuthentication',
|
'rest_framework.authentication.TokenAuthentication',
|
||||||
)
|
),
|
||||||
|
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'
|
||||||
}
|
}
|
||||||
|
|
||||||
WSGI_APPLICATION = 'InvenTree.wsgi.application'
|
WSGI_APPLICATION = 'InvenTree.wsgi.application'
|
||||||
|
27
InvenTree/InvenTree/test_views.py
Normal file
27
InvenTree/InvenTree/test_views.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
""" Unit tests for the main web views """
|
||||||
|
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
class ViewTests(TestCase):
|
||||||
|
""" Tests for various top-level views """
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
|
||||||
|
# Create a user
|
||||||
|
User = get_user_model()
|
||||||
|
User.objects.create_user('username', 'user@email.com', 'password')
|
||||||
|
|
||||||
|
self.client.login(username='username', password='password')
|
||||||
|
|
||||||
|
def test_api_doc(self):
|
||||||
|
""" Test that the api-doc view works """
|
||||||
|
|
||||||
|
api_url = os.path.join(reverse('index'), 'api-doc') + '/'
|
||||||
|
|
||||||
|
response = self.client.get(api_url)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
@ -4,6 +4,8 @@ from django.test import TestCase
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
class StockViewTestCase(TestCase):
|
class StockViewTestCase(TestCase):
|
||||||
|
|
||||||
@ -128,3 +130,43 @@ class StockItemTest(StockViewTestCase):
|
|||||||
# Copy from an invalid item, invalid location
|
# Copy from an invalid item, invalid location
|
||||||
response = self.client.get(reverse('stock-item-create'), {'location': 999, 'copy': 9999}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
response = self.client.get(reverse('stock-item-create'), {'location': 999, 'copy': 9999}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||||
self.assertEqual(response.status_code, 200)
|
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'])
|
||||||
|
|
||||||
|
# Try again to serialize with the same numbers
|
||||||
|
response = self.client.post(url, data_valid, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
data = json.loads(response.content)
|
||||||
|
self.assertFalse(data['form_valid'])
|
||||||
|
|
||||||
|
# POST with invalid data
|
||||||
|
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'])
|
||||||
|
@ -267,6 +267,9 @@ class StockTest(TestCase):
|
|||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
item.serializeStock(5, [1, 2, 3, 4, 5], self.user)
|
item.serializeStock(5, [1, 2, 3, 4, 5], self.user)
|
||||||
|
|
||||||
|
with self.assertRaises(ValidationError):
|
||||||
|
item.serializeStock(5, [1, 2, 3], self.user)
|
||||||
|
|
||||||
# Pick a StockItem which can actually be serialized
|
# Pick a StockItem which can actually be serialized
|
||||||
item = StockItem.objects.get(pk=100)
|
item = StockItem.objects.get(pk=100)
|
||||||
|
|
||||||
@ -284,7 +287,7 @@ class StockTest(TestCase):
|
|||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
item.serializeStock(3, "hello", self.user)
|
item.serializeStock(3, "hello", self.user)
|
||||||
|
|
||||||
def test_seiralize_stock_valid(self):
|
def test_serialize_stock_valid(self):
|
||||||
""" Perform valid stock serializations """
|
""" Perform valid stock serializations """
|
||||||
|
|
||||||
# There are 10 of these in stock
|
# There are 10 of these in stock
|
||||||
|
@ -491,10 +491,10 @@ class StockItemSerialize(AjaxUpdateView):
|
|||||||
|
|
||||||
item = self.get_object()
|
item = self.get_object()
|
||||||
|
|
||||||
quantity = request.POST.get('quantity', None)
|
quantity = request.POST.get('quantity', 0)
|
||||||
serials = request.POST.get('serial_numbers', '')
|
serials = request.POST.get('serial_numbers', '')
|
||||||
dest_id = request.POST.get('destination', None)
|
dest_id = request.POST.get('destination', None)
|
||||||
notes = request.POST.get('note', None)
|
notes = request.POST.get('note', '')
|
||||||
user = request.user
|
user = request.user
|
||||||
|
|
||||||
valid = True
|
valid = True
|
||||||
@ -509,6 +509,7 @@ class StockItemSerialize(AjaxUpdateView):
|
|||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
form.errors['serial_numbers'] = e.messages
|
form.errors['serial_numbers'] = e.messages
|
||||||
valid = False
|
valid = False
|
||||||
|
numbers = []
|
||||||
|
|
||||||
if valid:
|
if valid:
|
||||||
try:
|
try:
|
||||||
@ -517,7 +518,7 @@ class StockItemSerialize(AjaxUpdateView):
|
|||||||
messages = e.message_dict
|
messages = e.message_dict
|
||||||
|
|
||||||
for k in messages.keys():
|
for k in messages.keys():
|
||||||
if k in ['quantity', 'destionation', 'serial_numbers']:
|
if k in ['quantity', 'destination', 'serial_numbers']:
|
||||||
form.errors[k] = messages[k]
|
form.errors[k] = messages[k]
|
||||||
else:
|
else:
|
||||||
form.non_field_errors = messages[k]
|
form.non_field_errors = messages[k]
|
||||||
|
Loading…
Reference in New Issue
Block a user