Browse Source

Add __eq__, __ne__, and __repr__ to Dynamic objects and test

pull/307/head
Ross McFarland 7 years ago
parent
commit
b80348c2c7
No known key found for this signature in database GPG Key ID: 61C10C4FC8FE4A89
2 changed files with 136 additions and 1 deletions
  1. +28
    -0
      octodns/record.py
  2. +108
    -1
      tests/test_octodns_record.py

+ 28
- 0
octodns/record.py View File

@ -396,6 +396,15 @@ class _DynamicPool(object):
def _data(self): def _data(self):
return self.data return self.data
def __eq__(self, other):
return self.data == other.data
def __ne__(self, other):
return not self.__eq__(other)
def __repr__(self):
return '{}'.format(self.data)
class _DynamicRule(object): class _DynamicRule(object):
@ -407,6 +416,15 @@ class _DynamicRule(object):
def _data(self): def _data(self):
return self.data return self.data
def __eq__(self, other):
return self.data == other.data
def __ne__(self, other):
return not self.__eq__(other)
def __repr__(self):
return '{}'.format(self.data)
class _Dynamic(object): class _Dynamic(object):
@ -426,6 +444,16 @@ class _Dynamic(object):
'rules': rules, 'rules': rules,
} }
def __eq__(self, other):
ret = self.pools == other.pools and self.rules == other.rules
return ret
def __ne__(self, other):
return not self.__eq__(other)
def __repr__(self):
return '{}, {}'.format(self.pools, self.rules)
class _DynamicMixin(object): class _DynamicMixin(object):


+ 108
- 1
tests/test_octodns_record.py View File

@ -13,7 +13,7 @@ from octodns.record import ARecord, AaaaRecord, AliasRecord, CaaRecord, \
TxtRecord, Update, ValidationError TxtRecord, Update, ValidationError
from octodns.zone import Zone from octodns.zone import Zone
from helpers import GeoProvider, SimpleProvider
from helpers import DynamicProvider, GeoProvider, SimpleProvider
class TestRecord(TestCase): class TestRecord(TestCase):
@ -2389,3 +2389,110 @@ class TestDynamicRecords(TestCase):
}, },
'rules': [], 'rules': [],
}, a._data()['dynamic']) }, a._data()['dynamic'])
def test_dynamic_changes(self):
simple = SimpleProvider()
dynamic = DynamicProvider()
a_data = {
'dynamic': {
'pools': {
'one': '3.3.3.3',
'two': [
'4.4.4.4',
'5.5.5.5',
],
},
'rules': [{
'pools': {
100: 'one',
200: 'two',
}
}],
},
'ttl': 60,
'values': [
'1.1.1.1',
'2.2.2.2',
],
}
a = ARecord(self.zone, 'weighted', a_data)
dup = ARecord(self.zone, 'weighted', a_data)
b_data = {
'dynamic': {
'pools': {
'one': '3.3.3.5',
'two': [
'4.4.4.4',
'5.5.5.5',
],
},
'rules': [{
'pools': {
100: 'one',
200: 'two',
}
}],
},
'ttl': 60,
'values': [
'1.1.1.1',
'2.2.2.2',
],
}
b = ARecord(self.zone, 'weighted', b_data)
c_data = {
'dynamic': {
'pools': {
'one': '3.3.3.3',
'two': [
'4.4.4.4',
'5.5.5.5',
],
},
'rules': [{
'pools': {
100: 'one',
300: 'two',
}
}],
},
'ttl': 60,
'values': [
'1.1.1.1',
'2.2.2.2',
],
}
c = ARecord(self.zone, 'weighted', c_data)
# a changes a (identical dup) is never true
self.assertFalse(a.changes(dup, simple))
self.assertFalse(a.changes(dup, dynamic))
# a changes b is not true for simple
self.assertFalse(a.changes(b, simple))
# but is true for dynamic
update = a.changes(b, dynamic)
self.assertEquals(a, update.existing)
self.assertEquals(b, update.new)
# transitive
self.assertFalse(b.changes(a, simple))
update = b.changes(a, dynamic)
self.assertEquals(a, update.existing)
self.assertEquals(b, update.new)
# same for a change c
self.assertFalse(a.changes(c, simple))
self.assertTrue(a.changes(c, dynamic))
self.assertFalse(c.changes(a, simple))
self.assertTrue(c.changes(a, dynamic))
# smoke test some of the equiality bits
self.assertEquals(a.dynamic.pools, a.dynamic.pools)
self.assertEquals(a.dynamic.pools['one'], a.dynamic.pools['one'])
self.assertNotEquals(a.dynamic.pools['one'], a.dynamic.pools['two'])
self.assertEquals(a.dynamic.rules, a.dynamic.rules)
self.assertEquals(a.dynamic.rules[0], a.dynamic.rules[0])
self.assertNotEquals(a.dynamic.rules[0], c.dynamic.rules[0])

Loading…
Cancel
Save