1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00

Vastly improved CloudflareProvider _apply_Update, much safer

This commit is contained in:
Ross McFarland
2018-10-15 16:29:36 -07:00
parent c66feba63f
commit e0c4e60c43
2 changed files with 138 additions and 83 deletions

View File

@@ -287,14 +287,16 @@ class TestCloudflareProvider(TestCase):
self.assertEquals(2, len(plan.changes))
self.assertEquals(2, provider.apply(plan))
self.assertTrue(plan.exists)
# recreate for update, and deletes for the 2 parts of the other
# creates a the new value and then deletes all the old
provider._request.assert_has_calls([
call('PUT', '/zones/ff12ab34cd5611334422ab3322997650/dns_records/'
'fc12ab34cd5611334422ab3322997655',
data={'content': '3.2.3.4',
'type': 'A',
'name': 'ttl.unit.tests',
'ttl': 300}),
call('POST', '/zones/42/dns_records', data={
'content': '3.2.3.4',
'type': 'A',
'name': 'ttl.unit.tests',
'ttl': 300
}),
call('DELETE',
'/zones/42/dns_records/fc12ab34cd5611334422ab3322997655'),
call('DELETE', '/zones/ff12ab34cd5611334422ab3322997650/'
'dns_records/fc12ab34cd5611334422ab3322997653'),
call('DELETE', '/zones/ff12ab34cd5611334422ab3322997650/'
@@ -351,6 +353,8 @@ class TestCloudflareProvider(TestCase):
}, # zone create
None,
None,
None,
None,
]
# Add something and delete something
@@ -371,17 +375,35 @@ class TestCloudflareProvider(TestCase):
plan = Plan(zone, zone, [change], True)
provider._apply(plan)
# get the list of zones, create a zone, add some records, update
# something, and delete something
provider._request.assert_has_calls([
call('GET', '/zones', params={'page': 1}),
call('POST', '/zones', data={'jump_start': False,
'name': 'unit.tests'}),
call('PUT', '/zones/ff12ab34cd5611334422ab3322997650/dns_records/'
'fc12ab34cd5611334422ab3322997653',
data={'content': '4.4.4.4', 'type': 'A', 'name':
'a.unit.tests', 'ttl': 300}),
call('POST', '/zones/42/dns_records',
data={'content': '3.3.3.3', 'type': 'A',
'name': 'a.unit.tests', 'ttl': 300})
call('POST', '/zones', data={
'jump_start': False,
'name': 'unit.tests'
}),
call('POST', '/zones/42/dns_records', data={
'content': '3.3.3.3',
'type': 'A',
'name': 'a.unit.tests',
'ttl': 300
}),
call('POST', '/zones/42/dns_records', data={
'content': '4.4.4.4',
'type': 'A',
'name': 'a.unit.tests',
'ttl': 300
}),
call('PUT', '/zones/42/dns_records/'
'fc12ab34cd5611334422ab3322997654', data={
'content': '2.2.2.2',
'type': 'A',
'name': 'a.unit.tests',
'ttl': 300
}),
call('DELETE', '/zones/42/dns_records/'
'fc12ab34cd5611334422ab3322997653')
])
def test_update_delete(self):
@@ -456,12 +478,22 @@ class TestCloudflareProvider(TestCase):
plan = Plan(zone, zone, [change], True)
provider._apply(plan)
# Get zones, create zone, create a record, delete a record
provider._request.assert_has_calls([
call('GET', '/zones', params={'page': 1}),
call('POST', '/zones',
data={'jump_start': False, 'name': 'unit.tests'}),
call('DELETE', '/zones/ff12ab34cd5611334422ab3322997650/'
'dns_records/fc12ab34cd5611334422ab3322997653')
call('POST', '/zones', data={
'jump_start': False,
'name': 'unit.tests'
}),
call('PUT', '/zones/42/dns_records/'
'fc12ab34cd5611334422ab3322997654', data={
'content': 'ns2.foo.bar.',
'type': 'NS',
'name': 'unit.tests',
'ttl': 300
}),
call('DELETE', '/zones/42/dns_records/'
'fc12ab34cd5611334422ab3322997653')
])
def test_alias(self):
@@ -498,9 +530,9 @@ class TestCloudflareProvider(TestCase):
self.assertEquals('www.unit.tests.', record.value)
# Make sure we transform back to CNAME going the other way
contents = provider._gen_contents(record)
contents = provider._gen_data(record)
self.assertEquals({
'content': u'www.unit.tests.',
'content': 'www.unit.tests.',
'name': 'unit.tests',
'ttl': 300,
'type': 'CNAME'