mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Tests for part creation
- Need more tests for POST action
This commit is contained in:
parent
51e4a4c006
commit
3a87cd866c
@ -85,10 +85,10 @@ class PartDetailTest(PartViewTestCase):
|
||||
self.assertIn('streaming_content', dir(response))
|
||||
|
||||
|
||||
class PartEditTest(PartViewTestCase):
|
||||
""" Tests for Part editing form """
|
||||
class PartTests(PartViewTestCase):
|
||||
""" Tests for Part forms """
|
||||
|
||||
def test_get_edit(self):
|
||||
def test_part_edit(self):
|
||||
response = self.client.get(reverse('part-edit', args=(1,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
@ -101,6 +101,28 @@ class PartEditTest(PartViewTestCase):
|
||||
self.assertIn('html_form', data)
|
||||
self.assertIn('"title":', data)
|
||||
|
||||
def test_part_create(self):
|
||||
""" Launch form to create a new part """
|
||||
response = self.client.get(reverse('part-create'), {'category': 1}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
# And again, with an invalid category
|
||||
response = self.client.get(reverse('part-create'), {'category': 9999}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
# And again, with no category
|
||||
response = self.client.get(reverse('part-create'), {'name': 'Test part'}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_part_duplicate(self):
|
||||
""" Launch form to duplicate part """
|
||||
|
||||
# First try with an invalid part
|
||||
response = self.client.get(reverse('part-duplicate', args=(9999,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.client.get(reverse('part-duplicate', args=(1,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
class PartAttachmentTests(PartViewTestCase):
|
||||
|
||||
|
@ -295,7 +295,7 @@ class PartDuplicate(AjaxCreateView):
|
||||
def get_part_to_copy(self):
|
||||
try:
|
||||
return Part.objects.get(id=self.kwargs['pk'])
|
||||
except Part.DoesNotExist:
|
||||
except (Part.DoesNotExist, ValueError):
|
||||
return None
|
||||
|
||||
def get_context_data(self):
|
||||
@ -419,7 +419,7 @@ class PartCreate(AjaxCreateView):
|
||||
if cat_id:
|
||||
try:
|
||||
context['category'] = PartCategory.objects.get(pk=cat_id)
|
||||
except PartCategory.DoesNotExist:
|
||||
except (PartCategory.DoesNotExist, ValueError):
|
||||
pass
|
||||
|
||||
return context
|
||||
@ -494,7 +494,7 @@ class PartCreate(AjaxCreateView):
|
||||
category = PartCategory.objects.get(pk=self.get_category_id())
|
||||
initials['category'] = category
|
||||
initials['keywords'] = category.default_keywords
|
||||
except PartCategory.DoesNotExist:
|
||||
except (PartCategory.DoesNotExist, ValueError):
|
||||
pass
|
||||
|
||||
# Allow initial data to be passed through as arguments
|
||||
|
Loading…
Reference in New Issue
Block a user