mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
API and viewset tests (incomplete)
This commit is contained in:
parent
0985ef43d3
commit
eece55b212
@ -118,7 +118,7 @@ class VLANTranslationRuleSerializer(NetBoxModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = VLANTranslationRule
|
||||
fields = ['policy', 'local_vid', 'remote_vid']
|
||||
fields = ['id', 'policy', 'local_vid', 'remote_vid']
|
||||
|
||||
|
||||
class VLANTranslationPolicySerializer(NetBoxModelSerializer):
|
||||
|
@ -282,7 +282,7 @@ class VLANGroupType(OrganizationalObjectType):
|
||||
filters=VLANTranslationPolicyFilter
|
||||
)
|
||||
class VLANTranslationPolicyType(NetBoxObjectType):
|
||||
pass
|
||||
rules: List[Annotated["VLANTranslationRuleType", strawberry.lazy('ipam.graphql.types')]]
|
||||
|
||||
|
||||
@strawberry_django.type(
|
||||
@ -291,7 +291,7 @@ class VLANTranslationPolicyType(NetBoxObjectType):
|
||||
filters=VLANTranslationRuleFilter
|
||||
)
|
||||
class VLANTranslationRuleType(NetBoxObjectType):
|
||||
pass
|
||||
policy: Annotated["VLANTranslationPolicyType", strawberry.lazy('ipam.graphql.types')]
|
||||
|
||||
|
||||
@strawberry_django.type(
|
||||
|
@ -1020,6 +1020,114 @@ class VLANTest(APIViewTestCases.APIViewTestCase):
|
||||
self.assertTrue(content['detail'].startswith('Unable to delete object.'))
|
||||
|
||||
|
||||
class VLANTranslationPolicyTest(APIViewTestCases.APIViewTestCase):
|
||||
model = VLANTranslationPolicy
|
||||
brief_fields = ['description', 'display', 'id', 'name', 'url',]
|
||||
bulk_update_data = {
|
||||
'description': 'New description',
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
|
||||
vlan_translation_policies = (
|
||||
VLANTranslationPolicy(
|
||||
name='Policy 1',
|
||||
description='foobar1',
|
||||
),
|
||||
VLANTranslationPolicy(
|
||||
name='Policy 2',
|
||||
description='foobar2',
|
||||
),
|
||||
VLANTranslationPolicy(
|
||||
name='Policy 3',
|
||||
description='foobar3',
|
||||
),
|
||||
)
|
||||
VLANTranslationPolicy.objects.bulk_create(vlan_translation_policies)
|
||||
|
||||
cls.create_data = [
|
||||
{
|
||||
'name': 'Policy 4',
|
||||
'description': 'foobar4',
|
||||
},
|
||||
{
|
||||
'name': 'Policy 5',
|
||||
'description': 'foobar5',
|
||||
},
|
||||
{
|
||||
'name': 'Policy 6',
|
||||
'description': 'foobar6',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
class VLANTranslationRuleTest(APIViewTestCases.APIViewTestCase):
|
||||
model = VLANTranslationRule
|
||||
brief_fields = ['id', 'local_vid', 'policy', 'remote_vid',]
|
||||
bulk_update_data = {
|
||||
'policy': '109',
|
||||
'remote_vid': '209',
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
|
||||
vlan_translation_policies = (
|
||||
VLANTranslationPolicy(
|
||||
name='Policy 1',
|
||||
description='foobar1',
|
||||
),
|
||||
VLANTranslationPolicy(
|
||||
name='Policy 2',
|
||||
description='foobar2',
|
||||
),
|
||||
)
|
||||
VLANTranslationPolicy.objects.bulk_create(vlan_translation_policies)
|
||||
|
||||
vlan_translation_rules = (
|
||||
VLANTranslationRule(
|
||||
policy=vlan_translation_policies[0],
|
||||
local_vid=100,
|
||||
remote_vid=200,
|
||||
),
|
||||
VLANTranslationRule(
|
||||
policy=vlan_translation_policies[0],
|
||||
local_vid=101,
|
||||
remote_vid=201,
|
||||
),
|
||||
VLANTranslationRule(
|
||||
policy=vlan_translation_policies[1],
|
||||
local_vid=102,
|
||||
remote_vid=202,
|
||||
),
|
||||
)
|
||||
VLANTranslationRule.objects.bulk_create(vlan_translation_rules)
|
||||
print(VLANTranslationRule.objects.all().values('id', 'policy'))
|
||||
|
||||
cls.create_data = [
|
||||
{
|
||||
'policy': vlan_translation_policies[0].pk,
|
||||
'local_vid': 300,
|
||||
'remote_vid': 400,
|
||||
},
|
||||
{
|
||||
'policy': vlan_translation_policies[0].pk,
|
||||
'local_vid': 301,
|
||||
'remote_vid': 401,
|
||||
},
|
||||
{
|
||||
'policy': vlan_translation_policies[1].pk,
|
||||
'local_vid': 302,
|
||||
'remote_vid': 402,
|
||||
},
|
||||
]
|
||||
|
||||
cls.bulk_update_data = {
|
||||
'policy': vlan_translation_policies[1].pk,
|
||||
}
|
||||
|
||||
|
||||
class ServiceTemplateTest(APIViewTestCases.APIViewTestCase):
|
||||
model = ServiceTemplate
|
||||
brief_fields = ['description', 'display', 'id', 'name', 'ports', 'protocol', 'url']
|
||||
|
@ -912,6 +912,89 @@ class VLANTranslationPolicyTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
||||
}
|
||||
|
||||
|
||||
class VLANTranslationRuleTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
||||
model = VLANTranslationRule
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
|
||||
vlan_translation_policies = (
|
||||
VLANTranslationPolicy(
|
||||
name='Policy 1',
|
||||
description='foobar1',
|
||||
),
|
||||
VLANTranslationPolicy(
|
||||
name='Policy 2',
|
||||
description='foobar2',
|
||||
),
|
||||
VLANTranslationPolicy(
|
||||
name='Policy 3',
|
||||
description='foobar3',
|
||||
),
|
||||
)
|
||||
VLANTranslationPolicy.objects.bulk_create(vlan_translation_policies)
|
||||
|
||||
vlan_translation_rules = (
|
||||
VLANTranslationRule(
|
||||
policy=vlan_translation_policies[0],
|
||||
local_vid=100,
|
||||
remote_vid=200,
|
||||
),
|
||||
VLANTranslationRule(
|
||||
policy=vlan_translation_policies[0],
|
||||
local_vid=101,
|
||||
remote_vid=201,
|
||||
),
|
||||
VLANTranslationRule(
|
||||
policy=vlan_translation_policies[1],
|
||||
local_vid=102,
|
||||
remote_vid=202,
|
||||
),
|
||||
)
|
||||
VLANTranslationRule.objects.bulk_create(vlan_translation_rules)
|
||||
|
||||
tags = create_tags('Alpha', 'Bravo', 'Charlie')
|
||||
|
||||
cls.form_data = {
|
||||
'policy': vlan_translation_policies[0].pk,
|
||||
'local_vid': 300,
|
||||
'remote_vid': 400,
|
||||
}
|
||||
|
||||
cls.csv_data = (
|
||||
"policy_id,local_vid,remote_vid",
|
||||
f"{vlan_translation_policies[0].pk},103,203",
|
||||
f"{vlan_translation_policies[0].pk},104,204",
|
||||
f"{vlan_translation_policies[1].pk},105,205",
|
||||
)
|
||||
|
||||
cls.csv_update_data = (
|
||||
"id,policy_id,local_vid,remote_vid",
|
||||
f"{vlan_translation_rules[0].pk},{vlan_translation_policies[1].pk},105,205",
|
||||
f"{vlan_translation_rules[1].pk},{vlan_translation_policies[1].pk},106,206",
|
||||
f"{vlan_translation_rules[2].pk},{vlan_translation_policies[0].pk},107,207",
|
||||
)
|
||||
|
||||
cls.bulk_edit_data = {
|
||||
'tags': [t.pk for t in tags],
|
||||
}
|
||||
|
||||
# def test_bulk_edit_objects_with_permission(self):
|
||||
# pass
|
||||
#
|
||||
# def test_bulk_edit_objects_with_constrained_permission(self):
|
||||
# pass
|
||||
#
|
||||
# def test_bulk_import_objects_with_permission(self):
|
||||
# pass
|
||||
#
|
||||
# def test_bulk_import_objects_with_constrained_permission(self):
|
||||
# pass
|
||||
#
|
||||
# def test_bulk_update_objects_with_permission(self):
|
||||
# pass
|
||||
|
||||
|
||||
class ServiceTemplateTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
||||
model = ServiceTemplate
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user