From 59e7474f75523e9c9c8ebd299997caa650816d6b Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 31 Aug 2020 20:09:43 +1000 Subject: [PATCH] Stock: More unit tests - Add some more tests (would have caught a bug that was there already, darn it) --- InvenTree/stock/test_api.py | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/InvenTree/stock/test_api.py b/InvenTree/stock/test_api.py index cd598e8538..47f2e5fcb1 100644 --- a/InvenTree/stock/test_api.py +++ b/InvenTree/stock/test_api.py @@ -81,6 +81,59 @@ class StockItemTest(StockAPITestCase): response = self.client.get(self.list_url, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) + def test_stock_item_create(self): + """ + Test creation of a StockItem via the API + """ + + # POST with an empty part reference + + response = self.client.post( + self.list_url, + data={ + 'quantity': 10, + 'location': 1 + } + ) + + self.assertContains(response, 'This field is required', status_code=status.HTTP_400_BAD_REQUEST) + + # POST with an invalid part reference + + response = self.client.post( + self.list_url, + data={ + 'quantity': 10, + 'location': 1, + 'part': 10000000, + } + ) + + self.assertContains(response, 'does not exist', status_code=status.HTTP_400_BAD_REQUEST) + + # POST without quantity + response = self.client.post( + self.list_url, + data={ + 'part': 1, + 'location': 1, + } + ) + + self.assertContains(response, 'This field is required', status_code=status.HTTP_400_BAD_REQUEST) + + # POST with quantity and part and location + response = self.client.post( + self.list_url, + data={ + 'part': 1, + 'location': 1, + 'quantity': 10, + } + ) + + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + class StocktakeTest(StockAPITestCase): """