-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test cases for sanitize_record()
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |