2017-03-16 13:29:55 -04:00
|
|
|
from django.urls import reverse
|
|
|
|
|
|
|
|
from tenancy.models import Tenant, TenantGroup
|
2020-06-05 14:30:01 -04:00
|
|
|
from utilities.testing import APITestCase, APIViewTestCases
|
2017-03-16 13:29:55 -04:00
|
|
|
|
|
|
|
|
2020-01-15 17:47:55 -05:00
|
|
|
class AppTest(APITestCase):
|
|
|
|
|
|
|
|
def test_root(self):
|
|
|
|
|
|
|
|
url = reverse('tenancy-api:api-root')
|
|
|
|
response = self.client.get('{}?format=api'.format(url), **self.header)
|
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2020-01-14 15:50:32 -05:00
|
|
|
|
|
|
|
|
2020-06-05 14:30:01 -04:00
|
|
|
class TenantGroupTest(APIViewTestCases.APIViewTestCase):
|
|
|
|
model = TenantGroup
|
2021-03-16 10:06:25 -04:00
|
|
|
brief_fields = ['_depth', 'display', 'id', 'name', 'slug', 'tenant_count', 'url']
|
2020-09-22 13:50:55 -04:00
|
|
|
bulk_update_data = {
|
|
|
|
'description': 'New description',
|
|
|
|
}
|
2017-03-16 13:29:55 -04:00
|
|
|
|
2020-06-05 14:30:01 -04:00
|
|
|
@classmethod
|
|
|
|
def setUpTestData(cls):
|
2017-03-16 13:29:55 -04:00
|
|
|
|
2020-06-05 14:30:01 -04:00
|
|
|
parent_tenant_groups = (
|
|
|
|
TenantGroup.objects.create(name='Parent Tenant Group 1', slug='parent-tenant-group-1'),
|
|
|
|
TenantGroup.objects.create(name='Parent Tenant Group 2', slug='parent-tenant-group-2'),
|
2018-10-04 16:20:01 -04:00
|
|
|
)
|
|
|
|
|
2020-06-05 14:30:01 -04:00
|
|
|
TenantGroup.objects.create(name='Tenant Group 1', slug='tenant-group-1', parent=parent_tenant_groups[0])
|
|
|
|
TenantGroup.objects.create(name='Tenant Group 2', slug='tenant-group-2', parent=parent_tenant_groups[0])
|
|
|
|
TenantGroup.objects.create(name='Tenant Group 3', slug='tenant-group-3', parent=parent_tenant_groups[0])
|
2017-03-16 13:29:55 -04:00
|
|
|
|
2020-06-05 14:30:01 -04:00
|
|
|
cls.create_data = [
|
2018-01-02 16:29:44 -05:00
|
|
|
{
|
2020-03-11 21:14:53 -04:00
|
|
|
'name': 'Tenant Group 4',
|
|
|
|
'slug': 'tenant-group-4',
|
2020-06-05 14:30:01 -04:00
|
|
|
'parent': parent_tenant_groups[1].pk,
|
2018-01-02 16:29:44 -05:00
|
|
|
},
|
|
|
|
{
|
2020-03-11 21:14:53 -04:00
|
|
|
'name': 'Tenant Group 5',
|
|
|
|
'slug': 'tenant-group-5',
|
2020-06-05 14:30:01 -04:00
|
|
|
'parent': parent_tenant_groups[1].pk,
|
2018-01-02 16:29:44 -05:00
|
|
|
},
|
|
|
|
{
|
2020-03-11 21:14:53 -04:00
|
|
|
'name': 'Tenant Group 6',
|
|
|
|
'slug': 'tenant-group-6',
|
2020-06-05 14:30:01 -04:00
|
|
|
'parent': parent_tenant_groups[1].pk,
|
2018-01-02 16:29:44 -05:00
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2017-03-16 13:29:55 -04:00
|
|
|
|
2020-06-05 14:30:01 -04:00
|
|
|
class TenantTest(APIViewTestCases.APIViewTestCase):
|
|
|
|
model = Tenant
|
2021-03-16 10:06:25 -04:00
|
|
|
brief_fields = ['display', 'id', 'name', 'slug', 'url']
|
2020-09-22 13:50:55 -04:00
|
|
|
bulk_update_data = {
|
2021-02-24 14:39:09 -05:00
|
|
|
'group': None,
|
2020-09-22 13:50:55 -04:00
|
|
|
'description': 'New description',
|
|
|
|
}
|
2017-03-16 13:29:55 -04:00
|
|
|
|
2020-06-05 14:30:01 -04:00
|
|
|
@classmethod
|
|
|
|
def setUpTestData(cls):
|
2017-03-16 13:29:55 -04:00
|
|
|
|
2020-06-05 14:30:01 -04:00
|
|
|
tenant_groups = (
|
|
|
|
TenantGroup.objects.create(name='Tenant Group 1', slug='tenant-group-1'),
|
|
|
|
TenantGroup.objects.create(name='Tenant Group 2', slug='tenant-group-2'),
|
2020-03-11 21:14:53 -04:00
|
|
|
)
|
|
|
|
|
2020-06-05 14:30:01 -04:00
|
|
|
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]),
|
2020-03-11 21:14:53 -04:00
|
|
|
)
|
2020-06-05 14:30:01 -04:00
|
|
|
Tenant.objects.bulk_create(tenants)
|
2017-03-16 13:29:55 -04:00
|
|
|
|
2020-06-05 14:30:01 -04:00
|
|
|
cls.create_data = [
|
2018-01-02 16:29:44 -05:00
|
|
|
{
|
2020-06-05 14:30:01 -04:00
|
|
|
'name': 'Tenant 4',
|
|
|
|
'slug': 'tenant-4',
|
|
|
|
'group': tenant_groups[1].pk,
|
2018-01-02 16:29:44 -05:00
|
|
|
},
|
|
|
|
{
|
2020-06-05 14:30:01 -04:00
|
|
|
'name': 'Tenant 5',
|
|
|
|
'slug': 'tenant-5',
|
|
|
|
'group': tenant_groups[1].pk,
|
2018-01-02 16:29:44 -05:00
|
|
|
},
|
|
|
|
{
|
2020-06-05 14:30:01 -04:00
|
|
|
'name': 'Tenant 6',
|
|
|
|
'slug': 'tenant-6',
|
|
|
|
'group': tenant_groups[1].pk,
|
2018-01-02 16:29:44 -05:00
|
|
|
},
|
|
|
|
]
|