7961 avoid MPTT issue in test cases

This commit is contained in:
Arthur 2022-10-27 09:50:54 -07:00
parent 0be3747c01
commit 86fba116f5
4 changed files with 9 additions and 17 deletions

View File

@ -54,7 +54,7 @@ class RegionTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
"id,name,description", "id,name,description",
f"{regions[0].pk},Region 7,Fourth region7", f"{regions[0].pk},Region 7,Fourth region7",
f"{regions[1].pk},Region 8,Fifth region8", f"{regions[1].pk},Region 8,Fifth region8",
f"{regions[2].pk},Region 9,Sixth region9", f"{regions[2].pk},Region 0,Sixth region9",
) )
cls.bulk_edit_data = { cls.bulk_edit_data = {
@ -98,7 +98,7 @@ class SiteGroupTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
"id,name,description", "id,name,description",
f"{sitegroups[0].pk},Site Group 7,Fourth site group7", f"{sitegroups[0].pk},Site Group 7,Fourth site group7",
f"{sitegroups[1].pk},Site Group 8,Fifth site group8", f"{sitegroups[1].pk},Site Group 8,Fifth site group8",
f"{sitegroups[2].pk},Site Group 9,Sixth site group9", f"{sitegroups[2].pk},Site Group 0,Sixth site group9",
) )
cls.bulk_edit_data = { cls.bulk_edit_data = {
@ -227,7 +227,7 @@ class LocationTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
"id,name,description", "id,name,description",
f"{locations[0].pk},Location 7,Fourth location7", f"{locations[0].pk},Location 7,Fourth location7",
f"{locations[1].pk},Location 8,Fifth location8", f"{locations[1].pk},Location 8,Fifth location8",
f"{locations[2].pk},Location 9,Sixth location9", f"{locations[2].pk},Location 0,Sixth location9",
) )
cls.bulk_edit_data = { cls.bulk_edit_data = {

View File

@ -36,7 +36,7 @@ class TenantGroupTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
"id,name,description", "id,name,description",
f"{tenant_groups[0].pk},Tenant Group 7,Fourth tenant group7", f"{tenant_groups[0].pk},Tenant Group 7,Fourth tenant group7",
f"{tenant_groups[1].pk},Tenant Group 8,Fifth tenant group8", f"{tenant_groups[1].pk},Tenant Group 8,Fifth tenant group8",
f"{tenant_groups[2].pk},Tenant Group 9,Sixth tenant group9", f"{tenant_groups[2].pk},Tenant Group 0,Sixth tenant group9",
) )
cls.bulk_edit_data = { cls.bulk_edit_data = {
@ -128,7 +128,7 @@ class ContactGroupTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
"id,name,description", "id,name,description",
f"{contact_groups[0].pk},Contact Group 7,Fourth contact group7", f"{contact_groups[0].pk},Contact Group 7,Fourth contact group7",
f"{contact_groups[1].pk},Contact Group 8,Fifth contact group8", f"{contact_groups[1].pk},Contact Group 8,Fifth contact group8",
f"{contact_groups[2].pk},Contact Group 9,Sixth contact group9", f"{contact_groups[2].pk},Contact Group 0,Sixth contact group9",
) )
cls.bulk_edit_data = { cls.bulk_edit_data = {

View File

@ -596,8 +596,9 @@ class ViewTestCases:
raise NotImplementedError("The test must define csv_update_data.") raise NotImplementedError("The test must define csv_update_data.")
initial_count = self._get_queryset().count() initial_count = self._get_queryset().count()
array, csv_data = self._get_update_csv_data()
data = { data = {
'csv': self._get_csv_data(), 'csv': csv_data,
} }
# Assign model-level permission # Assign model-level permission
@ -609,18 +610,9 @@ class ViewTestCases:
obj_perm.users.add(self.user) obj_perm.users.add(self.user)
obj_perm.object_types.add(ContentType.objects.get_for_model(self.model)) obj_perm.object_types.add(ContentType.objects.get_for_model(self.model))
# self.assertHttpStatus(self.client.post(self._get_url('import'), data), 200)
count = self._get_queryset().count()
# Now try update the data
array, csv_data = self._get_update_csv_data()
data = {
'csv': csv_data,
}
# Test POST with permission # Test POST with permission
self.assertHttpStatus(self.client.post(self._get_url('import'), data), 200) self.assertHttpStatus(self.client.post(self._get_url('import'), data), 200)
self.assertEqual(count, self._get_queryset().count()) self.assertEqual(initial_count, self._get_queryset().count())
reader = csv.DictReader(array, delimiter=',') reader = csv.DictReader(array, delimiter=',')
check_data = list(reader) check_data = list(reader)

View File

@ -41,7 +41,7 @@ class WirelessLANGroupTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
"id,name,description", "id,name,description",
f"{groups[0].pk},Wireless LAN Group 7,Fourth wireless LAN group7", f"{groups[0].pk},Wireless LAN Group 7,Fourth wireless LAN group7",
f"{groups[1].pk},Wireless LAN Group 8,Fifth wireless LAN group8", f"{groups[1].pk},Wireless LAN Group 8,Fifth wireless LAN group8",
f"{groups[2].pk},Wireless LAN Group 9,Sixth wireless LAN group9", f"{groups[2].pk},Wireless LAN Group 0,Sixth wireless LAN group9",
) )
cls.bulk_edit_data = { cls.bulk_edit_data = {