1
0
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:
Ross McFarland
2021-08-23 18:00:24 -07:00
parent aa88b877c4
commit 025180ac3f
2 changed files with 29 additions and 2 deletions

View File

@@ -224,16 +224,20 @@ class Ns1Client(object):
return cached[_type] return cached[_type]
def records_update(self, zone, domain, _type, **params): def records_update(self, zone, domain, _type, **params):
cached = self._records_cache.setdefault(zone, {}) \
.setdefault(domain, {})
try: try:
# remove record's zone from cache # remove record's zone from cache
del self._zones_cache[zone] del self._zones_cache[zone]
# remove record from cache, after zone since we may not have # remove record from cache, after zone since we may not have
# fetched the record details # fetched the record details
del self._records_cache[zone][domain][_type] del cached[_type]
except KeyError: except KeyError:
# never mind if record is not found in cache # never mind if record is not found in cache
pass 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): def zones_create(self, name):
self._zones_cache[name] = self._try(self._zones.create, name) self._zones_cache[name] = self._try(self._zones.create, name)

View File

@@ -2614,3 +2614,26 @@ class TestNs1Client(TestCase):
self.assertEquals({ self.assertEquals({
'sub.unit.tests': 'bar', 'sub.unit.tests': 'bar',
}, client._zones_cache) }, 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)