Skip to content

Commit

Permalink
Add test cases for sanitize_record()
Browse files Browse the repository at this point in the history
  • Loading branch information
s-hamann committed Jun 21, 2024
1 parent dd34020 commit 23b74d9
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import pytest

import desec


@pytest.mark.parametrize(
"rtype, subname, records",
[
("A", "", ["192.0.2.1"]),
("A", "", ["192.0.2.1", "192.0.2.2"]),
("AAAA", "", ["2001:db8:10::1"]),
("TXT", "test", ['"test"']),
("CNAME", "www", ["test-suite.test."]),
("MX", "", ["test-suite.test."]),
("NS", "", ["ns1.test-suite.test.", "ns2.test-suite.test."]),
],
)
def test_sanitize_records_valid(rtype, subname, records):
"""Test sanitize_records() with valid input.
Assert that output is the unchanged input.
"""
rrset = desec.sanitize_records(rtype, subname, records)

assert rrset == records


@pytest.mark.parametrize(
"rtype, subname, records, expected",
[
("TXT", "test", ["test"], ['"test"']),
("CNAME", "www", ["test-suite.test"], ["test-suite.test."]),
("MX", "", ["test-suite.test"], ["test-suite.test."]),
(
"NS",
"",
["ns1.test-suite.test", "ns2.test-suite.test"],
["ns1.test-suite.test.", "ns2.test-suite.test."],
),
],
)
def test_sanitize_records_fixable(rtype, subname, records, expected):
"""Test sanitize_records() with fixable errors.
Assert that the output is fixed.
"""
rrset = desec.sanitize_records(rtype, subname, records)

assert rrset == expected


@pytest.mark.parametrize(
"rtype, subname, records",
[
("CNAME", "www", ["test-suite.test.", "prod-suite.test."]),
("CNAME", "", ["test-suite.test."]),
("NS", "*", ["ns1.test-suite.test", "ns2.test-suite.test"]),
("NS", "*.test", ["ns1.test-suite.test", "ns2.test-suite.test"]),
],
)
def test_sanitize_records_unfixable(rtype, subname, records):
"""Test sanitize_records() with unfixable errors.
Assert that an appropriate exception is raised.
"""
with pytest.raises(desec.ParameterCheckError):
desec.sanitize_records(rtype, subname, records)

0 comments on commit 23b74d9

Please sign in to comment.