From a70484caff4b0f04de64fe09c6ff2c99a89910cd Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 8 Aug 2019 22:45:02 +1000 Subject: [PATCH] Test PartDetail view --- InvenTree/part/test_views.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/InvenTree/part/test_views.py b/InvenTree/part/test_views.py index 5680dfdebe..ae268e873a 100644 --- a/InvenTree/part/test_views.py +++ b/InvenTree/part/test_views.py @@ -4,6 +4,8 @@ from django.test import TestCase from django.urls import reverse from django.contrib.auth import get_user_model +from .models import Part + class PartViewTestCase(TestCase): fixtures = [ @@ -21,6 +23,9 @@ class PartViewTestCase(TestCase): self.client.login(username='username', password='password') + +class PartListTest(PartViewTestCase): + def test_part_index(self): response = self.client.get(reverse('part-index')) self.assertEqual(response.status_code, 200) @@ -30,3 +35,34 @@ class PartViewTestCase(TestCase): self.assertIn('parts', keys) self.assertIn('user', keys) + +class PartDetailTest(PartViewTestCase): + + def test_part_detail(self): + """ Test that we can retrieve a part detail page """ + + pk = 1 + + response = self.client.get(reverse('part-detail', args=(pk,))) + self.assertEqual(response.status_code, 200) + + part = Part.objects.get(pk=pk) + + keys = response.context.keys() + + self.assertIn('part', keys) + self.assertIn('category', keys) + + self.assertEqual(response.context['part'].pk, pk) + self.assertEqual(response.context['category'], part.category) + + self.assertFalse(response.context['editing_enabled']) + + def test_editable(self): + + pk = 1 + response = self.client.get(reverse('part-detail', args=(pk,)), {'edit': True}) + + self.assertEqual(response.status_code, 200) + self.assertTrue(response.context['editing_enabled']) +