mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #14629: Add filter tests for all q and description filters
This commit is contained in:
@ -25,8 +25,8 @@ class ProviderTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
ASN.objects.bulk_create(asns)
|
||||
|
||||
providers = (
|
||||
Provider(name='Provider 1', slug='provider-1'),
|
||||
Provider(name='Provider 2', slug='provider-2'),
|
||||
Provider(name='Provider 1', slug='provider-1', description='foobar1'),
|
||||
Provider(name='Provider 2', slug='provider-2', description='foobar2'),
|
||||
Provider(name='Provider 3', slug='provider-3'),
|
||||
Provider(name='Provider 4', slug='provider-4'),
|
||||
Provider(name='Provider 5', slug='provider-5'),
|
||||
@ -74,6 +74,10 @@ class ProviderTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
CircuitTermination(circuit=circuits[1], site=sites[0], term_side='A'),
|
||||
))
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Provider 1', 'Provider 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -82,6 +86,10 @@ class ProviderTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
params = {'slug': ['provider-1', 'provider-2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_asn_id(self): # ASN object assignment
|
||||
asns = ASN.objects.all()[:2]
|
||||
params = {'asn_id': [asns[0].pk, asns[1].pk]}
|
||||
@ -122,6 +130,10 @@ class CircuitTypeTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
CircuitType(name='Circuit Type 3', slug='circuit-type-3'),
|
||||
))
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Circuit Type 1']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
@ -227,6 +239,10 @@ class CircuitTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
))
|
||||
CircuitTermination.objects.bulk_create(circuit_terminations)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_cid(self):
|
||||
params = {'cid': ['Test Circuit 1', 'Test Circuit 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -369,6 +385,10 @@ class CircuitTerminationTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
|
||||
Cable(a_terminations=[circuit_terminations[0]], b_terminations=[circuit_terminations[1]]).save()
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_term_side(self):
|
||||
params = {'term_side': 'A'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 7)
|
||||
@ -440,6 +460,10 @@ class ProviderNetworkTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
)
|
||||
ProviderNetwork.objects.bulk_create(provider_networks)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Provider Network 1', 'Provider Network 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -477,6 +501,10 @@ class ProviderAccountTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
)
|
||||
ProviderAccount.objects.bulk_create(provider_accounts)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Provider Account 1', 'Provider Account 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
@ -21,14 +21,16 @@ class DataSourceTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
type=DataSourceTypeChoices.LOCAL,
|
||||
source_url='file:///var/tmp/source1/',
|
||||
status=DataSourceStatusChoices.NEW,
|
||||
enabled=True
|
||||
enabled=True,
|
||||
description='foobar1'
|
||||
),
|
||||
DataSource(
|
||||
name='Data Source 2',
|
||||
type=DataSourceTypeChoices.LOCAL,
|
||||
source_url='file:///var/tmp/source2/',
|
||||
status=DataSourceStatusChoices.SYNCING,
|
||||
enabled=True
|
||||
enabled=True,
|
||||
description='foobar2'
|
||||
),
|
||||
DataSource(
|
||||
name='Data Source 3',
|
||||
@ -40,10 +42,18 @@ class DataSourceTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
)
|
||||
DataSource.objects.bulk_create(data_sources)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Data Source 1', 'Data Source 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_type(self):
|
||||
params = {'type': [DataSourceTypeChoices.LOCAL]}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -97,6 +107,10 @@ class DataFileTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
)
|
||||
DataFile.objects.bulk_create(data_files)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'file1.txt'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_source(self):
|
||||
sources = DataSource.objects.all()
|
||||
params = {'source_id': [sources[0].pk, sources[1].pk]}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -40,7 +40,8 @@ class CustomFieldTestCase(TestCase, BaseFilterSetTests):
|
||||
required=True,
|
||||
weight=100,
|
||||
filter_logic=CustomFieldFilterLogicChoices.FILTER_LOOSE,
|
||||
ui_visibility=CustomFieldVisibilityChoices.VISIBILITY_READ_WRITE
|
||||
ui_visibility=CustomFieldVisibilityChoices.VISIBILITY_READ_WRITE,
|
||||
description='foobar1'
|
||||
),
|
||||
CustomField(
|
||||
name='Custom Field 2',
|
||||
@ -48,7 +49,8 @@ class CustomFieldTestCase(TestCase, BaseFilterSetTests):
|
||||
required=False,
|
||||
weight=200,
|
||||
filter_logic=CustomFieldFilterLogicChoices.FILTER_EXACT,
|
||||
ui_visibility=CustomFieldVisibilityChoices.VISIBILITY_READ_ONLY
|
||||
ui_visibility=CustomFieldVisibilityChoices.VISIBILITY_READ_ONLY,
|
||||
description='foobar2'
|
||||
),
|
||||
CustomField(
|
||||
name='Custom Field 3',
|
||||
@ -56,7 +58,8 @@ class CustomFieldTestCase(TestCase, BaseFilterSetTests):
|
||||
required=False,
|
||||
weight=300,
|
||||
filter_logic=CustomFieldFilterLogicChoices.FILTER_DISABLED,
|
||||
ui_visibility=CustomFieldVisibilityChoices.VISIBILITY_HIDDEN
|
||||
ui_visibility=CustomFieldVisibilityChoices.VISIBILITY_HIDDEN,
|
||||
description='foobar3'
|
||||
),
|
||||
CustomField(
|
||||
name='Custom Field 4',
|
||||
@ -84,6 +87,10 @@ class CustomFieldTestCase(TestCase, BaseFilterSetTests):
|
||||
custom_fields[3].content_types.add(ContentType.objects.get_by_natural_key('dcim', 'device'))
|
||||
custom_fields[4].content_types.add(ContentType.objects.get_by_natural_key('dcim', 'device'))
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Custom Field 1', 'Custom Field 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -116,6 +123,10 @@ class CustomFieldTestCase(TestCase, BaseFilterSetTests):
|
||||
params = {'choice_set_id': CustomFieldChoiceSet.objects.values_list('pk', flat=True)}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
|
||||
class CustomFieldChoiceSetTestCase(TestCase, BaseFilterSetTests):
|
||||
queryset = CustomFieldChoiceSet.objects.all()
|
||||
@ -124,12 +135,16 @@ class CustomFieldChoiceSetTestCase(TestCase, BaseFilterSetTests):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
choice_sets = (
|
||||
CustomFieldChoiceSet(name='Choice Set 1', extra_choices=['A', 'B', 'C']),
|
||||
CustomFieldChoiceSet(name='Choice Set 2', extra_choices=['D', 'E', 'F']),
|
||||
CustomFieldChoiceSet(name='Choice Set 3', extra_choices=['G', 'H', 'I']),
|
||||
CustomFieldChoiceSet(name='Choice Set 1', extra_choices=['A', 'B', 'C'], description='foobar1'),
|
||||
CustomFieldChoiceSet(name='Choice Set 2', extra_choices=['D', 'E', 'F'], description='foobar2'),
|
||||
CustomFieldChoiceSet(name='Choice Set 3', extra_choices=['G', 'H', 'I'], description='foobar3'),
|
||||
)
|
||||
CustomFieldChoiceSet.objects.bulk_create(choice_sets)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Choice Set 1', 'Choice Set 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -138,6 +153,10 @@ class CustomFieldChoiceSetTestCase(TestCase, BaseFilterSetTests):
|
||||
params = {'choice': ['A', 'D']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
|
||||
class WebhookTestCase(TestCase, BaseFilterSetTests):
|
||||
queryset = Webhook.objects.all()
|
||||
@ -216,6 +235,10 @@ class WebhookTestCase(TestCase, BaseFilterSetTests):
|
||||
webhooks[3].content_types.add(content_types[3])
|
||||
webhooks[4].content_types.add(content_types[4])
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'Webhook 1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Webhook 1', 'Webhook 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -297,6 +320,10 @@ class CustomLinkTestCase(TestCase, BaseFilterSetTests):
|
||||
for i, custom_link in enumerate(custom_links):
|
||||
custom_link.content_types.set([content_types[i]])
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'Custom Link 1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Custom Link 1', 'Custom Link 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -347,7 +374,8 @@ class SavedFilterTestCase(TestCase, BaseFilterSetTests):
|
||||
weight=100,
|
||||
enabled=True,
|
||||
shared=True,
|
||||
parameters={'status': ['active']}
|
||||
parameters={'status': ['active']},
|
||||
description='foobar1'
|
||||
),
|
||||
SavedFilter(
|
||||
name='Saved Filter 2',
|
||||
@ -356,7 +384,8 @@ class SavedFilterTestCase(TestCase, BaseFilterSetTests):
|
||||
weight=200,
|
||||
enabled=True,
|
||||
shared=True,
|
||||
parameters={'status': ['planned']}
|
||||
parameters={'status': ['planned']},
|
||||
description='foobar2'
|
||||
),
|
||||
SavedFilter(
|
||||
name='Saved Filter 3',
|
||||
@ -365,13 +394,18 @@ class SavedFilterTestCase(TestCase, BaseFilterSetTests):
|
||||
weight=300,
|
||||
enabled=False,
|
||||
shared=False,
|
||||
parameters={'status': ['retired']}
|
||||
parameters={'status': ['retired']},
|
||||
description='foobar3'
|
||||
),
|
||||
)
|
||||
SavedFilter.objects.bulk_create(saved_filters)
|
||||
for i, savedfilter in enumerate(saved_filters):
|
||||
savedfilter.content_types.set([content_types[i]])
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Saved Filter 1', 'Saved Filter 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -380,6 +414,10 @@ class SavedFilterTestCase(TestCase, BaseFilterSetTests):
|
||||
params = {'slug': ['saved-filter-1', 'saved-filter-2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_content_types(self):
|
||||
params = {'content_types': 'dcim.site'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
@ -423,8 +461,6 @@ class BookmarkTestCase(TestCase, BaseFilterSetTests):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
content_types = ContentType.objects.filter(model__in=['site', 'rack', 'device'])
|
||||
|
||||
users = (
|
||||
User(username='User 1'),
|
||||
User(username='User 2'),
|
||||
@ -505,6 +541,10 @@ class ExportTemplateTestCase(TestCase, BaseFilterSetTests):
|
||||
for i, et in enumerate(export_templates):
|
||||
et.content_types.set([content_types[i]])
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Export Template 1', 'Export Template 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -578,6 +618,10 @@ class ImageAttachmentTestCase(TestCase, BaseFilterSetTests):
|
||||
)
|
||||
ImageAttachment.objects.bulk_create(image_attachments)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'Attachment 1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Image Attachment 1', 'Image Attachment 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -630,41 +674,45 @@ class JournalEntryTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
assigned_object=sites[0],
|
||||
created_by=users[0],
|
||||
kind=JournalEntryKindChoices.KIND_INFO,
|
||||
comments='New journal entry'
|
||||
comments='foobar1'
|
||||
),
|
||||
JournalEntry(
|
||||
assigned_object=sites[0],
|
||||
created_by=users[1],
|
||||
kind=JournalEntryKindChoices.KIND_SUCCESS,
|
||||
comments='New journal entry'
|
||||
comments='foobar2'
|
||||
),
|
||||
JournalEntry(
|
||||
assigned_object=sites[1],
|
||||
created_by=users[2],
|
||||
kind=JournalEntryKindChoices.KIND_WARNING,
|
||||
comments='New journal entry'
|
||||
comments='foobar3'
|
||||
),
|
||||
JournalEntry(
|
||||
assigned_object=racks[0],
|
||||
created_by=users[0],
|
||||
kind=JournalEntryKindChoices.KIND_INFO,
|
||||
comments='New journal entry'
|
||||
comments='foobar4'
|
||||
),
|
||||
JournalEntry(
|
||||
assigned_object=racks[0],
|
||||
created_by=users[1],
|
||||
kind=JournalEntryKindChoices.KIND_SUCCESS,
|
||||
comments='New journal entry'
|
||||
comments='foobar5'
|
||||
),
|
||||
JournalEntry(
|
||||
assigned_object=racks[1],
|
||||
created_by=users[2],
|
||||
kind=JournalEntryKindChoices.KIND_WARNING,
|
||||
comments='New journal entry'
|
||||
comments='foobar6'
|
||||
),
|
||||
)
|
||||
JournalEntry.objects.bulk_create(journal_entries)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_created_by(self):
|
||||
users = User.objects.filter(username__in=['Alice', 'Bob'])
|
||||
params = {'created_by': [users[0].username, users[1].username]}
|
||||
@ -800,9 +848,10 @@ class ConfigContextTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
for i in range(0, 3):
|
||||
is_active = bool(i % 2)
|
||||
c = ConfigContext.objects.create(
|
||||
name='Config Context {}'.format(i + 1),
|
||||
name=f"Config Context {i + 1}",
|
||||
is_active=is_active,
|
||||
data='{"foo": 123}'
|
||||
data='{"foo": 123}',
|
||||
description=f"foobar{i + 1}"
|
||||
)
|
||||
c.regions.set([regions[i]])
|
||||
c.site_groups.set([site_groups[i]])
|
||||
@ -818,6 +867,10 @@ class ConfigContextTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
c.tenants.set([tenants[i]])
|
||||
c.tags.set([tags[i]])
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Config Context 1', 'Config Context 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -828,6 +881,10 @@ class ConfigContextTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
params = {'is_active': False}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_region(self):
|
||||
regions = Region.objects.all()[:2]
|
||||
params = {'region_id': [regions[0].pk, regions[1].pk]}
|
||||
@ -929,6 +986,10 @@ class ConfigTemplateTestCase(TestCase, BaseFilterSetTests):
|
||||
)
|
||||
ConfigTemplate.objects.bulk_create(config_templates)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Config Template 1', 'Config Template 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -965,6 +1026,10 @@ class TagTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
site.tags.set([tags[0]])
|
||||
provider.tags.set([tags[1]])
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Tag 1', 'Tag 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -1076,6 +1141,10 @@ class ObjectChangeTestCase(TestCase, BaseFilterSetTests):
|
||||
)
|
||||
ObjectChange.objects.bulk_create(object_changes)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'Site 1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
|
||||
|
||||
def test_user(self):
|
||||
params = {'user_id': User.objects.filter(username__in=['user1', 'user2']).values_list('pk', flat=True)}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
|
||||
|
@ -39,7 +39,7 @@ class ASNRangeTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
tenant=None,
|
||||
start=65000,
|
||||
end=65009,
|
||||
description='aaa'
|
||||
description='foobar1'
|
||||
),
|
||||
ASNRange(
|
||||
name='ASN Range 2',
|
||||
@ -48,7 +48,7 @@ class ASNRangeTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
tenant=tenants[0],
|
||||
start=65010,
|
||||
end=65019,
|
||||
description='bbb'
|
||||
description='foobar2'
|
||||
),
|
||||
ASNRange(
|
||||
name='ASN Range 3',
|
||||
@ -57,11 +57,15 @@ class ASNRangeTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
tenant=tenants[1],
|
||||
start=65020,
|
||||
end=65029,
|
||||
description='ccc'
|
||||
description='foobar3'
|
||||
),
|
||||
)
|
||||
ASNRange.objects.bulk_create(asn_ranges)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['ASN Range 1', 'ASN Range 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -89,7 +93,7 @@ class ASNRangeTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['aaa', 'bbb']}
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
|
||||
@ -123,9 +127,9 @@ class ASNTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
Tenant.objects.bulk_create(tenants)
|
||||
|
||||
asns = (
|
||||
ASN(asn=65001, rir=rirs[0], tenant=tenants[0], description='aaa'),
|
||||
ASN(asn=65002, rir=rirs[1], tenant=tenants[1], description='bbb'),
|
||||
ASN(asn=65003, rir=rirs[2], tenant=tenants[2], description='ccc'),
|
||||
ASN(asn=65001, rir=rirs[0], tenant=tenants[0], description='foobar1'),
|
||||
ASN(asn=65002, rir=rirs[1], tenant=tenants[1], description='foobar2'),
|
||||
ASN(asn=65003, rir=rirs[2], tenant=tenants[2], description='foobar3'),
|
||||
ASN(asn=4200000000, rir=rirs[0], tenant=tenants[0]),
|
||||
ASN(asn=4200000001, rir=rirs[1], tenant=tenants[1]),
|
||||
ASN(asn=4200000002, rir=rirs[2], tenant=tenants[2]),
|
||||
@ -139,6 +143,10 @@ class ASNTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
asns[4].sites.set([sites[1]])
|
||||
asns[5].sites.set([sites[2]])
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_asn(self):
|
||||
params = {'asn': [65001, 4200000000]}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -165,7 +173,7 @@ class ASNTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['aaa', 'bbb']}
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
|
||||
@ -214,6 +222,10 @@ class VRFTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
vrfs[2].import_targets.add(route_targets[2])
|
||||
vrfs[2].export_targets.add(route_targets[2])
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['VRF 1', 'VRF 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -310,6 +322,10 @@ class RouteTargetTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
vrfs[1].import_targets.add(route_targets[4], route_targets[5])
|
||||
vrfs[1].export_targets.add(route_targets[6], route_targets[7])
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['65000:1001', '65000:1002', '65000:1003']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
|
||||
@ -355,15 +371,19 @@ class RIRTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
def setUpTestData(cls):
|
||||
|
||||
rirs = (
|
||||
RIR(name='RIR 1', slug='rir-1', is_private=False, description='A'),
|
||||
RIR(name='RIR 2', slug='rir-2', is_private=False, description='B'),
|
||||
RIR(name='RIR 3', slug='rir-3', is_private=False, description='C'),
|
||||
RIR(name='RIR 4', slug='rir-4', is_private=True, description='D'),
|
||||
RIR(name='RIR 5', slug='rir-5', is_private=True, description='E'),
|
||||
RIR(name='RIR 6', slug='rir-6', is_private=True, description='F'),
|
||||
RIR(name='RIR 1', slug='rir-1', is_private=False, description='foobar1'),
|
||||
RIR(name='RIR 2', slug='rir-2', is_private=False, description='foobar2'),
|
||||
RIR(name='RIR 3', slug='rir-3', is_private=False, description='foobar3'),
|
||||
RIR(name='RIR 4', slug='rir-4', is_private=True),
|
||||
RIR(name='RIR 5', slug='rir-5', is_private=True),
|
||||
RIR(name='RIR 6', slug='rir-6', is_private=True),
|
||||
)
|
||||
RIR.objects.bulk_create(rirs)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['RIR 1', 'RIR 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -373,7 +393,7 @@ class RIRTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['A', 'B']}
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_is_private(self):
|
||||
@ -422,6 +442,10 @@ class AggregateTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
)
|
||||
Aggregate.objects.bulk_create(aggregates)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_family(self):
|
||||
params = {'family': '4'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
|
||||
@ -475,6 +499,10 @@ class RoleTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
)
|
||||
Role.objects.bulk_create(roles)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Role 1', 'Role 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -579,6 +607,10 @@ class PrefixTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
for prefix in prefixes:
|
||||
prefix.save()
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_family(self):
|
||||
params = {'family': '6'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 5)
|
||||
@ -745,17 +777,87 @@ class IPRangeTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
Tenant.objects.bulk_create(tenants)
|
||||
|
||||
ip_ranges = (
|
||||
IPRange(start_address='10.0.1.100/24', end_address='10.0.1.199/24', size=100, vrf=None, tenant=None, role=None, status=IPRangeStatusChoices.STATUS_ACTIVE, description='foobar1'),
|
||||
IPRange(start_address='10.0.2.100/24', end_address='10.0.2.199/24', size=100, vrf=vrfs[0], tenant=tenants[0], role=roles[0], status=IPRangeStatusChoices.STATUS_ACTIVE, description='foobar2'),
|
||||
IPRange(start_address='10.0.3.100/24', end_address='10.0.3.199/24', size=100, vrf=vrfs[1], tenant=tenants[1], role=roles[1], status=IPRangeStatusChoices.STATUS_DEPRECATED),
|
||||
IPRange(start_address='10.0.4.100/24', end_address='10.0.4.199/24', size=100, vrf=vrfs[2], tenant=tenants[2], role=roles[2], status=IPRangeStatusChoices.STATUS_RESERVED),
|
||||
IPRange(start_address='2001:db8:0:1::1/64', end_address='2001:db8:0:1::100/64', size=100, vrf=None, tenant=None, role=None, status=IPRangeStatusChoices.STATUS_ACTIVE),
|
||||
IPRange(start_address='2001:db8:0:2::1/64', end_address='2001:db8:0:2::100/64', size=100, vrf=vrfs[0], tenant=tenants[0], role=roles[0], status=IPRangeStatusChoices.STATUS_ACTIVE),
|
||||
IPRange(start_address='2001:db8:0:3::1/64', end_address='2001:db8:0:3::100/64', size=100, vrf=vrfs[1], tenant=tenants[1], role=roles[1], status=IPRangeStatusChoices.STATUS_DEPRECATED),
|
||||
IPRange(start_address='2001:db8:0:4::1/64', end_address='2001:db8:0:4::100/64', size=100, vrf=vrfs[2], tenant=tenants[2], role=roles[2], status=IPRangeStatusChoices.STATUS_RESERVED),
|
||||
IPRange(
|
||||
start_address='10.0.1.100/24',
|
||||
end_address='10.0.1.199/24',
|
||||
size=100,
|
||||
vrf=None,
|
||||
tenant=None,
|
||||
role=None,
|
||||
status=IPRangeStatusChoices.STATUS_ACTIVE,
|
||||
description='foobar1'
|
||||
),
|
||||
IPRange(
|
||||
start_address='10.0.2.100/24',
|
||||
end_address='10.0.2.199/24',
|
||||
size=100,
|
||||
vrf=vrfs[0],
|
||||
tenant=tenants[0],
|
||||
role=roles[0],
|
||||
status=IPRangeStatusChoices.STATUS_ACTIVE,
|
||||
description='foobar2'
|
||||
),
|
||||
IPRange(
|
||||
start_address='10.0.3.100/24',
|
||||
end_address='10.0.3.199/24',
|
||||
size=100,
|
||||
vrf=vrfs[1],
|
||||
tenant=tenants[1],
|
||||
role=roles[1],
|
||||
status=IPRangeStatusChoices.STATUS_DEPRECATED
|
||||
),
|
||||
IPRange(
|
||||
start_address='10.0.4.100/24',
|
||||
end_address='10.0.4.199/24',
|
||||
size=100,
|
||||
vrf=vrfs[2],
|
||||
tenant=tenants[2],
|
||||
role=roles[2],
|
||||
status=IPRangeStatusChoices.STATUS_RESERVED
|
||||
),
|
||||
IPRange(
|
||||
start_address='2001:db8:0:1::1/64',
|
||||
end_address='2001:db8:0:1::100/64',
|
||||
size=100,
|
||||
vrf=None,
|
||||
tenant=None,
|
||||
role=None,
|
||||
status=IPRangeStatusChoices.STATUS_ACTIVE
|
||||
),
|
||||
IPRange(
|
||||
start_address='2001:db8:0:2::1/64',
|
||||
end_address='2001:db8:0:2::100/64',
|
||||
size=100,
|
||||
vrf=vrfs[0],
|
||||
tenant=tenants[0],
|
||||
role=roles[0],
|
||||
status=IPRangeStatusChoices.STATUS_ACTIVE
|
||||
),
|
||||
IPRange(
|
||||
start_address='2001:db8:0:3::1/64',
|
||||
end_address='2001:db8:0:3::100/64',
|
||||
size=100,
|
||||
vrf=vrfs[1],
|
||||
tenant=tenants[1],
|
||||
role=roles[1],
|
||||
status=IPRangeStatusChoices.STATUS_DEPRECATED
|
||||
),
|
||||
IPRange(
|
||||
start_address='2001:db8:0:4::1/64',
|
||||
end_address='2001:db8:0:4::100/64',
|
||||
size=100,
|
||||
vrf=vrfs[2],
|
||||
tenant=tenants[2],
|
||||
role=roles[2],
|
||||
status=IPRangeStatusChoices.STATUS_RESERVED
|
||||
),
|
||||
)
|
||||
IPRange.objects.bulk_create(ip_ranges)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_family(self):
|
||||
params = {'family': '6'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
|
||||
@ -889,21 +991,111 @@ class IPAddressTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
Tenant.objects.bulk_create(tenants)
|
||||
|
||||
ipaddresses = (
|
||||
IPAddress(address='10.0.0.1/24', tenant=None, vrf=None, assigned_object=None, status=IPAddressStatusChoices.STATUS_ACTIVE, dns_name='ipaddress-a', description='foobar1'),
|
||||
IPAddress(address='10.0.0.2/24', tenant=tenants[0], vrf=vrfs[0], assigned_object=interfaces[0], status=IPAddressStatusChoices.STATUS_ACTIVE, dns_name='ipaddress-b'),
|
||||
IPAddress(address='10.0.0.3/24', tenant=tenants[1], vrf=vrfs[1], assigned_object=interfaces[1], status=IPAddressStatusChoices.STATUS_RESERVED, role=IPAddressRoleChoices.ROLE_VIP, dns_name='ipaddress-c'),
|
||||
IPAddress(address='10.0.0.4/24', tenant=tenants[2], vrf=vrfs[2], assigned_object=interfaces[2], status=IPAddressStatusChoices.STATUS_DEPRECATED, role=IPAddressRoleChoices.ROLE_SECONDARY, dns_name='ipaddress-d'),
|
||||
IPAddress(address='10.0.0.5/24', tenant=None, vrf=None, assigned_object=fhrp_groups[0], status=IPAddressStatusChoices.STATUS_ACTIVE),
|
||||
IPAddress(address='10.0.0.1/25', tenant=None, vrf=None, assigned_object=None, status=IPAddressStatusChoices.STATUS_ACTIVE),
|
||||
IPAddress(address='2001:db8::1/64', tenant=None, vrf=None, assigned_object=None, status=IPAddressStatusChoices.STATUS_ACTIVE, dns_name='ipaddress-a', description='foobar2'),
|
||||
IPAddress(address='2001:db8::2/64', tenant=tenants[0], vrf=vrfs[0], assigned_object=vminterfaces[0], status=IPAddressStatusChoices.STATUS_ACTIVE, dns_name='ipaddress-b'),
|
||||
IPAddress(address='2001:db8::3/64', tenant=tenants[1], vrf=vrfs[1], assigned_object=vminterfaces[1], status=IPAddressStatusChoices.STATUS_RESERVED, role=IPAddressRoleChoices.ROLE_VIP, dns_name='ipaddress-c'),
|
||||
IPAddress(address='2001:db8::4/64', tenant=tenants[2], vrf=vrfs[2], assigned_object=vminterfaces[2], status=IPAddressStatusChoices.STATUS_DEPRECATED, role=IPAddressRoleChoices.ROLE_SECONDARY, dns_name='ipaddress-d'),
|
||||
IPAddress(address='2001:db8::5/64', tenant=None, vrf=None, assigned_object=fhrp_groups[1], status=IPAddressStatusChoices.STATUS_ACTIVE),
|
||||
IPAddress(address='2001:db8::1/65', tenant=None, vrf=None, assigned_object=None, status=IPAddressStatusChoices.STATUS_ACTIVE),
|
||||
IPAddress(
|
||||
address='10.0.0.1/24',
|
||||
tenant=None,
|
||||
vrf=None,
|
||||
assigned_object=None,
|
||||
status=IPAddressStatusChoices.STATUS_ACTIVE,
|
||||
dns_name='ipaddress-a',
|
||||
description='foobar1'
|
||||
),
|
||||
IPAddress(
|
||||
address='10.0.0.2/24',
|
||||
tenant=tenants[0],
|
||||
vrf=vrfs[0],
|
||||
assigned_object=interfaces[0],
|
||||
status=IPAddressStatusChoices.STATUS_ACTIVE,
|
||||
dns_name='ipaddress-b'
|
||||
),
|
||||
IPAddress(
|
||||
address='10.0.0.3/24',
|
||||
tenant=tenants[1],
|
||||
vrf=vrfs[1],
|
||||
assigned_object=interfaces[1],
|
||||
status=IPAddressStatusChoices.STATUS_RESERVED,
|
||||
role=IPAddressRoleChoices.ROLE_VIP,
|
||||
dns_name='ipaddress-c'
|
||||
),
|
||||
IPAddress(
|
||||
address='10.0.0.4/24',
|
||||
tenant=tenants[2],
|
||||
vrf=vrfs[2],
|
||||
assigned_object=interfaces[2],
|
||||
status=IPAddressStatusChoices.STATUS_DEPRECATED,
|
||||
role=IPAddressRoleChoices.ROLE_SECONDARY,
|
||||
dns_name='ipaddress-d'
|
||||
),
|
||||
IPAddress(
|
||||
address='10.0.0.5/24',
|
||||
tenant=None,
|
||||
vrf=None,
|
||||
assigned_object=fhrp_groups[0],
|
||||
status=IPAddressStatusChoices.STATUS_ACTIVE
|
||||
),
|
||||
IPAddress(
|
||||
address='10.0.0.1/25',
|
||||
tenant=None,
|
||||
vrf=None,
|
||||
assigned_object=None,
|
||||
status=IPAddressStatusChoices.STATUS_ACTIVE
|
||||
),
|
||||
IPAddress(
|
||||
address='2001:db8::1/64',
|
||||
tenant=None,
|
||||
vrf=None,
|
||||
assigned_object=None,
|
||||
status=IPAddressStatusChoices.STATUS_ACTIVE,
|
||||
dns_name='ipaddress-a',
|
||||
description='foobar2'
|
||||
),
|
||||
IPAddress(
|
||||
address='2001:db8::2/64',
|
||||
tenant=tenants[0],
|
||||
vrf=vrfs[0],
|
||||
assigned_object=vminterfaces[0],
|
||||
status=IPAddressStatusChoices.STATUS_ACTIVE,
|
||||
dns_name='ipaddress-b'
|
||||
),
|
||||
IPAddress(
|
||||
address='2001:db8::3/64',
|
||||
tenant=tenants[1],
|
||||
vrf=vrfs[1],
|
||||
assigned_object=vminterfaces[1],
|
||||
status=IPAddressStatusChoices.STATUS_RESERVED,
|
||||
role=IPAddressRoleChoices.ROLE_VIP,
|
||||
dns_name='ipaddress-c'
|
||||
),
|
||||
IPAddress(
|
||||
address='2001:db8::4/64',
|
||||
tenant=tenants[2],
|
||||
vrf=vrfs[2],
|
||||
assigned_object=vminterfaces[2],
|
||||
status=IPAddressStatusChoices.STATUS_DEPRECATED,
|
||||
role=IPAddressRoleChoices.ROLE_SECONDARY,
|
||||
dns_name='ipaddress-d'
|
||||
),
|
||||
IPAddress(
|
||||
address='2001:db8::5/64',
|
||||
tenant=None,
|
||||
vrf=None,
|
||||
assigned_object=fhrp_groups[1],
|
||||
status=IPAddressStatusChoices.STATUS_ACTIVE
|
||||
),
|
||||
IPAddress(
|
||||
address='2001:db8::1/65',
|
||||
tenant=None,
|
||||
vrf=None,
|
||||
assigned_object=None,
|
||||
status=IPAddressStatusChoices.STATUS_ACTIVE
|
||||
),
|
||||
)
|
||||
IPAddress.objects.bulk_create(ipaddresses)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_family(self):
|
||||
params = {'family': '4'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 6)
|
||||
@ -1055,15 +1247,36 @@ class FHRPGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
IPAddress.objects.bulk_create(ip_addresses)
|
||||
|
||||
fhrp_groups = (
|
||||
FHRPGroup(protocol=FHRPGroupProtocolChoices.PROTOCOL_VRRP2, group_id=10, auth_type=FHRPGroupAuthTypeChoices.AUTHENTICATION_PLAINTEXT, auth_key='foo123'),
|
||||
FHRPGroup(protocol=FHRPGroupProtocolChoices.PROTOCOL_VRRP3, group_id=20, auth_type=FHRPGroupAuthTypeChoices.AUTHENTICATION_MD5, auth_key='bar456', name='bar123'),
|
||||
FHRPGroup(protocol=FHRPGroupProtocolChoices.PROTOCOL_HSRP, group_id=30),
|
||||
FHRPGroup(
|
||||
protocol=FHRPGroupProtocolChoices.PROTOCOL_VRRP2,
|
||||
group_id=10,
|
||||
auth_type=FHRPGroupAuthTypeChoices.AUTHENTICATION_PLAINTEXT,
|
||||
auth_key='foo123',
|
||||
description='foobar1'
|
||||
),
|
||||
FHRPGroup(
|
||||
protocol=FHRPGroupProtocolChoices.PROTOCOL_VRRP3,
|
||||
group_id=20,
|
||||
auth_type=FHRPGroupAuthTypeChoices.AUTHENTICATION_MD5,
|
||||
auth_key='bar456',
|
||||
name='bar123',
|
||||
description='foobar2'
|
||||
),
|
||||
FHRPGroup(
|
||||
protocol=FHRPGroupProtocolChoices.PROTOCOL_HSRP,
|
||||
group_id=30,
|
||||
description='foobar3'
|
||||
),
|
||||
)
|
||||
FHRPGroup.objects.bulk_create(fhrp_groups)
|
||||
fhrp_groups[0].ip_addresses.set([ip_addresses[0]])
|
||||
fhrp_groups[1].ip_addresses.set([ip_addresses[1]])
|
||||
fhrp_groups[2].ip_addresses.set([ip_addresses[2]])
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_protocol(self):
|
||||
params = {'protocol': [FHRPGroupProtocolChoices.PROTOCOL_VRRP2, FHRPGroupProtocolChoices.PROTOCOL_VRRP3]}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -1084,6 +1297,10 @@ class FHRPGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
params = {'name': ['bar123', ]}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_related_ip(self):
|
||||
# Create some regular IPs to query for related IPs
|
||||
ipaddresses = (
|
||||
@ -1199,17 +1416,21 @@ class VLANGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
cluster.save()
|
||||
|
||||
vlan_groups = (
|
||||
VLANGroup(name='VLAN Group 1', slug='vlan-group-1', scope=region, description='A'),
|
||||
VLANGroup(name='VLAN Group 2', slug='vlan-group-2', scope=sitegroup, description='B'),
|
||||
VLANGroup(name='VLAN Group 3', slug='vlan-group-3', scope=site, description='C'),
|
||||
VLANGroup(name='VLAN Group 4', slug='vlan-group-4', scope=location, description='D'),
|
||||
VLANGroup(name='VLAN Group 5', slug='vlan-group-5', scope=rack, description='E'),
|
||||
VLANGroup(name='VLAN Group 6', slug='vlan-group-6', scope=clustergroup, description='F'),
|
||||
VLANGroup(name='VLAN Group 7', slug='vlan-group-7', scope=cluster, description='G'),
|
||||
VLANGroup(name='VLAN Group 1', slug='vlan-group-1', scope=region, description='foobar1'),
|
||||
VLANGroup(name='VLAN Group 2', slug='vlan-group-2', scope=sitegroup, description='foobar2'),
|
||||
VLANGroup(name='VLAN Group 3', slug='vlan-group-3', scope=site, description='foobar3'),
|
||||
VLANGroup(name='VLAN Group 4', slug='vlan-group-4', scope=location),
|
||||
VLANGroup(name='VLAN Group 5', slug='vlan-group-5', scope=rack),
|
||||
VLANGroup(name='VLAN Group 6', slug='vlan-group-6', scope=clustergroup),
|
||||
VLANGroup(name='VLAN Group 7', slug='vlan-group-7', scope=cluster),
|
||||
VLANGroup(name='VLAN Group 8', slug='vlan-group-8'),
|
||||
)
|
||||
VLANGroup.objects.bulk_create(vlan_groups)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['VLAN Group 1', 'VLAN Group 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -1219,7 +1440,7 @@ class VLANGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['A', 'B']}
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_region(self):
|
||||
@ -1424,6 +1645,10 @@ class VLANTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
)
|
||||
VLAN.objects.bulk_create(vlans)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['VLAN 101', 'VLAN 102']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -1512,15 +1737,46 @@ class ServiceTemplateTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
service_templates = (
|
||||
ServiceTemplate(name='Service Template 1', protocol=ServiceProtocolChoices.PROTOCOL_TCP, ports=[1001]),
|
||||
ServiceTemplate(name='Service Template 2', protocol=ServiceProtocolChoices.PROTOCOL_TCP, ports=[1002]),
|
||||
ServiceTemplate(name='Service Template 3', protocol=ServiceProtocolChoices.PROTOCOL_UDP, ports=[1003]),
|
||||
ServiceTemplate(name='Service Template 4', protocol=ServiceProtocolChoices.PROTOCOL_TCP, ports=[2001]),
|
||||
ServiceTemplate(name='Service Template 5', protocol=ServiceProtocolChoices.PROTOCOL_TCP, ports=[2002]),
|
||||
ServiceTemplate(name='Service Template 6', protocol=ServiceProtocolChoices.PROTOCOL_UDP, ports=[2003]),
|
||||
ServiceTemplate(
|
||||
name='Service Template 1',
|
||||
protocol=ServiceProtocolChoices.PROTOCOL_TCP,
|
||||
ports=[1001],
|
||||
description='foobar1'
|
||||
),
|
||||
ServiceTemplate(
|
||||
name='Service Template 2',
|
||||
protocol=ServiceProtocolChoices.PROTOCOL_TCP,
|
||||
ports=[1002],
|
||||
description='foobar2'
|
||||
),
|
||||
ServiceTemplate(
|
||||
name='Service Template 3',
|
||||
protocol=ServiceProtocolChoices.PROTOCOL_UDP,
|
||||
ports=[1003],
|
||||
description='foobar3'
|
||||
),
|
||||
ServiceTemplate(
|
||||
name='Service Template 4',
|
||||
protocol=ServiceProtocolChoices.PROTOCOL_TCP,
|
||||
ports=[2001]
|
||||
),
|
||||
ServiceTemplate(
|
||||
name='Service Template 5',
|
||||
protocol=ServiceProtocolChoices.PROTOCOL_TCP,
|
||||
ports=[2002]
|
||||
),
|
||||
ServiceTemplate(
|
||||
name='Service Template 6',
|
||||
protocol=ServiceProtocolChoices.PROTOCOL_UDP,
|
||||
ports=[2003]
|
||||
),
|
||||
)
|
||||
ServiceTemplate.objects.bulk_create(service_templates)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Service Template 1', 'Service Template 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -1533,6 +1789,10 @@ class ServiceTemplateTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
params = {'port': '1001'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
|
||||
class ServiceTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
queryset = Service.objects.all()
|
||||
@ -1589,6 +1849,10 @@ class ServiceTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
services[1].ipaddresses.add(ip_addresses[1])
|
||||
services[2].ipaddresses.add(ip_addresses[2])
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Service 1', 'Service 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -1645,9 +1909,26 @@ class L2VPNTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
RouteTarget.objects.bulk_create(route_targets)
|
||||
|
||||
l2vpns = (
|
||||
L2VPN(name='L2VPN 1', slug='l2vpn-1', type=L2VPNTypeChoices.TYPE_VXLAN, identifier=65001),
|
||||
L2VPN(name='L2VPN 2', slug='l2vpn-2', type=L2VPNTypeChoices.TYPE_VPWS, identifier=65002),
|
||||
L2VPN(name='L2VPN 3', slug='l2vpn-3', type=L2VPNTypeChoices.TYPE_VPLS),
|
||||
L2VPN(
|
||||
name='L2VPN 1',
|
||||
slug='l2vpn-1',
|
||||
type=L2VPNTypeChoices.TYPE_VXLAN,
|
||||
identifier=65001,
|
||||
description='foobar1'
|
||||
),
|
||||
L2VPN(
|
||||
name='L2VPN 2',
|
||||
slug='l2vpn-2',
|
||||
type=L2VPNTypeChoices.TYPE_VPWS,
|
||||
identifier=65002,
|
||||
description='foobar2'
|
||||
),
|
||||
L2VPN(
|
||||
name='L2VPN 3',
|
||||
slug='l2vpn-3',
|
||||
type=L2VPNTypeChoices.TYPE_VPLS,
|
||||
description='foobar3'
|
||||
),
|
||||
)
|
||||
L2VPN.objects.bulk_create(l2vpns)
|
||||
l2vpns[0].import_targets.add(route_targets[0])
|
||||
@ -1657,6 +1938,10 @@ class L2VPNTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
l2vpns[1].export_targets.add(route_targets[4])
|
||||
l2vpns[2].export_targets.add(route_targets[5])
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['L2VPN 1', 'L2VPN 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -1673,6 +1958,10 @@ class L2VPNTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
params = {'type': [L2VPNTypeChoices.TYPE_VXLAN, L2VPNTypeChoices.TYPE_VPWS]}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_import_targets(self):
|
||||
route_targets = RouteTarget.objects.filter(name__in=['1:1', '1:2'])
|
||||
params = {'import_target_id': [route_targets[0].pk, route_targets[1].pk]}
|
||||
|
@ -23,13 +23,32 @@ class TenantGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
tenantgroup.save()
|
||||
|
||||
tenant_groups = (
|
||||
TenantGroup(name='Tenant Group 1', slug='tenant-group-1', parent=parent_tenant_groups[0], description='A'),
|
||||
TenantGroup(name='Tenant Group 2', slug='tenant-group-2', parent=parent_tenant_groups[1], description='B'),
|
||||
TenantGroup(name='Tenant Group 3', slug='tenant-group-3', parent=parent_tenant_groups[2], description='C'),
|
||||
TenantGroup(
|
||||
name='Tenant Group 1',
|
||||
slug='tenant-group-1',
|
||||
parent=parent_tenant_groups[0],
|
||||
description='foobar1'
|
||||
),
|
||||
TenantGroup(
|
||||
name='Tenant Group 2',
|
||||
slug='tenant-group-2',
|
||||
parent=parent_tenant_groups[1],
|
||||
description='foobar2'
|
||||
),
|
||||
TenantGroup(
|
||||
name='Tenant Group 3',
|
||||
slug='tenant-group-3',
|
||||
parent=parent_tenant_groups[2],
|
||||
description='foobar3'
|
||||
),
|
||||
)
|
||||
for tenantgroup in tenant_groups:
|
||||
tenantgroup.save()
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Tenant Group 1', 'Tenant Group 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -39,7 +58,7 @@ class TenantGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['A', 'B']}
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_parent(self):
|
||||
@ -68,10 +87,14 @@ class TenantTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
tenants = (
|
||||
Tenant(name='Tenant 1', slug='tenant-1', group=tenant_groups[0], description='foobar1'),
|
||||
Tenant(name='Tenant 2', slug='tenant-2', group=tenant_groups[1], description='foobar2'),
|
||||
Tenant(name='Tenant 3', slug='tenant-3', group=tenant_groups[2]),
|
||||
Tenant(name='Tenant 3', slug='tenant-3', group=tenant_groups[2], description='foobar3'),
|
||||
)
|
||||
Tenant.objects.bulk_create(tenants)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Tenant 1', 'Tenant 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -108,13 +131,32 @@ class ContactGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
contactgroup.save()
|
||||
|
||||
contact_groups = (
|
||||
ContactGroup(name='Contact Group 1', slug='contact-group-1', parent=parent_contact_groups[0], description='A'),
|
||||
ContactGroup(name='Contact Group 2', slug='contact-group-2', parent=parent_contact_groups[1], description='B'),
|
||||
ContactGroup(name='Contact Group 3', slug='contact-group-3', parent=parent_contact_groups[2], description='C'),
|
||||
ContactGroup(
|
||||
name='Contact Group 1',
|
||||
slug='contact-group-1',
|
||||
parent=parent_contact_groups[0],
|
||||
description='foobar1'
|
||||
),
|
||||
ContactGroup(
|
||||
name='Contact Group 2',
|
||||
slug='contact-group-2',
|
||||
parent=parent_contact_groups[1],
|
||||
description='foobar2'
|
||||
),
|
||||
ContactGroup(
|
||||
name='Contact Group 3',
|
||||
slug='contact-group-3',
|
||||
parent=parent_contact_groups[2],
|
||||
description='foobar3'
|
||||
),
|
||||
)
|
||||
for contactgroup in contact_groups:
|
||||
contactgroup.save()
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Contact Group 1', 'Contact Group 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -124,7 +166,7 @@ class ContactGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['A', 'B']}
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_parent(self):
|
||||
@ -145,10 +187,14 @@ class ContactRoleTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
contact_roles = (
|
||||
ContactRole(name='Contact Role 1', slug='contact-role-1', description='foobar1'),
|
||||
ContactRole(name='Contact Role 2', slug='contact-role-2', description='foobar2'),
|
||||
ContactRole(name='Contact Role 3', slug='contact-role-3'),
|
||||
ContactRole(name='Contact Role 3', slug='contact-role-3', description='foobar3'),
|
||||
)
|
||||
ContactRole.objects.bulk_create(contact_roles)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Contact Role 1', 'Contact Role 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -178,16 +224,24 @@ class ContactTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
contactgroup.save()
|
||||
|
||||
contacts = (
|
||||
Contact(name='Contact 1', group=contact_groups[0]),
|
||||
Contact(name='Contact 2', group=contact_groups[1]),
|
||||
Contact(name='Contact 3', group=contact_groups[2]),
|
||||
Contact(name='Contact 1', group=contact_groups[0], description='foobar1'),
|
||||
Contact(name='Contact 2', group=contact_groups[1], description='foobar2'),
|
||||
Contact(name='Contact 3', group=contact_groups[2], description='foobar3'),
|
||||
)
|
||||
Contact.objects.bulk_create(contacts)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Contact 1', 'Contact 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_group(self):
|
||||
group = ContactGroup.objects.all()[:2]
|
||||
params = {'group_id': [group[0].pk, group[1].pk]}
|
||||
|
@ -67,6 +67,10 @@ class UserTestCase(TestCase, BaseFilterSetTests):
|
||||
users[1].groups.set([groups[1]])
|
||||
users[2].groups.set([groups[2]])
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'user1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_username(self):
|
||||
params = {'username': ['User1', 'User2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -117,6 +121,10 @@ class GroupTestCase(TestCase, BaseFilterSetTests):
|
||||
)
|
||||
Group.objects.bulk_create(groups)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'group 1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Group 1', 'Group 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -164,6 +172,10 @@ class ObjectPermissionTestCase(TestCase, BaseFilterSetTests):
|
||||
permissions[i].users.set([users[i]])
|
||||
permissions[i].object_types.set([object_types[i]])
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Permission 1', 'Permission 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -235,6 +247,10 @@ class TokenTestCase(TestCase, BaseFilterSetTests):
|
||||
)
|
||||
Token.objects.bulk_create(tokens)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_user(self):
|
||||
users = User.objects.order_by('id')[:2]
|
||||
params = {'user_id': [users[0].pk, users[1].pk]}
|
||||
|
@ -17,12 +17,16 @@ class ClusterTypeTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
def setUpTestData(cls):
|
||||
|
||||
cluster_types = (
|
||||
ClusterType(name='Cluster Type 1', slug='cluster-type-1', description='A'),
|
||||
ClusterType(name='Cluster Type 2', slug='cluster-type-2', description='B'),
|
||||
ClusterType(name='Cluster Type 3', slug='cluster-type-3', description='C'),
|
||||
ClusterType(name='Cluster Type 1', slug='cluster-type-1', description='foobar1'),
|
||||
ClusterType(name='Cluster Type 2', slug='cluster-type-2', description='foobar2'),
|
||||
ClusterType(name='Cluster Type 3', slug='cluster-type-3', description='foobar3'),
|
||||
)
|
||||
ClusterType.objects.bulk_create(cluster_types)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Cluster Type 1', 'Cluster Type 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -32,7 +36,7 @@ class ClusterTypeTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['A', 'B']}
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
|
||||
@ -44,12 +48,16 @@ class ClusterGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
def setUpTestData(cls):
|
||||
|
||||
cluster_groups = (
|
||||
ClusterGroup(name='Cluster Group 1', slug='cluster-group-1', description='A'),
|
||||
ClusterGroup(name='Cluster Group 2', slug='cluster-group-2', description='B'),
|
||||
ClusterGroup(name='Cluster Group 3', slug='cluster-group-3', description='C'),
|
||||
ClusterGroup(name='Cluster Group 1', slug='cluster-group-1', description='foobar1'),
|
||||
ClusterGroup(name='Cluster Group 2', slug='cluster-group-2', description='foobar2'),
|
||||
ClusterGroup(name='Cluster Group 3', slug='cluster-group-3', description='foobar3'),
|
||||
)
|
||||
ClusterGroup.objects.bulk_create(cluster_groups)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Cluster Group 1', 'Cluster Group 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -59,7 +67,7 @@ class ClusterGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['A', 'B']}
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
|
||||
@ -123,16 +131,48 @@ class ClusterTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
Tenant.objects.bulk_create(tenants)
|
||||
|
||||
clusters = (
|
||||
Cluster(name='Cluster 1', type=cluster_types[0], group=cluster_groups[0], status=ClusterStatusChoices.STATUS_PLANNED, site=sites[0], tenant=tenants[0]),
|
||||
Cluster(name='Cluster 2', type=cluster_types[1], group=cluster_groups[1], status=ClusterStatusChoices.STATUS_STAGING, site=sites[1], tenant=tenants[1]),
|
||||
Cluster(name='Cluster 3', type=cluster_types[2], group=cluster_groups[2], status=ClusterStatusChoices.STATUS_ACTIVE, site=sites[2], tenant=tenants[2]),
|
||||
Cluster(
|
||||
name='Cluster 1',
|
||||
type=cluster_types[0],
|
||||
group=cluster_groups[0],
|
||||
status=ClusterStatusChoices.STATUS_PLANNED,
|
||||
site=sites[0],
|
||||
tenant=tenants[0],
|
||||
description='foobar1'
|
||||
),
|
||||
Cluster(
|
||||
name='Cluster 2',
|
||||
type=cluster_types[1],
|
||||
group=cluster_groups[1],
|
||||
status=ClusterStatusChoices.STATUS_STAGING,
|
||||
site=sites[1],
|
||||
tenant=tenants[1],
|
||||
description='foobar2'
|
||||
),
|
||||
Cluster(
|
||||
name='Cluster 3',
|
||||
type=cluster_types[2],
|
||||
group=cluster_groups[2],
|
||||
status=ClusterStatusChoices.STATUS_ACTIVE,
|
||||
site=sites[2],
|
||||
tenant=tenants[2],
|
||||
description='foobar3'
|
||||
),
|
||||
)
|
||||
Cluster.objects.bulk_create(clusters)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Cluster 1', 'Cluster 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_region(self):
|
||||
regions = Region.objects.all()[:2]
|
||||
params = {'region_id': [regions[0].pk, regions[1].pk]}
|
||||
@ -274,9 +314,49 @@ class VirtualMachineTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
Tenant.objects.bulk_create(tenants)
|
||||
|
||||
vms = (
|
||||
VirtualMachine(name='Virtual Machine 1', site=sites[0], cluster=clusters[0], device=devices[0], platform=platforms[0], role=roles[0], tenant=tenants[0], status=VirtualMachineStatusChoices.STATUS_ACTIVE, vcpus=1, memory=1, disk=1, local_context_data={"foo": 123}),
|
||||
VirtualMachine(name='Virtual Machine 2', site=sites[1], cluster=clusters[1], device=devices[1], platform=platforms[1], role=roles[1], tenant=tenants[1], status=VirtualMachineStatusChoices.STATUS_STAGED, vcpus=2, memory=2, disk=2),
|
||||
VirtualMachine(name='Virtual Machine 3', site=sites[2], cluster=clusters[2], device=devices[2], platform=platforms[2], role=roles[2], tenant=tenants[2], status=VirtualMachineStatusChoices.STATUS_OFFLINE, vcpus=3, memory=3, disk=3),
|
||||
VirtualMachine(
|
||||
name='Virtual Machine 1',
|
||||
site=sites[0],
|
||||
cluster=clusters[0],
|
||||
device=devices[0],
|
||||
platform=platforms[0],
|
||||
role=roles[0],
|
||||
tenant=tenants[0],
|
||||
status=VirtualMachineStatusChoices.STATUS_ACTIVE,
|
||||
vcpus=1,
|
||||
memory=1,
|
||||
disk=1,
|
||||
description='foobar1',
|
||||
local_context_data={"foo": 123}
|
||||
),
|
||||
VirtualMachine(
|
||||
name='Virtual Machine 2',
|
||||
site=sites[1],
|
||||
cluster=clusters[1],
|
||||
device=devices[1],
|
||||
platform=platforms[1],
|
||||
role=roles[1],
|
||||
tenant=tenants[1],
|
||||
status=VirtualMachineStatusChoices.STATUS_STAGED,
|
||||
vcpus=2,
|
||||
memory=2,
|
||||
disk=2,
|
||||
description='foobar2'
|
||||
),
|
||||
VirtualMachine(
|
||||
name='Virtual Machine 3',
|
||||
site=sites[2],
|
||||
cluster=clusters[2],
|
||||
device=devices[2],
|
||||
platform=platforms[2],
|
||||
role=roles[2],
|
||||
tenant=tenants[2],
|
||||
status=VirtualMachineStatusChoices.STATUS_OFFLINE,
|
||||
vcpus=3,
|
||||
memory=3,
|
||||
disk=3,
|
||||
description='foobar3'
|
||||
),
|
||||
)
|
||||
VirtualMachine.objects.bulk_create(vms)
|
||||
|
||||
@ -300,6 +380,10 @@ class VirtualMachineTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
VirtualMachine.objects.filter(pk=vms[0].pk).update(primary_ip4=ipaddresses[0], primary_ip6=ipaddresses[3])
|
||||
VirtualMachine.objects.filter(pk=vms[1].pk).update(primary_ip4=ipaddresses[1], primary_ip6=ipaddresses[4])
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Virtual Machine 1', 'Virtual Machine 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -307,6 +391,10 @@ class VirtualMachineTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
params = {'name': ['VIRTUAL MACHINE 1', 'VIRTUAL MACHINE 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_vcpus(self):
|
||||
params = {'vcpus': [1, 2]}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -467,12 +555,40 @@ class VMInterfaceTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
VirtualMachine.objects.bulk_create(vms)
|
||||
|
||||
interfaces = (
|
||||
VMInterface(virtual_machine=vms[0], name='Interface 1', enabled=True, mtu=100, mac_address='00-00-00-00-00-01', vrf=vrfs[0], description='foobar1'),
|
||||
VMInterface(virtual_machine=vms[1], name='Interface 2', enabled=True, mtu=200, mac_address='00-00-00-00-00-02', vrf=vrfs[1], description='foobar2'),
|
||||
VMInterface(virtual_machine=vms[2], name='Interface 3', enabled=False, mtu=300, mac_address='00-00-00-00-00-03', vrf=vrfs[2]),
|
||||
VMInterface(
|
||||
virtual_machine=vms[0],
|
||||
name='Interface 1',
|
||||
enabled=True,
|
||||
mtu=100,
|
||||
mac_address='00-00-00-00-00-01',
|
||||
vrf=vrfs[0],
|
||||
description='foobar1'
|
||||
),
|
||||
VMInterface(
|
||||
virtual_machine=vms[1],
|
||||
name='Interface 2',
|
||||
enabled=True,
|
||||
mtu=200,
|
||||
mac_address='00-00-00-00-00-02',
|
||||
vrf=vrfs[1],
|
||||
description='foobar2'
|
||||
),
|
||||
VMInterface(
|
||||
virtual_machine=vms[2],
|
||||
name='Interface 3',
|
||||
enabled=False,
|
||||
mtu=300,
|
||||
mac_address='00-00-00-00-00-03',
|
||||
vrf=vrfs[2],
|
||||
description='foobar3'
|
||||
),
|
||||
)
|
||||
VMInterface.objects.bulk_create(interfaces)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Interface 1', 'Interface 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
@ -36,6 +36,10 @@ class WirelessLANGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
for group in child_groups:
|
||||
group.save()
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Wireless LAN Group 1', 'Wireless LAN Group 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -103,7 +107,8 @@ class WirelessLANTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
tenant=tenants[0],
|
||||
auth_type=WirelessAuthTypeChoices.TYPE_OPEN,
|
||||
auth_cipher=WirelessAuthCipherChoices.CIPHER_AUTO,
|
||||
auth_psk='PSK1'
|
||||
auth_psk='PSK1',
|
||||
description='foobar1'
|
||||
),
|
||||
WirelessLAN(
|
||||
ssid='WLAN2',
|
||||
@ -113,7 +118,8 @@ class WirelessLANTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
tenant=tenants[1],
|
||||
auth_type=WirelessAuthTypeChoices.TYPE_WEP,
|
||||
auth_cipher=WirelessAuthCipherChoices.CIPHER_TKIP,
|
||||
auth_psk='PSK2'
|
||||
auth_psk='PSK2',
|
||||
description='foobar2'
|
||||
),
|
||||
WirelessLAN(
|
||||
ssid='WLAN3',
|
||||
@ -123,11 +129,16 @@ class WirelessLANTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
tenant=tenants[2],
|
||||
auth_type=WirelessAuthTypeChoices.TYPE_WPA_PERSONAL,
|
||||
auth_cipher=WirelessAuthCipherChoices.CIPHER_AES,
|
||||
auth_psk='PSK3'
|
||||
auth_psk='PSK3',
|
||||
description='foobar3'
|
||||
),
|
||||
)
|
||||
WirelessLAN.objects.bulk_create(wireless_lans)
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_ssid(self):
|
||||
params = {'ssid': ['WLAN1', 'WLAN2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
@ -160,6 +171,10 @@ class WirelessLANTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
params = {'auth_psk': ['PSK1', 'PSK2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_tenant(self):
|
||||
tenants = Tenant.objects.all()[:2]
|
||||
params = {'tenant_id': [tenants[0].pk, tenants[1].pk]}
|
||||
@ -240,6 +255,10 @@ class WirelessLinkTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
ssid='LINK4'
|
||||
).save()
|
||||
|
||||
def test_q(self):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_ssid(self):
|
||||
params = {'ssid': ['LINK1', 'LINK2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
Reference in New Issue
Block a user