mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -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 utilities.testing import TestCase
|
||||
from utilities.testing import StandardTestCases
|
||||
|
||||
|
||||
class TenantGroupTestCase(TestCase):
|
||||
user_permissions = (
|
||||
'tenancy.view_tenantgroup',
|
||||
)
|
||||
class TenantGroupTestCase(StandardTestCases.Views):
|
||||
model = TenantGroup
|
||||
|
||||
# Disable inapplicable tests
|
||||
test_get_object = None
|
||||
test_delete_object = None
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
@ -20,39 +18,26 @@ class TenantGroupTestCase(TestCase):
|
||||
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')
|
||||
|
||||
response = self.client.get(url, follow=True)
|
||||
self.assertHttpStatus(response, 200)
|
||||
|
||||
def test_tenantgroup_import(self):
|
||||
self.add_permissions('tenancy.add_tenantgroup')
|
||||
|
||||
csv_data = (
|
||||
cls.csv_data = (
|
||||
"name,slug",
|
||||
"Tenant Group 4,tenant-group-4",
|
||||
"Tenant Group 5,tenant-group-5",
|
||||
"Tenant Group 6,tenant-group-6",
|
||||
)
|
||||
|
||||
response = self.client.post(reverse('tenancy:tenantgroup_import'), {'csv': '\n'.join(csv_data)})
|
||||
|
||||
self.assertHttpStatus(response, 200)
|
||||
self.assertEqual(TenantGroup.objects.count(), 6)
|
||||
|
||||
|
||||
class TenantTestCase(TestCase):
|
||||
user_permissions = (
|
||||
'tenancy.view_tenant',
|
||||
)
|
||||
class TenantTestCase(StandardTestCases.Views):
|
||||
model = Tenant
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
|
||||
tenantgroup = TenantGroup(name='Tenant Group 1', slug='tenant-group-1')
|
||||
tenantgroup.save()
|
||||
tenantgroup = TenantGroup.objects.create(name='Tenant Group 1', slug='tenant-group-1')
|
||||
|
||||
Tenant.objects.bulk_create([
|
||||
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),
|
||||
])
|
||||
|
||||
def test_tenant_list(self):
|
||||
|
||||
url = reverse('tenancy:tenant_list')
|
||||
params = {
|
||||
"group": TenantGroup.objects.first().slug,
|
||||
cls.form_data = {
|
||||
'name': 'Tenant X',
|
||||
'slug': 'tenant-x',
|
||||
'group': tenantgroup.pk,
|
||||
'description': 'A new tenant',
|
||||
'comments': 'Some comments',
|
||||
'tags': 'Alpha,Bravo,Charlie',
|
||||
}
|
||||
|
||||
response = self.client.get('{}?{}'.format(url, urllib.parse.urlencode(params)), follow=True)
|
||||
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 = (
|
||||
cls.csv_data = (
|
||||
"name,slug",
|
||||
"Tenant 4,tenant-4",
|
||||
"Tenant 5,tenant-5",
|
||||
"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