mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 01:48:38 -06:00
Add NestedContactAssignmentSerializer; add contact assignment API tests
This commit is contained in:
parent
519884d167
commit
ff3edc9889
@ -5,6 +5,7 @@ from tenancy.models import *
|
|||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'NestedContactSerializer',
|
'NestedContactSerializer',
|
||||||
|
'NestedContactAssignmentSerializer',
|
||||||
'NestedContactGroupSerializer',
|
'NestedContactGroupSerializer',
|
||||||
'NestedContactRoleSerializer',
|
'NestedContactRoleSerializer',
|
||||||
'NestedTenantGroupSerializer',
|
'NestedTenantGroupSerializer',
|
||||||
@ -62,3 +63,13 @@ class NestedContactSerializer(WritableNestedSerializer):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = Contact
|
model = Contact
|
||||||
fields = ['id', 'url', 'display', 'name']
|
fields = ['id', 'url', 'display', 'name']
|
||||||
|
|
||||||
|
|
||||||
|
class NestedContactAssignmentSerializer(WritableNestedSerializer):
|
||||||
|
url = serializers.HyperlinkedIdentityField(view_name='tenancy-api:contactassignment-detail')
|
||||||
|
contact = NestedContactSerializer()
|
||||||
|
role = NestedContactRoleSerializer
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ContactAssignment
|
||||||
|
fields = ['id', 'url', 'display', 'contact', 'role', 'priority']
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import graphene
|
import graphene
|
||||||
|
|
||||||
from tenancy import filtersets, models
|
from tenancy import filtersets, models
|
||||||
from netbox.graphql.types import OrganizationalObjectType, PrimaryObjectType
|
from netbox.graphql.types import BaseObjectType, OrganizationalObjectType, PrimaryObjectType
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'ContactAssignmentType',
|
'ContactAssignmentType',
|
||||||
@ -68,7 +68,7 @@ class ContactGroupType(OrganizationalObjectType):
|
|||||||
filterset_class = filtersets.ContactGroupFilterSet
|
filterset_class = filtersets.ContactGroupFilterSet
|
||||||
|
|
||||||
|
|
||||||
class ContactAssignmentType(OrganizationalObjectType):
|
class ContactAssignmentType(BaseObjectType):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.ContactAssignment
|
model = models.ContactAssignment
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from dcim.models import Site
|
||||||
|
from tenancy.choices import *
|
||||||
from tenancy.models import *
|
from tenancy.models import *
|
||||||
from utilities.testing import APITestCase, APIViewTestCases
|
from utilities.testing import APITestCase, APIViewTestCases
|
||||||
|
|
||||||
@ -201,3 +203,68 @@ class ContactTest(APIViewTestCases.APIViewTestCase):
|
|||||||
'group': contact_groups[1].pk,
|
'group': contact_groups[1].pk,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class ContactAssignmentTest(APIViewTestCases.APIViewTestCase):
|
||||||
|
model = ContactAssignment
|
||||||
|
brief_fields = ['contact', 'display', 'id', 'priority', 'role', 'url']
|
||||||
|
bulk_update_data = {
|
||||||
|
'priority': ContactPriorityChoices.PRIORITY_INACTIVE,
|
||||||
|
}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpTestData(cls):
|
||||||
|
|
||||||
|
sites = (
|
||||||
|
Site(name='Site 1', slug='site-1'),
|
||||||
|
Site(name='Site 2', slug='site-2'),
|
||||||
|
)
|
||||||
|
Site.objects.bulk_create(sites)
|
||||||
|
|
||||||
|
contacts = (
|
||||||
|
Contact(name='Contact 1'),
|
||||||
|
Contact(name='Contact 2'),
|
||||||
|
Contact(name='Contact 3'),
|
||||||
|
Contact(name='Contact 4'),
|
||||||
|
Contact(name='Contact 5'),
|
||||||
|
Contact(name='Contact 6'),
|
||||||
|
)
|
||||||
|
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.objects.bulk_create(contact_roles)
|
||||||
|
|
||||||
|
contact_assignments = (
|
||||||
|
ContactAssignment(object=sites[0], contact=contacts[0], role=contact_roles[0], priority=ContactPriorityChoices.PRIORITY_PRIMARY),
|
||||||
|
ContactAssignment(object=sites[0], contact=contacts[1], role=contact_roles[1], priority=ContactPriorityChoices.PRIORITY_SECONDARY),
|
||||||
|
ContactAssignment(object=sites[0], contact=contacts[2], role=contact_roles[2], priority=ContactPriorityChoices.PRIORITY_TERTIARY),
|
||||||
|
)
|
||||||
|
ContactAssignment.objects.bulk_create(contact_assignments)
|
||||||
|
|
||||||
|
cls.create_data = [
|
||||||
|
{
|
||||||
|
'content_type': 'dcim.site',
|
||||||
|
'object_id': sites[1].pk,
|
||||||
|
'contact': contacts[3].pk,
|
||||||
|
'role': contact_roles[0].pk,
|
||||||
|
'priority': ContactPriorityChoices.PRIORITY_PRIMARY,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'content_type': 'dcim.site',
|
||||||
|
'object_id': sites[1].pk,
|
||||||
|
'contact': contacts[4].pk,
|
||||||
|
'role': contact_roles[1].pk,
|
||||||
|
'priority': ContactPriorityChoices.PRIORITY_SECONDARY,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'content_type': 'dcim.site',
|
||||||
|
'object_id': sites[1].pk,
|
||||||
|
'contact': contacts[5].pk,
|
||||||
|
'role': contact_roles[2].pk,
|
||||||
|
'priority': ContactPriorityChoices.PRIORITY_TERTIARY,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user