Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check the type of a record when testing for uniqueness #76

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion netbox_dns/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,13 +969,14 @@ def check_unique(self):
records = Record.objects.filter(
zone=self.zone,
name=self.name,
type=self.type,
value=self.value,
status__in=Record.ACTIVE_STATUS_LIST,
)
if len(records):
raise ValidationError(
{
"value": f"There is already an active record for name {self.name} in zone {self.zone} with value {self.value}."
"value": f"There is already an active {self.type} record for name {self.name} in zone {self.zone} with value {self.value}."
}
) from None

Expand Down
23 changes: 23 additions & 0 deletions netbox_dns/tests/record/test_uniqueness.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,29 @@ def test_create_duplicate_records_ok(self):
)
f_record.save()

@override_settings(
PLUGINS_CONFIG={
"netbox_dns": {
"enforce_unique_records": True,
}
}
)
def test_create_different_type_records_ok(self):
f_zone = self.zones[0]

records = [
{"name": "test1", "type": RecordTypeChoices.A, "value": "10.0.1.42"},
{"name": "test1", "type": RecordTypeChoices.TXT, "value": "10.0.1.42"},
]

for record in records:
f_record = Record(
zone=f_zone,
**record,
**self.record_data,
)
f_record.save()

@override_settings(
PLUGINS_CONFIG={
"netbox_dns": {
Expand Down