mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 09:28:38 -06:00
Convert tenancy view tests to use StandardTestCases
This commit is contained in:
parent
e8e39dc5e3
commit
5517145ae3
@ -1,15 +1,13 @@
|
|||||||
import urllib.parse
|
|
||||||
|
|
||||||
from django.urls import reverse
|
|
||||||
|
|
||||||
from tenancy.models import Tenant, TenantGroup
|
from tenancy.models import Tenant, TenantGroup
|
||||||
from utilities.testing import TestCase
|
from utilities.testing import StandardTestCases
|
||||||
|
|
||||||
|
|
||||||
class TenantGroupTestCase(TestCase):
|
class TenantGroupTestCase(StandardTestCases.Views):
|
||||||
user_permissions = (
|
model = TenantGroup
|
||||||
'tenancy.view_tenantgroup',
|
|
||||||
)
|
# Disable inapplicable tests
|
||||||
|
test_get_object = None
|
||||||
|
test_delete_object = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
@ -20,39 +18,26 @@ class TenantGroupTestCase(TestCase):
|
|||||||
TenantGroup(name='Tenant Group 3', slug='tenant-group-3'),
|
TenantGroup(name='Tenant Group 3', slug='tenant-group-3'),
|
||||||
])
|
])
|
||||||
|
|
||||||
def test_tenantgroup_list(self):
|
cls.form_data = {
|
||||||
|
'name': 'Tenant Group X',
|
||||||
|
'slug': 'tenant-group-x',
|
||||||
|
}
|
||||||
|
|
||||||
url = reverse('tenancy:tenantgroup_list')
|
cls.csv_data = (
|
||||||
|
|
||||||
response = self.client.get(url, follow=True)
|
|
||||||
self.assertHttpStatus(response, 200)
|
|
||||||
|
|
||||||
def test_tenantgroup_import(self):
|
|
||||||
self.add_permissions('tenancy.add_tenantgroup')
|
|
||||||
|
|
||||||
csv_data = (
|
|
||||||
"name,slug",
|
"name,slug",
|
||||||
"Tenant Group 4,tenant-group-4",
|
"Tenant Group 4,tenant-group-4",
|
||||||
"Tenant Group 5,tenant-group-5",
|
"Tenant Group 5,tenant-group-5",
|
||||||
"Tenant Group 6,tenant-group-6",
|
"Tenant Group 6,tenant-group-6",
|
||||||
)
|
)
|
||||||
|
|
||||||
response = self.client.post(reverse('tenancy:tenantgroup_import'), {'csv': '\n'.join(csv_data)})
|
|
||||||
|
|
||||||
self.assertHttpStatus(response, 200)
|
class TenantTestCase(StandardTestCases.Views):
|
||||||
self.assertEqual(TenantGroup.objects.count(), 6)
|
model = Tenant
|
||||||
|
|
||||||
|
|
||||||
class TenantTestCase(TestCase):
|
|
||||||
user_permissions = (
|
|
||||||
'tenancy.view_tenant',
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
|
|
||||||
tenantgroup = TenantGroup(name='Tenant Group 1', slug='tenant-group-1')
|
tenantgroup = TenantGroup.objects.create(name='Tenant Group 1', slug='tenant-group-1')
|
||||||
tenantgroup.save()
|
|
||||||
|
|
||||||
Tenant.objects.bulk_create([
|
Tenant.objects.bulk_create([
|
||||||
Tenant(name='Tenant 1', slug='tenant-1', group=tenantgroup),
|
Tenant(name='Tenant 1', slug='tenant-1', group=tenantgroup),
|
||||||
@ -60,33 +45,18 @@ class TenantTestCase(TestCase):
|
|||||||
Tenant(name='Tenant 3', slug='tenant-3', group=tenantgroup),
|
Tenant(name='Tenant 3', slug='tenant-3', group=tenantgroup),
|
||||||
])
|
])
|
||||||
|
|
||||||
def test_tenant_list(self):
|
cls.form_data = {
|
||||||
|
'name': 'Tenant X',
|
||||||
url = reverse('tenancy:tenant_list')
|
'slug': 'tenant-x',
|
||||||
params = {
|
'group': tenantgroup.pk,
|
||||||
"group": TenantGroup.objects.first().slug,
|
'description': 'A new tenant',
|
||||||
|
'comments': 'Some comments',
|
||||||
|
'tags': 'Alpha,Bravo,Charlie',
|
||||||
}
|
}
|
||||||
|
|
||||||
response = self.client.get('{}?{}'.format(url, urllib.parse.urlencode(params)), follow=True)
|
cls.csv_data = (
|
||||||
self.assertHttpStatus(response, 200)
|
|
||||||
|
|
||||||
def test_tenant(self):
|
|
||||||
|
|
||||||
tenant = Tenant.objects.first()
|
|
||||||
response = self.client.get(tenant.get_absolute_url(), follow=True)
|
|
||||||
self.assertHttpStatus(response, 200)
|
|
||||||
|
|
||||||
def test_tenant_import(self):
|
|
||||||
self.add_permissions('tenancy.add_tenant')
|
|
||||||
|
|
||||||
csv_data = (
|
|
||||||
"name,slug",
|
"name,slug",
|
||||||
"Tenant 4,tenant-4",
|
"Tenant 4,tenant-4",
|
||||||
"Tenant 5,tenant-5",
|
"Tenant 5,tenant-5",
|
||||||
"Tenant 6,tenant-6",
|
"Tenant 6,tenant-6",
|
||||||
)
|
)
|
||||||
|
|
||||||
response = self.client.post(reverse('tenancy:tenant_import'), {'csv': '\n'.join(csv_data)})
|
|
||||||
|
|
||||||
self.assertHttpStatus(response, 200)
|
|
||||||
self.assertEqual(Tenant.objects.count(), 6)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user