mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 05:28:16 -06:00
Clean up tests
This commit is contained in:
parent
ce08e8d437
commit
e3365ed509
@ -13,6 +13,7 @@ from extras.reports import Report
|
|||||||
from extras.scripts import BooleanVar, IntegerVar, Script, StringVar
|
from extras.scripts import BooleanVar, IntegerVar, Script, StringVar
|
||||||
from utilities.testing import APITestCase, APIViewTestCases
|
from utilities.testing import APITestCase, APIViewTestCases
|
||||||
|
|
||||||
|
|
||||||
User = get_user_model()
|
User = get_user_model()
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,20 +87,18 @@ class BulkEditCustomValidationTest(ModelViewTestCase):
|
|||||||
{'asns': {'required': True}}
|
{'asns': {'required': True}}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
def test_m2m_validation(self):
|
def test_bulk_edit_without_m2m(self):
|
||||||
"""
|
"""
|
||||||
Check that custom validation rules work for many-to-many fields.
|
Check that custom validation rules do not interfere with bulk editing.
|
||||||
"""
|
"""
|
||||||
providers = Provider.objects.all()
|
|
||||||
data = {
|
data = {
|
||||||
'pk': [provider.pk for provider in providers],
|
'pk': list(Provider.objects.values_list('pk', flat=True)),
|
||||||
'_apply': '',
|
'_apply': '',
|
||||||
'description': 'New description',
|
'description': 'New description',
|
||||||
}
|
}
|
||||||
self.add_permissions(
|
self.add_permissions(
|
||||||
'circuits.view_provider',
|
'circuits.view_provider',
|
||||||
'circuits.change_provider',
|
'circuits.change_provider',
|
||||||
'ipam.view_asn',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Bulk edit the description without changing ASN assignments
|
# Bulk edit the description without changing ASN assignments
|
||||||
@ -112,7 +110,27 @@ class BulkEditCustomValidationTest(ModelViewTestCase):
|
|||||||
self.assertHttpStatus(response, 302)
|
self.assertHttpStatus(response, 302)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
Provider.objects.filter(description=data['description']).count(),
|
Provider.objects.filter(description=data['description']).count(),
|
||||||
len(providers)
|
len(data['pk'])
|
||||||
|
)
|
||||||
|
|
||||||
|
@override_settings(CUSTOM_VALIDATORS={
|
||||||
|
'circuits.provider': [
|
||||||
|
{'asns': {'required': True}}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
def test_bulk_edit_m2m(self):
|
||||||
|
"""
|
||||||
|
Test that custom validation rules are enforced during bulk editing.
|
||||||
|
"""
|
||||||
|
data = {
|
||||||
|
'pk': list(Provider.objects.values_list('pk', flat=True)),
|
||||||
|
'_apply': '',
|
||||||
|
'description': 'New description',
|
||||||
|
}
|
||||||
|
self.add_permissions(
|
||||||
|
'circuits.view_provider',
|
||||||
|
'circuits.change_provider',
|
||||||
|
'ipam.view_asn',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Change the ASN assignments
|
# Change the ASN assignments
|
||||||
|
@ -5,7 +5,7 @@ from dcim.forms import SiteForm
|
|||||||
from dcim.models import Site
|
from dcim.models import Site
|
||||||
from extras.choices import CustomFieldTypeChoices
|
from extras.choices import CustomFieldTypeChoices
|
||||||
from extras.forms import SavedFilterForm
|
from extras.forms import SavedFilterForm
|
||||||
from extras.models import *
|
from extras.models import CustomField, CustomFieldChoiceSet
|
||||||
|
|
||||||
|
|
||||||
class CustomFieldModelFormTest(TestCase):
|
class CustomFieldModelFormTest(TestCase):
|
||||||
|
Loading…
Reference in New Issue
Block a user