Browse Source

Zone.apply(changes)

pull/1223/head
Ross McFarland 1 year ago
parent
commit
fda93452ca
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
2 changed files with 22 additions and 0 deletions
  1. +10
    -0
      octodns/zone.py
  2. +12
    -0
      tests/test_octodns_zone.py

+ 10
- 0
octodns/zone.py View File

@ -340,6 +340,16 @@ class Zone(object):
return changes
def apply(self, changes):
'''
Apply the provided changes to the zone.
'''
for change in changes:
if isinstance(change, Delete):
self.remove_record(change.existing)
else:
self.add_record(change.new, replace=True, lenient=True)
def hydrate(self):
'''
Take a shallow copy Zone and make it a deeper copy holding its own


+ 12
- 0
tests/test_octodns_zone.py View File

@ -179,6 +179,9 @@ class TestZone(TestCase):
# before == after -> no changes
self.assertFalse(before.changes(after, target))
copy = before.copy()
copy.apply([])
self.assertEqual(copy.records, before.records)
# add a record, delete a record -> [Delete, Create]
c = ARecord(before, 'c', {'ttl': 42, 'value': '1.1.1.1'})
@ -199,6 +202,15 @@ class TestZone(TestCase):
delete.__repr__()
create.__repr__()
# make a copy of before
copy = before.copy()
# apply the changes to it
copy.apply(changes)
# copy should not match it's origin any longer
self.assertNotEqual(copy.records, before.records)
# and it should now match the target
self.assertEqual(copy.records, after.records)
after = Zone('unit.tests.', [])
changed = ARecord(before, 'a', {'ttl': 42, 'value': '2.2.2.2'})
after.add_record(changed)


Loading…
Cancel
Save