mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
NS1Client.records_update result caching & tests
This commit is contained in:
@@ -224,16 +224,20 @@ class Ns1Client(object):
|
||||
return cached[_type]
|
||||
|
||||
def records_update(self, zone, domain, _type, **params):
|
||||
cached = self._records_cache.setdefault(zone, {}) \
|
||||
.setdefault(domain, {})
|
||||
try:
|
||||
# remove record's zone from cache
|
||||
del self._zones_cache[zone]
|
||||
# remove record from cache, after zone since we may not have
|
||||
# fetched the record details
|
||||
del self._records_cache[zone][domain][_type]
|
||||
del cached[_type]
|
||||
except KeyError:
|
||||
# never mind if record is not found in cache
|
||||
pass
|
||||
return self._try(self._records.update, zone, domain, _type, **params)
|
||||
cached[_type] = self._try(self._records.update, zone, domain, _type,
|
||||
**params)
|
||||
return cached[_type]
|
||||
|
||||
def zones_create(self, name):
|
||||
self._zones_cache[name] = self._try(self._zones.create, name)
|
||||
|
||||
@@ -2614,3 +2614,26 @@ class TestNs1Client(TestCase):
|
||||
self.assertEquals({
|
||||
'sub.unit.tests': 'bar',
|
||||
}, client._zones_cache)
|
||||
|
||||
# Record update removes zone and caches result
|
||||
record_update_mock.side_effect = ['done']
|
||||
self.assertEquals('done', client.records_update('sub.unit.tests',
|
||||
'aaaa.sub.unit.tests',
|
||||
'AAAA', key='val'))
|
||||
record_update_mock.assert_has_calls([call('sub.unit.tests',
|
||||
'aaaa.sub.unit.tests',
|
||||
'AAAA', key='val')])
|
||||
self.assertEquals({
|
||||
'unit.tests': {
|
||||
'a.unit.tests': {
|
||||
'A': 'baz'
|
||||
},
|
||||
'aaaa.unit.tests': {},
|
||||
},
|
||||
'sub.unit.tests': {
|
||||
'aaaa.sub.unit.tests': {
|
||||
'AAAA': 'done',
|
||||
},
|
||||
}
|
||||
}, client._records_cache)
|
||||
self.assertEquals({}, client._zones_cache)
|
||||
|
||||
Reference in New Issue
Block a user