mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
DynProvider and DnsimpleProvider ALIAS tests
This commit is contained in:
2
tests/fixtures/dnsimple-page-1.json
vendored
2
tests/fixtures/dnsimple-page-1.json
vendored
@@ -308,7 +308,7 @@
|
||||
"pagination": {
|
||||
"current_page": 1,
|
||||
"per_page": 20,
|
||||
"total_entries": 28,
|
||||
"total_entries": 29,
|
||||
"total_pages": 2
|
||||
}
|
||||
}
|
||||
|
||||
18
tests/fixtures/dnsimple-page-2.json
vendored
18
tests/fixtures/dnsimple-page-2.json
vendored
@@ -143,12 +143,28 @@
|
||||
"system_record": false,
|
||||
"created_at": "2017-03-09T15:55:09Z",
|
||||
"updated_at": "2017-03-09T15:55:09Z"
|
||||
},
|
||||
{
|
||||
"id": 11188802,
|
||||
"zone_id": "unit.tests",
|
||||
"parent_id": null,
|
||||
"name": "txt",
|
||||
"content": "ALIAS for www.unit.tests.",
|
||||
"ttl": 600,
|
||||
"priority": null,
|
||||
"type": "TXT",
|
||||
"regions": [
|
||||
"global"
|
||||
],
|
||||
"system_record": false,
|
||||
"created_at": "2017-03-09T15:55:09Z",
|
||||
"updated_at": "2017-03-09T15:55:09Z"
|
||||
}
|
||||
],
|
||||
"pagination": {
|
||||
"current_page": 2,
|
||||
"per_page": 20,
|
||||
"total_entries": 28,
|
||||
"total_entries": 29,
|
||||
"total_pages": 2
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1154,3 +1154,109 @@ class TestDynProviderGeo(TestCase):
|
||||
# old ruleset ruleset should be deleted, it's pool will have been
|
||||
# reused
|
||||
ruleset_mock.delete.assert_called_once()
|
||||
|
||||
|
||||
class TestDynProviderAlias(TestCase):
|
||||
expected = Zone('unit.tests.', [])
|
||||
for name, data in (
|
||||
('', {
|
||||
'type': 'ALIAS',
|
||||
'ttl': 300,
|
||||
'value': 'www.unit.tests.'
|
||||
}),
|
||||
('www', {
|
||||
'type': 'A',
|
||||
'ttl': 300,
|
||||
'values': ['1.2.3.4']
|
||||
})):
|
||||
expected.add_record(Record.new(expected, name, data))
|
||||
|
||||
def setUp(self):
|
||||
# Flush our zone to ensure we start fresh
|
||||
_CachingDynZone.flush_zone(self.expected.name[:-1])
|
||||
|
||||
@patch('dyn.core.SessionEngine.execute')
|
||||
def test_populate(self, execute_mock):
|
||||
provider = DynProvider('test', 'cust', 'user', 'pass')
|
||||
|
||||
# Test Zone create
|
||||
execute_mock.side_effect = [
|
||||
# get Zone
|
||||
{'data': {}},
|
||||
# get_all_records
|
||||
{'data': {
|
||||
'a_records': [{
|
||||
'fqdn': 'www.unit.tests',
|
||||
'rdata': {'address': '1.2.3.4'},
|
||||
'record_id': 1,
|
||||
'record_type': 'A',
|
||||
'ttl': 300,
|
||||
'zone': 'unit.tests',
|
||||
}],
|
||||
'alias_records': [{
|
||||
'fqdn': 'unit.tests',
|
||||
'rdata': {'alias': 'www.unit.tests.'},
|
||||
'record_id': 2,
|
||||
'record_type': 'ALIAS',
|
||||
'ttl': 300,
|
||||
'zone': 'unit.tests',
|
||||
}],
|
||||
}}
|
||||
]
|
||||
got = Zone('unit.tests.', [])
|
||||
provider.populate(got)
|
||||
execute_mock.assert_has_calls([
|
||||
call('/Zone/unit.tests/', 'GET', {}),
|
||||
call('/AllRecord/unit.tests/unit.tests./', 'GET', {'detail': 'Y'})
|
||||
])
|
||||
changes = self.expected.changes(got, SimpleProvider())
|
||||
self.assertEquals([], changes)
|
||||
|
||||
@patch('dyn.core.SessionEngine.execute')
|
||||
def test_sync(self, execute_mock):
|
||||
provider = DynProvider('test', 'cust', 'user', 'pass')
|
||||
|
||||
# Test Zone create
|
||||
execute_mock.side_effect = [
|
||||
# No such zone, during populate
|
||||
DynectGetError('foo'),
|
||||
# No such zone, during sync
|
||||
DynectGetError('foo'),
|
||||
# get empty Zone
|
||||
{'data': {}},
|
||||
# get zone we can modify & delete with
|
||||
{'data': {
|
||||
# A top-level to delete
|
||||
'a_records': [{
|
||||
'fqdn': 'www.unit.tests',
|
||||
'rdata': {'address': '1.2.3.4'},
|
||||
'record_id': 1,
|
||||
'record_type': 'A',
|
||||
'ttl': 300,
|
||||
'zone': 'unit.tests',
|
||||
}],
|
||||
# A node to delete
|
||||
'alias_records': [{
|
||||
'fqdn': 'unit.tests',
|
||||
'rdata': {'alias': 'www.unit.tests.'},
|
||||
'record_id': 2,
|
||||
'record_type': 'ALIAS',
|
||||
'ttl': 300,
|
||||
'zone': 'unit.tests',
|
||||
}],
|
||||
}}
|
||||
]
|
||||
|
||||
# No existing records, create all
|
||||
with patch('dyn.tm.zones.Zone.add_record') as add_mock:
|
||||
with patch('dyn.tm.zones.Zone._update') as update_mock:
|
||||
plan = provider.plan(self.expected)
|
||||
update_mock.assert_not_called()
|
||||
provider.apply(plan)
|
||||
update_mock.assert_called()
|
||||
add_mock.assert_called()
|
||||
# Once for each dyn record
|
||||
self.assertEquals(2, len(add_mock.call_args_list))
|
||||
execute_mock.assert_has_calls([call('/Zone/unit.tests/', 'GET', {}),
|
||||
call('/Zone/unit.tests/', 'GET', {})])
|
||||
self.assertEquals(2, len(plan.changes))
|
||||
|
||||
Reference in New Issue
Block a user