mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
* 7961 add csv bulk update * temp checkin - blocked * 7961 bugfix and cleanup * 7961 change to id, add docs * 7961 add tests cases * 7961 fix does not exist validation error * 7961 fix does not exist validation error * 7961 update tests * 7961 update tests * 7961 update tests * 7961 update tests * 7961 update tests * 7961 update tests * 7961 update tests * 7961 update tests * 7961 update tests * 7961 make test cases more explicit * 7961 make test cases more explicit * 7961 make test cases more explicit * 7961 make test cases more explicit * 7961 make test cases more explicit * 7961 make test cases more explicit * 7961 make test cases more explicit * 7961 optimize loading csv test data * 7961 update tests remove redundant code * 7961 avoid MPTT issue in test cases
226 lines
7.0 KiB
Python
226 lines
7.0 KiB
Python
from tenancy.models import *
|
|
from utilities.testing import ViewTestCases, create_tags
|
|
|
|
|
|
class TenantGroupTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
|
|
model = TenantGroup
|
|
|
|
@classmethod
|
|
def setUpTestData(cls):
|
|
|
|
tenant_groups = (
|
|
TenantGroup(name='Tenant Group 1', slug='tenant-group-1'),
|
|
TenantGroup(name='Tenant Group 2', slug='tenant-group-2'),
|
|
TenantGroup(name='Tenant Group 3', slug='tenant-group-3'),
|
|
)
|
|
for tenanantgroup in tenant_groups:
|
|
tenanantgroup.save()
|
|
|
|
tags = create_tags('Alpha', 'Bravo', 'Charlie')
|
|
|
|
cls.form_data = {
|
|
'name': 'Tenant Group X',
|
|
'slug': 'tenant-group-x',
|
|
'description': 'A new tenant group',
|
|
'tags': [t.pk for t in tags],
|
|
}
|
|
|
|
cls.csv_data = (
|
|
"name,slug,description",
|
|
"Tenant Group 4,tenant-group-4,Fourth tenant group",
|
|
"Tenant Group 5,tenant-group-5,Fifth tenant group",
|
|
"Tenant Group 6,tenant-group-6,Sixth tenant group",
|
|
)
|
|
|
|
cls.csv_update_data = (
|
|
"id,name,description",
|
|
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[2].pk},Tenant Group 0,Sixth tenant group9",
|
|
)
|
|
|
|
cls.bulk_edit_data = {
|
|
'description': 'New description',
|
|
}
|
|
|
|
|
|
class TenantTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
|
model = Tenant
|
|
|
|
@classmethod
|
|
def setUpTestData(cls):
|
|
|
|
tenant_groups = (
|
|
TenantGroup(name='Tenant Group 1', slug='tenant-group-1'),
|
|
TenantGroup(name='Tenant Group 2', slug='tenant-group-2'),
|
|
)
|
|
for tenanantgroup in tenant_groups:
|
|
tenanantgroup.save()
|
|
|
|
tenants = (
|
|
Tenant(name='Tenant 1', slug='tenant-1', group=tenant_groups[0]),
|
|
Tenant(name='Tenant 2', slug='tenant-2', group=tenant_groups[0]),
|
|
Tenant(name='Tenant 3', slug='tenant-3', group=tenant_groups[0]),
|
|
)
|
|
Tenant.objects.bulk_create(tenants)
|
|
|
|
tags = create_tags('Alpha', 'Bravo', 'Charlie')
|
|
|
|
cls.form_data = {
|
|
'name': 'Tenant X',
|
|
'slug': 'tenant-x',
|
|
'group': tenant_groups[1].pk,
|
|
'description': 'A new tenant',
|
|
'comments': 'Some comments',
|
|
'tags': [t.pk for t in tags],
|
|
}
|
|
|
|
cls.csv_data = (
|
|
"name,slug",
|
|
"Tenant 4,tenant-4",
|
|
"Tenant 5,tenant-5",
|
|
"Tenant 6,tenant-6",
|
|
)
|
|
|
|
cls.csv_update_data = (
|
|
"id,name,description",
|
|
f"{tenants[0].pk},Tenant 7,New description 7",
|
|
f"{tenants[1].pk},Tenant 8,New description 8",
|
|
f"{tenants[2].pk},Tenant 9,New description 9",
|
|
)
|
|
|
|
cls.bulk_edit_data = {
|
|
'group': tenant_groups[1].pk,
|
|
}
|
|
|
|
|
|
class ContactGroupTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
|
|
model = ContactGroup
|
|
|
|
@classmethod
|
|
def setUpTestData(cls):
|
|
|
|
contact_groups = (
|
|
ContactGroup(name='Contact Group 1', slug='contact-group-1'),
|
|
ContactGroup(name='Contact Group 2', slug='contact-group-2'),
|
|
ContactGroup(name='Contact Group 3', slug='contact-group-3'),
|
|
)
|
|
for tenanantgroup in contact_groups:
|
|
tenanantgroup.save()
|
|
|
|
tags = create_tags('Alpha', 'Bravo', 'Charlie')
|
|
|
|
cls.form_data = {
|
|
'name': 'Contact Group X',
|
|
'slug': 'contact-group-x',
|
|
'description': 'A new contact group',
|
|
'tags': [t.pk for t in tags],
|
|
}
|
|
|
|
cls.csv_data = (
|
|
"name,slug,description",
|
|
"Contact Group 4,contact-group-4,Fourth contact group",
|
|
"Contact Group 5,contact-group-5,Fifth contact group",
|
|
"Contact Group 6,contact-group-6,Sixth contact group",
|
|
)
|
|
|
|
cls.csv_update_data = (
|
|
"id,name,description",
|
|
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[2].pk},Contact Group 0,Sixth contact group9",
|
|
)
|
|
|
|
cls.bulk_edit_data = {
|
|
'description': 'New description',
|
|
}
|
|
|
|
|
|
class ContactRoleTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
|
|
model = ContactRole
|
|
|
|
@classmethod
|
|
def setUpTestData(cls):
|
|
|
|
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)
|
|
|
|
tags = create_tags('Alpha', 'Bravo', 'Charlie')
|
|
|
|
cls.form_data = {
|
|
'name': 'Devie Role X',
|
|
'slug': 'contact-role-x',
|
|
'description': 'New contact role',
|
|
'tags': [t.pk for t in tags],
|
|
}
|
|
|
|
cls.csv_data = (
|
|
"name,slug",
|
|
"Contact Role 4,contact-role-4",
|
|
"Contact Role 5,contact-role-5",
|
|
"Contact Role 6,contact-role-6",
|
|
)
|
|
|
|
cls.csv_update_data = (
|
|
"id,name,description",
|
|
f"{contact_roles[0].pk},Contact Role 7,New description 7",
|
|
f"{contact_roles[1].pk},Contact Role 8,New description 8",
|
|
f"{contact_roles[2].pk},Contact Role 9,New description 9",
|
|
)
|
|
|
|
cls.bulk_edit_data = {
|
|
'description': 'New description',
|
|
}
|
|
|
|
|
|
class ContactTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
|
model = Contact
|
|
|
|
@classmethod
|
|
def setUpTestData(cls):
|
|
|
|
contact_groups = (
|
|
ContactGroup(name='Contact Group 1', slug='contact-group-1'),
|
|
ContactGroup(name='Contact Group 2', slug='contact-group-2'),
|
|
)
|
|
for contactgroup in contact_groups:
|
|
contactgroup.save()
|
|
|
|
contacts = (
|
|
Contact(name='Contact 1', group=contact_groups[0]),
|
|
Contact(name='Contact 2', group=contact_groups[0]),
|
|
Contact(name='Contact 3', group=contact_groups[0]),
|
|
)
|
|
Contact.objects.bulk_create(contacts)
|
|
|
|
tags = create_tags('Alpha', 'Bravo', 'Charlie')
|
|
|
|
cls.form_data = {
|
|
'name': 'Contact X',
|
|
'group': contact_groups[1].pk,
|
|
'comments': 'Some comments',
|
|
'tags': [t.pk for t in tags],
|
|
}
|
|
|
|
cls.csv_data = (
|
|
"group,name",
|
|
"Contact Group 1,Contact 4",
|
|
"Contact Group 1,Contact 5",
|
|
"Contact Group 1,Contact 6",
|
|
)
|
|
|
|
cls.csv_update_data = (
|
|
"id,name,comments",
|
|
f"{contacts[0].pk},Contact Group 7,New comments 7",
|
|
f"{contacts[1].pk},Contact Group 8,New comments 8",
|
|
f"{contacts[2].pk},Contact Group 9,New comments 9",
|
|
)
|
|
|
|
cls.bulk_edit_data = {
|
|
'group': contact_groups[1].pk,
|
|
}
|