mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
#11584: Add bulk edit view & tests
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.urls import reverse
|
||||
|
||||
from dcim.models import Site
|
||||
from tenancy.choices import ContactPriorityChoices
|
||||
from tenancy.models import *
|
||||
from utilities.testing import ViewTestCases, create_tags
|
||||
|
||||
@@ -223,3 +228,89 @@ class ContactTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
||||
cls.bulk_edit_data = {
|
||||
'group': contact_groups[1].pk,
|
||||
}
|
||||
|
||||
|
||||
class ContactAssignmentTestCase(
|
||||
ViewTestCases.CreateObjectViewTestCase,
|
||||
ViewTestCases.EditObjectViewTestCase,
|
||||
ViewTestCases.DeleteObjectViewTestCase,
|
||||
ViewTestCases.ListObjectsViewTestCase,
|
||||
ViewTestCases.BulkEditObjectsViewTestCase,
|
||||
ViewTestCases.BulkDeleteObjectsViewTestCase
|
||||
):
|
||||
model = ContactAssignment
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
|
||||
sites = (
|
||||
Site(name='Site 1', slug='site-1'),
|
||||
Site(name='Site 2', slug='site-2'),
|
||||
Site(name='Site 3', slug='site-3'),
|
||||
Site(name='Site 4', slug='site-4'),
|
||||
)
|
||||
Site.objects.bulk_create(sites)
|
||||
|
||||
contacts = (
|
||||
Contact(name='Contact 1'),
|
||||
Contact(name='Contact 2'),
|
||||
Contact(name='Contact 3'),
|
||||
Contact(name='Contact 4'),
|
||||
)
|
||||
Contact.objects.bulk_create(contacts)
|
||||
|
||||
contact_roles = (
|
||||
ContactRole(name='Contact Role 1', slug='contact-role-1'),
|
||||
ContactRole(name='Contact Role 2', slug='contact-role-2'),
|
||||
ContactRole(name='Contact Role 3', slug='contact-role-3'),
|
||||
ContactRole(name='Contact Role 4', slug='contact-role-4'),
|
||||
)
|
||||
ContactRole.objects.bulk_create(contact_roles)
|
||||
|
||||
assignments = (
|
||||
ContactAssignment(
|
||||
object=sites[0],
|
||||
contact=contacts[0],
|
||||
role=contact_roles[0],
|
||||
priority=ContactPriorityChoices.PRIORITY_PRIMARY
|
||||
),
|
||||
ContactAssignment(
|
||||
object=sites[1],
|
||||
contact=contacts[1],
|
||||
role=contact_roles[1],
|
||||
priority=ContactPriorityChoices.PRIORITY_SECONDARY
|
||||
),
|
||||
ContactAssignment(
|
||||
object=sites[2],
|
||||
contact=contacts[2],
|
||||
role=contact_roles[2],
|
||||
priority=ContactPriorityChoices.PRIORITY_TERTIARY
|
||||
),
|
||||
)
|
||||
ContactAssignment.objects.bulk_create(assignments)
|
||||
|
||||
tags = create_tags('Alpha', 'Bravo', 'Charlie')
|
||||
|
||||
cls.form_data = {
|
||||
'content_type': ContentType.objects.get_for_model(Site).pk,
|
||||
'object_id': sites[3].pk,
|
||||
'contact': contacts[3].pk,
|
||||
'role': contact_roles[3].pk,
|
||||
'priority': ContactPriorityChoices.PRIORITY_INACTIVE,
|
||||
'tags': [t.pk for t in tags],
|
||||
}
|
||||
|
||||
cls.bulk_edit_data = {
|
||||
'role': contact_roles[3].pk,
|
||||
'priority': ContactPriorityChoices.PRIORITY_INACTIVE,
|
||||
}
|
||||
|
||||
def _get_url(self, action, instance=None):
|
||||
# Override creation URL to append content_type & object_id parameters
|
||||
if action == 'add':
|
||||
url = reverse('tenancy:contactassignment_add')
|
||||
content_type = ContentType.objects.get_for_model(Site).pk
|
||||
object_id = Site.objects.first().pk
|
||||
return f"{url}?content_type={content_type}&object_id={object_id}"
|
||||
|
||||
return super()._get_url(action, instance=instance)
|
||||
|
Reference in New Issue
Block a user