mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 05:05:42 +00:00 
			
		
		
		
	Add some unit testing
This commit is contained in:
		| @@ -11,6 +11,7 @@ from django.contrib.auth.models import Group | |||||||
| from InvenTree.status_codes import PurchaseOrderStatus | from InvenTree.status_codes import PurchaseOrderStatus | ||||||
|  |  | ||||||
| from .models import PurchaseOrder, PurchaseOrderLineItem | from .models import PurchaseOrder, PurchaseOrderLineItem | ||||||
|  | from .models import SalesOrder | ||||||
|  |  | ||||||
| import json | import json | ||||||
|  |  | ||||||
| @@ -59,6 +60,88 @@ class OrderListTest(OrderViewTestCase): | |||||||
|         self.assertEqual(response.status_code, 200) |         self.assertEqual(response.status_code, 200) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class SalesOrderCreate(OrderViewTestCase): | ||||||
|  |     """ | ||||||
|  |     Create a SalesOrder using the form view | ||||||
|  |     """ | ||||||
|  |  | ||||||
|  |     URL = reverse('so-create') | ||||||
|  |  | ||||||
|  |     def test_create_view(self): | ||||||
|  |         """ | ||||||
|  |         Retrieve the view for creating a sales order' | ||||||
|  |         """ | ||||||
|  |  | ||||||
|  |         response = self.client.get(self.URL, HTTP_X_REQUESTED_WITH='XMLHttpRequest') | ||||||
|  |  | ||||||
|  |         self.assertEqual(response.status_code, 200) | ||||||
|  |  | ||||||
|  |     def post(self, data, **kwargs): | ||||||
|  |  | ||||||
|  |         return self.client.post(self.URL, data, HTTP_X_REQUESTED_WITH='XMLHttpRequest', **kwargs) | ||||||
|  |  | ||||||
|  |     def test_post_error(self): | ||||||
|  |         """ | ||||||
|  |         POST with errors | ||||||
|  |         """ | ||||||
|  |  | ||||||
|  |         n = SalesOrder.objects.count() | ||||||
|  |  | ||||||
|  |         data = { | ||||||
|  |             'reference': '12345678', | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         response = self.post(data) | ||||||
|  |  | ||||||
|  |         data = json.loads(response.content) | ||||||
|  |  | ||||||
|  |         self.assertIn('form_valid', data.keys()) | ||||||
|  |  | ||||||
|  |         # Customer is not specified - should return False | ||||||
|  |         self.assertFalse(data['form_valid']) | ||||||
|  |  | ||||||
|  |         errors = json.loads(data['form_errors']) | ||||||
|  |  | ||||||
|  |         self.assertIn('customer', errors.keys()) | ||||||
|  |         self.assertIn('description', errors.keys()) | ||||||
|  |  | ||||||
|  |         # No new SalesOrder objects should have been created | ||||||
|  |         self.assertEqual(SalesOrder.objects.count(), n) | ||||||
|  |  | ||||||
|  |     def test_post_valid(self): | ||||||
|  |         """ | ||||||
|  |         POST a valid SalesOrder | ||||||
|  |         """ | ||||||
|  |  | ||||||
|  |         n = SalesOrder.objects.count() | ||||||
|  |  | ||||||
|  |         data = { | ||||||
|  |             'reference': '12345678', | ||||||
|  |             'customer': 4, | ||||||
|  |             'description': 'A description', | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         response = self.post(data) | ||||||
|  |  | ||||||
|  |         json_data = json.loads(response.content) | ||||||
|  |  | ||||||
|  |         self.assertTrue(json_data['form_valid']) | ||||||
|  |  | ||||||
|  |         # Create another SalesOrder, this time with a target date | ||||||
|  |         data = { | ||||||
|  |             'reference': '12345679', | ||||||
|  |             'customer': 4, | ||||||
|  |             'description': 'Another order, this one with a target date!', | ||||||
|  |             'target_date': '2020-12-25', | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         response = self.post(data) | ||||||
|  |  | ||||||
|  |         json_data = json.loads(response.content) | ||||||
|  |  | ||||||
|  |         self.assertEqual(SalesOrder.objects.count(), n + 2) | ||||||
|  |  | ||||||
|  |  | ||||||
| class POTests(OrderViewTestCase): | class POTests(OrderViewTestCase): | ||||||
|     """ Tests for PurchaseOrder views """ |     """ Tests for PurchaseOrder views """ | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user