Skip to content

Commit

Permalink
Improve interface, fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Apr 24, 2021
1 parent 341504e commit 3ce02ed
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion plugins/module_utils/module/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def normalize_dns_name(name):
return name


def get_prefix(normalized_record, normalized_zone, prefix=None):
def get_prefix(normalized_zone, normalized_record=None, prefix=None):
# If normalized_record is not specified, use prefix
if normalized_record is None:
if prefix is not None:
Expand Down
4 changes: 2 additions & 2 deletions plugins/module_utils/module/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def run_module(module, create_api):
# Get zone information
if module.params.get('zone') is not None:
zone_in = normalize_dns_name(module.params.get('zone'))
record_in, prefix = get_prefix(normalized_record=record_in, normalized_zone=zone_in, prefix=prefix_in)
record_in, prefix = get_prefix(normalized_zone=zone_in, normalized_record=record_in, prefix=prefix_in)
zone = api.get_zone_with_records_by_name(zone_in)
if zone is None:
module.fail_json(msg='Zone not found')
Expand All @@ -74,7 +74,7 @@ def run_module(module, create_api):
if zone is None:
module.fail_json(msg='Zone not found')
zone_in = normalize_dns_name(zone.zone.name)
record_in, prefix = get_prefix(normalized_record=record_in, normalized_zone=zone_in, prefix=prefix_in)
record_in, prefix = get_prefix(normalized_zone=zone_in, normalized_record=record_in, prefix=prefix_in)

# Find matching records
type_in = module.params.get('type')
Expand Down
4 changes: 2 additions & 2 deletions plugins/module_utils/module/record_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def run_module(module, create_api):
# Extract prefix
record_in = normalize_dns_name(module.params.get('record'))
prefix_in = module.params.get('prefix')
record_in, prefix = get_prefix(normalized_record=record_in, normalized_zone=zone_in, prefix=prefix_in)
record_in, prefix = get_prefix(normalized_zone=zone_in, normalized_record=record_in, prefix=prefix_in)

# Find matching records
type_in = module.params.get('type')
Expand All @@ -99,7 +99,7 @@ def run_module(module, create_api):
check_prefix = True
record_in = normalize_dns_name(module.params.get('record'))
prefix_in = module.params.get('prefix')
record_in, prefix = get_prefix(normalized_record=record_in, normalized_zone=zone_in, prefix=prefix_in)
record_in, prefix = get_prefix(normalized_zone=zone_in, normalized_record=record_in, prefix=prefix_in)
else:
check_prefix = False
prefix = None
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/plugins/module_utils/module/test__utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ def test_normalize_dns_name():


def test_get_prefix():
assert get_prefix(normalized_record='example.com', normalized_zone='example.com') == ('example.com', None)
assert get_prefix(normalized_record='www.example.com', normalized_zone='example.com') == ('www.example.com', 'www')
assert get_prefix(normalized_zone='example.com', normalized_record='example.com') == ('example.com', None)
assert get_prefix(normalized_zone='example.com', normalized_record='www.example.com') == ('www.example.com', 'www')
assert get_prefix(normalized_zone='example.com') == ('example.com', None)
assert get_prefix(normalized_zone='example.com', prefix='') == ('example.com', None)
assert get_prefix(normalized_zone='example.com', prefix='.') == ('example.com', None)
assert get_prefix(normalized_zone='example.com', prefix='www') == ('www.example.com', 'www')
assert get_prefix(normalized_zone='example.com', prefix='www.') == ('www.example.com', 'www')
assert get_prefix(normalized_zone='example.com', prefix='wWw.') == ('www.example.com', 'www')
with pytest.raises(DNSAPIError):
get_prefix(normalized_record='example.org', normalized_zone='example.com')
get_prefix(normalized_zone='example.com', normalized_record='example.org')
with pytest.raises(DNSAPIError):
get_prefix(normalized_record='wwwexample.com', normalized_zone='example.com')
get_prefix(normalized_zone='example.com', normalized_record='wwwexample.com')

0 comments on commit 3ce02ed

Please sign in to comment.