Tests for new-style ns1 data_for_dynamic_A fallback only pools

This commit is contained in:
Ross McFarland
2021-04-26 17:10:22 -07:00
parent 078576520d
commit fbd8389903
2 changed files with 110 additions and 1 deletions
+1 -1
View File
@@ -542,7 +542,7 @@ class Ns1Provider(BaseProvider):
rules[rule_order] = rule
# The group notes field in the UI is a `note` on the region here,
# that's where we can find our pool's fallback.
# that's where we can find our pool's fallback in < v0.9.11 anyway
if 'fallback' in notes:
# set the fallback pool name
pools[pool_name]['fallback'] = notes['fallback']
+109
View File
@@ -1478,6 +1478,115 @@ class TestNs1ProviderDynamic(TestCase):
self.assertTrue(
'OC-{}'.format(c) in data4['dynamic']['rules'][0]['geos'])
# Test out fallback only pools and new-style notes
ns1_record = {
'answers': [{
'answer': ['1.1.1.1'],
'meta': {
'priority': 1,
'note': 'from:one__country pool:one fallback:two',
},
'region': 'one_country',
}, {
'answer': ['2.2.2.2'],
'meta': {
'priority': 2,
'note': 'from:one__country pool:two fallback:three',
},
'region': 'one_country',
}, {
'answer': ['3.3.3.3'],
'meta': {
'priority': 3,
'note': 'from:one__country pool:three fallback:',
},
'region': 'one_country',
}, {
'answer': ['5.5.5.5'],
'meta': {
'priority': 4,
'note': 'from:--default--',
},
'region': 'one_country',
}, {
'answer': ['4.4.4.4'],
'meta': {
'priority': 1,
'note': 'from:four__country pool:four fallback:',
},
'region': 'four_country',
}, {
'answer': ['5.5.5.5'],
'meta': {
'priority': 2,
'note': 'from:--default--',
},
'region': 'four_country',
}],
'domain': 'unit.tests',
'filters': filters,
'regions': {
'one__country': {
'meta': {
'note': 'rule-order:1 fallback:two',
'country': ['CA'],
'us_state': ['OR'],
},
},
'four__country': {
'meta': {
'note': 'rule-order:2',
'country': ['CA'],
'us_state': ['OR'],
},
},
catchall_pool_name: {
'meta': {
'note': 'rule-order:3',
},
}
},
'tier': 3,
'ttl': 42,
}
data = provider._data_for_dynamic_A('A', ns1_record)
self.assertEquals({
'dynamic': {
'pools': {
'four': {
'fallback': None,
'values': [{'value': '4.4.4.4', 'weight': 1}]
},
'one': {
'fallback': 'two',
'values': [{'value': '1.1.1.1', 'weight': 1}]
},
'three': {
'fallback': None,
'values': [{'value': '3.3.3.3', 'weight': 1}]
},
'two': {
'fallback': 'three',
'values': [{'value': '2.2.2.2', 'weight': 1}]
},
},
'rules': [{
'_order': '1',
'geos': ['NA-CA', 'NA-US-OR'],
'pool': 'one'
}, {
'_order': '2',
'geos': ['NA-CA', 'NA-US-OR'],
'pool': 'four'
}, {
'_order': '3', 'pool': 'iad'}
]
},
'ttl': 42,
'type': 'A',
'values': ['5.5.5.5']
}, data)
@patch('ns1.rest.records.Records.retrieve')
@patch('ns1.rest.zones.Zones.retrieve')
@patch('octodns.provider.ns1.Ns1Provider._monitors_for')