1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Add test method for changelog view

This commit is contained in:
Jeremy Stretch
2020-06-25 15:43:47 -04:00
parent 1dbae5b64c
commit 2e272132b0

View File

@ -177,27 +177,23 @@ class ModelViewTestCase(TestCase):
def _get_url(self, action, instance=None): def _get_url(self, action, instance=None):
""" """
Return the URL name for a specific action. An instance must be specified for Return the URL name for a specific action and optionally a specific instance
get/edit/delete views.
""" """
url_format = self._get_base_url() url_format = self._get_base_url()
if action in ('list', 'add', 'import', 'bulk_edit', 'bulk_delete'): # If no instance was provided, assume we don't need a unique identifier
if instance is None:
return reverse(url_format.format(action)) return reverse(url_format.format(action))
elif action in ('get', 'edit', 'delete'): # Attempt to resolve using slug as the unique identifier if one exists
if instance is None:
raise Exception("Resolving {} URL requires specifying an instance".format(action))
# Attempt to resolve using slug first
if hasattr(self.model, 'slug'): if hasattr(self.model, 'slug'):
try: try:
return reverse(url_format.format(action), kwargs={'slug': instance.slug}) return reverse(url_format.format(action), kwargs={'slug': instance.slug})
except NoReverseMatch: except NoReverseMatch:
pass pass
return reverse(url_format.format(action), kwargs={'pk': instance.pk})
else: # Default to using the numeric PK to retrieve the URL for an object
raise Exception("Invalid action for URL resolution: {}".format(action)) return reverse(url_format.format(action), kwargs={'pk': instance.pk})
class ViewTestCases: class ViewTestCases:
@ -257,6 +253,16 @@ class ViewTestCases:
# Try GET to non-permitted object # Try GET to non-permitted object
self.assertHttpStatus(self.client.get(instance2.get_absolute_url()), 404) self.assertHttpStatus(self.client.get(instance2.get_absolute_url()), 404)
class GetObjectChangelogViewTestCase(ModelViewTestCase):
"""
View the changelog for an instance.
"""
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
def test_get_object_changelog(self):
url = self._get_url('changelog', self.model.objects.first())
response = self.client.get(url)
self.assertHttpStatus(response, 200)
class CreateObjectViewTestCase(ModelViewTestCase): class CreateObjectViewTestCase(ModelViewTestCase):
""" """
Create a single new instance. Create a single new instance.
@ -879,6 +885,7 @@ class ViewTestCases:
class PrimaryObjectViewTestCase( class PrimaryObjectViewTestCase(
GetObjectViewTestCase, GetObjectViewTestCase,
GetObjectChangelogViewTestCase,
CreateObjectViewTestCase, CreateObjectViewTestCase,
EditObjectViewTestCase, EditObjectViewTestCase,
DeleteObjectViewTestCase, DeleteObjectViewTestCase,
@ -893,6 +900,7 @@ class ViewTestCases:
maxDiff = None maxDiff = None
class OrganizationalObjectViewTestCase( class OrganizationalObjectViewTestCase(
GetObjectChangelogViewTestCase,
CreateObjectViewTestCase, CreateObjectViewTestCase,
EditObjectViewTestCase, EditObjectViewTestCase,
ListObjectsViewTestCase, ListObjectsViewTestCase,
@ -918,6 +926,7 @@ class ViewTestCases:
class DeviceComponentViewTestCase( class DeviceComponentViewTestCase(
GetObjectViewTestCase, GetObjectViewTestCase,
GetObjectChangelogViewTestCase,
EditObjectViewTestCase, EditObjectViewTestCase,
DeleteObjectViewTestCase, DeleteObjectViewTestCase,
ListObjectsViewTestCase, ListObjectsViewTestCase,