From 087492faf8a2b942e712a5ccfeac8e2abb5f9fa6 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 15 Aug 2019 21:49:40 +1000 Subject: [PATCH] More build tests --- .coveragerc | 2 +- InvenTree/build/tests.py | 48 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/.coveragerc b/.coveragerc index b6b5f5a09d..409c378cac 100644 --- a/.coveragerc +++ b/.coveragerc @@ -4,7 +4,7 @@ omit = # Do not run coverage on migration files */migrations/* InvenTree/manage.py - InvenTree/secret.py + InvenTree/setup.py InvenTree/InvenTree/middleware.py InvenTree/InvenTree/utils.py InvenTree/InvenTree/wsgi.py diff --git a/InvenTree/build/tests.py b/InvenTree/build/tests.py index 6816b93fcd..0092cab091 100644 --- a/InvenTree/build/tests.py +++ b/InvenTree/build/tests.py @@ -221,6 +221,32 @@ class TestBuildViews(TestCase): # url = reverse('build-item-edit') pass + def test_build_complete(self): + """ Test the build completion form """ + + url = reverse('build-complete', args=(1,)) + + # Test without confirmation + response = self.client.post(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest') + self.assertEqual(response.status_code, 200) + + data = json.loads(response.content) + self.assertFalse(data['form_valid']) + + # Test with confirmation, valid location + response = self.client.post(url, {'confirm': 1, 'location': 1}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') + self.assertEqual(response.status_code, 200) + + data = json.loads(response.content) + self.assertTrue(data['form_valid']) + + # Test with confirmation, invalid location + response = self.client.post(url, {'confirm': 1, 'location': 9999}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') + self.assertEqual(response.status_code, 200) + + data = json.loads(response.content) + self.assertFalse(data['form_valid']) + def test_build_cancel(self): """ Test the build cancellation form """ @@ -231,7 +257,6 @@ class TestBuildViews(TestCase): self.assertEqual(response.status_code, 200) data = json.loads(response.content) - self.assertFalse(data['form_valid']) b = Build.objects.get(pk=1) @@ -245,4 +270,23 @@ class TestBuildViews(TestCase): self.assertTrue(data['form_valid']) b = Build.objects.get(pk=1) - self.assertEqual(b.status, 30) # Build status is now CANCELLED \ No newline at end of file + self.assertEqual(b.status, 30) # Build status is now CANCELLED + + def test_build_unallocate(self): + """ Test the build unallocation view (ajax form) """ + + url = reverse('build-unallocate', args=(1,)) + + # Test without confirmation + response = self.client.post(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest') + self.assertEqual(response.status_code, 200) + + data = json.loads(response.content) + self.assertFalse(data['form_valid']) + + # Test with confirmation + response = self.client.post(url, {'confirm': 1}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') + self.assertEqual(response.status_code, 200) + + data = json.loads(response.content) + self.assertTrue(data['form_valid'])