Skip to content

Commit

Permalink
Replaced hardcoded status names with choices for Zone and Record tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peteeckel committed Oct 16, 2024
1 parent f5c2780 commit 6b398a7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
20 changes: 10 additions & 10 deletions netbox_dns/tests/record/test_auto_ptr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


from netbox_dns.models import NameServer, Record, Zone
from netbox_dns.choices import RecordTypeChoices
from netbox_dns.choices import RecordTypeChoices, RecordStatusChoices


def reverse_name(address, reverse_zone):
Expand Down Expand Up @@ -831,7 +831,7 @@ def test_ipv4_create_inactive_record_no_ptr(self):
name=name,
type=RecordTypeChoices.A,
value=address,
status="inactive",
status=RecordStatusChoices.STATUS_INACTIVE,
)

with self.assertRaises(Record.DoesNotExist):
Expand Down Expand Up @@ -861,7 +861,7 @@ def test_ipv4_deactivate_record_delete_ptr(self):

self.assertEqual(r_record.value, f"{name}.{f_zone.name}.")

f_record.status = "inactive"
f_record.status = RecordStatusChoices.STATUS_INACTIVE
f_record.save()

with self.assertRaises(Record.DoesNotExist):
Expand All @@ -883,7 +883,7 @@ def test_ipv4_activate_record_create_ptr(self):
name=name,
type=RecordTypeChoices.A,
value=address,
status="inactive",
status=RecordStatusChoices.STATUS_INACTIVE,
)

with self.assertRaises(Record.DoesNotExist):
Expand All @@ -893,7 +893,7 @@ def test_ipv4_activate_record_create_ptr(self):
name=reverse_name(address, r_zone),
)

f_record.status = "active"
f_record.status = RecordStatusChoices.STATUS_ACTIVE
f_record.save()

r_record = Record.objects.get(
Expand All @@ -914,7 +914,7 @@ def test_ipv6_create_inactive_record_no_ptr(self):
name=name,
type=RecordTypeChoices.AAAA,
value=address,
status="inactive",
status=RecordStatusChoices.STATUS_INACTIVE,
)

with self.assertRaises(Record.DoesNotExist):
Expand All @@ -924,7 +924,7 @@ def test_ipv6_create_inactive_record_no_ptr(self):
name=reverse_name(address, r_zone),
)

f_record.status = "active"
f_record.status = RecordStatusChoices.STATUS_ACTIVE
f_record.save()

r_record = Record.objects.get(
Expand Down Expand Up @@ -953,7 +953,7 @@ def test_ipv6_deactivate_record_delete_ptr(self):

self.assertEqual(r_record.value, f"{name}.{f_zone.name}.")

f_record.status = "inactive"
f_record.status = RecordStatusChoices.STATUS_INACTIVE
f_record.save()

with self.assertRaises(Record.DoesNotExist):
Expand All @@ -975,7 +975,7 @@ def test_ipv6_activate_record_create_ptr(self):
name=name,
type=RecordTypeChoices.AAAA,
value=address,
status="inactive",
status=RecordStatusChoices.STATUS_INACTIVE,
)

with self.assertRaises(Record.DoesNotExist):
Expand All @@ -985,7 +985,7 @@ def test_ipv6_activate_record_create_ptr(self):
name=reverse_name(address, r_zone),
)

f_record.status = "active"
f_record.status = RecordStatusChoices.STATUS_ACTIVE
f_record.save()

r_record = Record.objects.get(
Expand Down
14 changes: 7 additions & 7 deletions netbox_dns/tests/record/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.core.exceptions import ValidationError

from netbox_dns.models import Zone, Record, NameServer
from netbox_dns.choices import RecordTypeChoices
from netbox_dns.choices import RecordTypeChoices, RecordStatusChoices


def split_text_value(value):
Expand Down Expand Up @@ -278,7 +278,7 @@ def test_inactive_name_and_active_cname(self):
name=name1,
type=RecordTypeChoices.AAAA,
value=address,
status="inactive",
status=RecordStatusChoices.STATUS_INACTIVE,
)
Record.objects.create(
zone=zone,
Expand All @@ -299,7 +299,7 @@ def test_inactive_cname_and_active_name(self):
name=name1,
type=RecordTypeChoices.CNAME,
value=name2,
status="inactive",
status=RecordStatusChoices.STATUS_INACTIVE,
)
Record.objects.create(
zone=zone,
Expand All @@ -320,7 +320,7 @@ def test_double_singletons_inactive_active(self):
name=name1,
type=RecordTypeChoices.DNAME,
value=name2,
status="inactive",
status=RecordStatusChoices.STATUS_INACTIVE,
)
Record.objects.create(
zone=zone,
Expand All @@ -347,7 +347,7 @@ def test_active_name_and_inactive_cname(self):
name=name1,
type=RecordTypeChoices.CNAME,
value=name2,
status="inactive",
status=RecordStatusChoices.STATUS_INACTIVE,
)

def test_active_cname_and_inactive_name(self):
Expand All @@ -368,7 +368,7 @@ def test_active_cname_and_inactive_name(self):
name=name1,
type=RecordTypeChoices.AAAA,
value=address,
status="inactive",
status=RecordStatusChoices.STATUS_INACTIVE,
)

def test_double_singletons_active_inactive(self):
Expand All @@ -389,7 +389,7 @@ def test_double_singletons_active_inactive(self):
name=name1,
type=RecordTypeChoices.DNAME,
value=name3,
status="inactive",
status=RecordStatusChoices.STATUS_INACTIVE,
)

def test_lowercase_type(self):
Expand Down
2 changes: 1 addition & 1 deletion netbox_dns/tests/record/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def setUpTestData(cls):
"value": "fe80::dead:beef",
"ttl": 86230,
"tags": [t.pk for t in tags],
"status": "active",
"status": RecordStatusChoices.STATUS_ACTIVE,
}

cls.bulk_edit_data = {
Expand Down
7 changes: 4 additions & 3 deletions netbox_dns/tests/zone/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from netbox_dns.tests.custom import APITestCase, NetBoxDNSGraphQLMixin
from netbox_dns.models import View, Zone, NameServer, Registrar, RegistrationContact
from netbox_dns.choices import ZoneStatusChoices


class ZoneAPITestCase(
Expand Down Expand Up @@ -106,7 +107,7 @@ def setUpTestData(cls):
cls.create_data = [
{
"name": "zone6.example.com",
"status": "reserved",
"status": ZoneStatusChoices.STATUS_RESERVED,
"nameservers": [nameserver.pk for nameserver in nameservers[0:2]],
**zone_data,
"soa_mname": nameservers[0].pk,
Expand All @@ -118,14 +119,14 @@ def setUpTestData(cls):
},
{
"name": "zone7.example.com",
"status": "reserved",
"status": ZoneStatusChoices.STATUS_RESERVED,
"nameservers": [nameserver.pk for nameserver in nameservers[1:3]],
**zone_data,
"soa_mname": nameservers[0].pk,
},
{
"name": "zone8.example.com",
"status": "reserved",
"status": ZoneStatusChoices.STATUS_RESERVED,
"nameservers": [nameserver.pk for nameserver in nameservers[0:3]],
**zone_data,
"soa_mname": nameservers[0].pk,
Expand Down
10 changes: 5 additions & 5 deletions netbox_dns/tests/zone/test_auto_ns.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.db.models import ProtectedError

from netbox_dns.models import NameServer, Record, Zone
from netbox_dns.choices import RecordTypeChoices
from netbox_dns.choices import RecordTypeChoices, ZoneStatusChoices, RecordStatusChoices


class ZoneAutoNSTestCase(TestCase):
Expand Down Expand Up @@ -75,7 +75,7 @@ def test_inactive_zone_with_ns_warning(self):
ns_zone = Zone.objects.create(
name="example.com",
**self.zone_data,
status="reserved",
status=ZoneStatusChoices.STATUS_RESERVED,
)
ns_zone.nameservers.add(nameserver)

Expand All @@ -90,7 +90,7 @@ def test_inactive_zone_with_ns_and_address_no_warning(self):
ns_zone = Zone.objects.create(
name="example.com",
**self.zone_data,
status="reserved",
status=ZoneStatusChoices.STATUS_RESERVED,
)
ns_zone.nameservers.add(nameserver)

Expand All @@ -111,7 +111,7 @@ def test_inactive_zone_with_ns_and_inactive_address_warning(self):
ns_zone = Zone.objects.create(
name="example.com",
**self.zone_data,
status="reserved",
status=ZoneStatusChoices.STATUS_RESERVED,
)
ns_zone.nameservers.add(nameserver)

Expand All @@ -121,7 +121,7 @@ def test_inactive_zone_with_ns_and_inactive_address_warning(self):
type="A",
value="10.0.0.23",
ttl=86400,
status="inactive",
status=RecordStatusChoices.STATUS_INACTIVE,
)
ns_record.save()

Expand Down

0 comments on commit 6b398a7

Please sign in to comment.