From e7685951e1d271b07df0e4a0681a2404806f4028 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 27 Apr 2019 15:24:30 +1000 Subject: [PATCH] Add (simple) test cases for Stock API - Still a lot of work to do here --- InvenTree/stock/test_api.py | 65 +++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 InvenTree/stock/test_api.py diff --git a/InvenTree/stock/test_api.py b/InvenTree/stock/test_api.py new file mode 100644 index 0000000000..c526116e91 --- /dev/null +++ b/InvenTree/stock/test_api.py @@ -0,0 +1,65 @@ +from rest_framework.test import APITestCase +from rest_framework import status +from django.urls import reverse +from django.contrib.auth import get_user_model + +from .models import StockLocation, StockItem + + +class StockLocationTest(APITestCase): + """ + Series of API tests for the StockLocation API + """ + list_url = reverse('api-location-list') + + def setUp(self): + # Create a user for auth + User = get_user_model() + User.objects.create_user('testuser', 'test@testing.com', 'password') + self.client.login(username='testuser', password='password') + + # Add some stock locations + StockLocation.objects.create(name='top', description='top category') + + def test_list(self): + # Check that we can request the StockLocation list + response = self.client.get(self.list_url, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertGreaterEqual(len(response.data), 1) + + def test_add(self): + # Check that we can add a new StockLocation + data = { + 'parent': 1, + 'name': 'Location', + 'description': 'Another location for stock' + } + response = self.client.post(self.list_url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + + +class StockItemTest(APITestCase): + """ + Series of API tests for the StockItem API + """ + + list_url = reverse('api-stock-list') + + def detail_url(self, pk): + return revere('api-stock-detail', kwargs={'pk': pk}) + + def setUp(self): + # Create a user for auth + User = get_user_model() + User.objects.create_user('testuser', 'test@testing.com', 'password') + self.client.login(username='testuser', password='password') + + # Create some stock locations + top = StockLocation.objects.create(name='A', description='top') + + StockLocation.objects.create(name='B', description='location b', parent=top) + StockLocation.objects.create(name='C', description='location c', parent=top) + + def test_get_stock_list(self): + response = self.client.get(self.list_url, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK)