mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Merge branch 'develop' into 2921-tags-select2
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
from django import forms
|
||||
from taggit.forms import TagField
|
||||
|
||||
from extras.forms import AddRemoveTagsForm, CustomFieldForm, CustomFieldBulkEditForm, CustomFieldFilterForm
|
||||
from extras.forms import (
|
||||
AddRemoveTagsForm, CustomFieldModelForm, CustomFieldBulkEditForm, CustomFieldModelCSVForm, CustomFieldFilterForm,
|
||||
)
|
||||
from utilities.forms import (
|
||||
APISelect, APISelectMultiple, BootstrapMixin, ChainedFieldsMixin, ChainedModelChoiceField, CommentField,
|
||||
FilterChoiceField, SlugField, TagFilterField
|
||||
@@ -38,7 +40,7 @@ class TenantGroupCSVForm(forms.ModelForm):
|
||||
# Tenants
|
||||
#
|
||||
|
||||
class TenantForm(BootstrapMixin, CustomFieldForm):
|
||||
class TenantForm(BootstrapMixin, CustomFieldModelForm):
|
||||
slug = SlugField()
|
||||
comments = CommentField()
|
||||
tags = TagField(
|
||||
@@ -57,7 +59,7 @@ class TenantForm(BootstrapMixin, CustomFieldForm):
|
||||
}
|
||||
|
||||
|
||||
class TenantCSVForm(forms.ModelForm):
|
||||
class TenantCSVForm(CustomFieldModelForm):
|
||||
slug = SlugField()
|
||||
group = forms.ModelChoiceField(
|
||||
queryset=TenantGroup.objects.all(),
|
||||
|
@@ -1,23 +1,17 @@
|
||||
import urllib.parse
|
||||
|
||||
from django.test import Client, TestCase
|
||||
from django.urls import reverse
|
||||
|
||||
from tenancy.models import Tenant, TenantGroup
|
||||
from utilities.testing import create_test_user
|
||||
from utilities.testing import StandardTestCases
|
||||
|
||||
|
||||
class TenantGroupTestCase(TestCase):
|
||||
class TenantGroupTestCase(StandardTestCases.Views):
|
||||
model = TenantGroup
|
||||
|
||||
def setUp(self):
|
||||
user = create_test_user(
|
||||
permissions=[
|
||||
'tenancy.view_tenantgroup',
|
||||
'tenancy.add_tenantgroup',
|
||||
]
|
||||
)
|
||||
self.client = Client()
|
||||
self.client.force_login(user)
|
||||
# Disable inapplicable tests
|
||||
test_get_object = None
|
||||
test_delete_object = None
|
||||
test_bulk_edit_objects = None
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
|
||||
TenantGroup.objects.bulk_create([
|
||||
TenantGroup(name='Tenant Group 1', slug='tenant-group-1'),
|
||||
@@ -25,75 +19,53 @@ 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.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_tenantgroup_import(self):
|
||||
|
||||
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.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(TenantGroup.objects.count(), 6)
|
||||
class TenantTestCase(StandardTestCases.Views):
|
||||
model = Tenant
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
|
||||
class TenantTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
user = create_test_user(
|
||||
permissions=[
|
||||
'tenancy.view_tenant',
|
||||
'tenancy.add_tenant',
|
||||
]
|
||||
tenantgroups = (
|
||||
TenantGroup(name='Tenant Group 1', slug='tenant-group-1'),
|
||||
TenantGroup(name='Tenant Group 2', slug='tenant-group-2'),
|
||||
)
|
||||
self.client = Client()
|
||||
self.client.force_login(user)
|
||||
|
||||
tenantgroup = TenantGroup(name='Tenant Group 1', slug='tenant-group-1')
|
||||
tenantgroup.save()
|
||||
TenantGroup.objects.bulk_create(tenantgroups)
|
||||
|
||||
Tenant.objects.bulk_create([
|
||||
Tenant(name='Tenant 1', slug='tenant-1', group=tenantgroup),
|
||||
Tenant(name='Tenant 2', slug='tenant-2', group=tenantgroup),
|
||||
Tenant(name='Tenant 3', slug='tenant-3', group=tenantgroup),
|
||||
Tenant(name='Tenant 1', slug='tenant-1', group=tenantgroups[0]),
|
||||
Tenant(name='Tenant 2', slug='tenant-2', group=tenantgroups[0]),
|
||||
Tenant(name='Tenant 3', slug='tenant-3', group=tenantgroups[0]),
|
||||
])
|
||||
|
||||
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': tenantgroups[1].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.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_tenant(self):
|
||||
|
||||
tenant = Tenant.objects.first()
|
||||
response = self.client.get(tenant.get_absolute_url(), follow=True)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_tenant_import(self):
|
||||
|
||||
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.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(Tenant.objects.count(), 6)
|
||||
cls.bulk_edit_data = {
|
||||
'group': tenantgroups[1].pk,
|
||||
}
|
||||
|
Reference in New Issue
Block a user