mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Address review comments
This commit is contained in:
@@ -229,9 +229,9 @@ class Ns1Provider(BaseProvider):
|
|||||||
|
|
||||||
# Necessary for handling unsupported continents in _CONTINENT_TO_REGIONS
|
# Necessary for handling unsupported continents in _CONTINENT_TO_REGIONS
|
||||||
_CONTINENT_TO_LIST_OF_COUNTRIES = {
|
_CONTINENT_TO_LIST_OF_COUNTRIES = {
|
||||||
'OC': ['FJ', 'NC', 'PG', 'SB', 'VU', 'AU', 'NF', 'NZ', 'FM', 'GU',
|
'OC': {'FJ', 'NC', 'PG', 'SB', 'VU', 'AU', 'NF', 'NZ', 'FM', 'GU',
|
||||||
'KI', 'MH', 'MP', 'NR', 'PW', 'AS', 'CK', 'NU', 'PF', 'PN',
|
'KI', 'MH', 'MP', 'NR', 'PW', 'AS', 'CK', 'NU', 'PF', 'PN',
|
||||||
'TK', 'TO', 'TV', 'WF', 'WS'],
|
'TK', 'TO', 'TV', 'WF', 'WS'},
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, id, api_key, retry_count=4, monitor_regions=None, *args,
|
def __init__(self, id, api_key, retry_count=4, monitor_regions=None, *args,
|
||||||
@@ -367,7 +367,7 @@ class Ns1Provider(BaseProvider):
|
|||||||
# Oceania countries list are found, set the region to OC and remove
|
# Oceania countries list are found, set the region to OC and remove
|
||||||
# individual oceania country entries
|
# individual oceania country entries
|
||||||
|
|
||||||
oc_countries = []
|
oc_countries = set()
|
||||||
for country in meta.get('country', []):
|
for country in meta.get('country', []):
|
||||||
# country_alpha2_to_continent_code fails for Pitcairn ('PN')
|
# country_alpha2_to_continent_code fails for Pitcairn ('PN')
|
||||||
if country == 'PN':
|
if country == 'PN':
|
||||||
@@ -376,16 +376,19 @@ class Ns1Provider(BaseProvider):
|
|||||||
con = country_alpha2_to_continent_code(country)
|
con = country_alpha2_to_continent_code(country)
|
||||||
|
|
||||||
if con == 'OC':
|
if con == 'OC':
|
||||||
oc_countries.append(country)
|
oc_countries.add(country)
|
||||||
|
else:
|
||||||
|
# Adding only non-OC countries here to geos
|
||||||
geos.add('{}-{}'.format(con, country))
|
geos.add('{}-{}'.format(con, country))
|
||||||
|
|
||||||
if len(oc_countries):
|
if oc_countries:
|
||||||
all_oc_countries = self._CONTINENT_TO_LIST_OF_COUNTRIES['OC']
|
if oc_countries == self._CONTINENT_TO_LIST_OF_COUNTRIES['OC']:
|
||||||
if sorted(oc_countries) == sorted(all_oc_countries):
|
# All OC countries found, so add 'OC' to geos
|
||||||
# Remove oceania countries from the map, add 'OC' region
|
|
||||||
for c in oc_countries:
|
|
||||||
geos.remove('{}-{}'.format('OC', c))
|
|
||||||
geos.add('OC')
|
geos.add('OC')
|
||||||
|
else:
|
||||||
|
# Partial OC countries found, just add them as-is to geos
|
||||||
|
for c in oc_countries:
|
||||||
|
geos.add('{}-{}'.format('OC', c))
|
||||||
|
|
||||||
# States are easy too, just assume NA-US (CA providences aren't
|
# States are easy too, just assume NA-US (CA providences aren't
|
||||||
# supported by octoDNS currently)
|
# supported by octoDNS currently)
|
||||||
|
|||||||
@@ -521,12 +521,6 @@ class TestNs1Provider(TestCase):
|
|||||||
class TestNs1ProviderDynamic(TestCase):
|
class TestNs1ProviderDynamic(TestCase):
|
||||||
zone = Zone('unit.tests.', [])
|
zone = Zone('unit.tests.', [])
|
||||||
|
|
||||||
_CONTINENT_TO_LIST_OF_COUNTRIES = {
|
|
||||||
'OC': ['FJ', 'NC', 'PG', 'SB', 'VU', 'AU', 'NF', 'NZ', 'FM', 'GU',
|
|
||||||
'KI', 'MH', 'MP', 'NR', 'PW', 'AS', 'CK', 'NU', 'PF', 'PN',
|
|
||||||
'TK', 'TO', 'TV', 'WF', 'WS'],
|
|
||||||
}
|
|
||||||
|
|
||||||
record = Record.new(zone, '', {
|
record = Record.new(zone, '', {
|
||||||
'dynamic': {
|
'dynamic': {
|
||||||
'pools': {
|
'pools': {
|
||||||
@@ -965,8 +959,8 @@ class TestNs1ProviderDynamic(TestCase):
|
|||||||
saved_geos = rule0['geos']
|
saved_geos = rule0['geos']
|
||||||
rule0['geos'] = ['OC']
|
rule0['geos'] = ['OC']
|
||||||
ret, _ = provider._params_for_A(self.record)
|
ret, _ = provider._params_for_A(self.record)
|
||||||
self.assertEquals(sorted(ret['regions']['lhr']['meta']['country']),
|
self.assertEquals(set(ret['regions']['lhr']['meta']['country']),
|
||||||
sorted(self._CONTINENT_TO_LIST_OF_COUNTRIES['OC']))
|
Ns1Provider._CONTINENT_TO_LIST_OF_COUNTRIES['OC'])
|
||||||
rule0['geos'] = saved_geos
|
rule0['geos'] = saved_geos
|
||||||
|
|
||||||
@patch('octodns.provider.ns1.Ns1Provider._monitor_sync')
|
@patch('octodns.provider.ns1.Ns1Provider._monitor_sync')
|
||||||
@@ -1137,17 +1131,18 @@ class TestNs1ProviderDynamic(TestCase):
|
|||||||
|
|
||||||
# Oceania test cases
|
# Oceania test cases
|
||||||
# 1. Full list of countries should return 'OC' in geos
|
# 1. Full list of countries should return 'OC' in geos
|
||||||
oc_country_list = self._CONTINENT_TO_LIST_OF_COUNTRIES['OC']
|
oc_countries = Ns1Provider._CONTINENT_TO_LIST_OF_COUNTRIES['OC']
|
||||||
ns1_record['regions']['lhr']['meta']['country'] = oc_country_list
|
ns1_record['regions']['lhr']['meta']['country'] = list(oc_countries)
|
||||||
data3 = provider._data_for_A('A', ns1_record)
|
data3 = provider._data_for_A('A', ns1_record)
|
||||||
assert('OC' in data3['dynamic']['rules'][0]['geos'])
|
self.assertTrue('OC' in data3['dynamic']['rules'][0]['geos'])
|
||||||
|
|
||||||
# 2. Partial list of countries should return just those
|
# 2. Partial list of countries should return just those
|
||||||
partial_oc_cntry_list = oc_country_list[:5]
|
partial_oc_cntry_list = list(oc_countries)[:5]
|
||||||
ns1_record['regions']['lhr']['meta']['country'] = partial_oc_cntry_list
|
ns1_record['regions']['lhr']['meta']['country'] = partial_oc_cntry_list
|
||||||
data4 = provider._data_for_A('A', ns1_record)
|
data4 = provider._data_for_A('A', ns1_record)
|
||||||
for c in partial_oc_cntry_list:
|
for c in partial_oc_cntry_list:
|
||||||
assert('OC-{}'.format(c) in data4['dynamic']['rules'][0]['geos'])
|
self.assertTrue(
|
||||||
|
'OC-{}'.format(c) in data4['dynamic']['rules'][0]['geos'])
|
||||||
|
|
||||||
@patch('octodns.provider.ns1.Ns1Provider._monitors_for')
|
@patch('octodns.provider.ns1.Ns1Provider._monitors_for')
|
||||||
def test_extra_changes(self, monitors_for_mock):
|
def test_extra_changes(self, monitors_for_mock):
|
||||||
|
|||||||
Reference in New Issue
Block a user