mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Tests for ns1 _monitors_gc
This commit is contained in:
@@ -726,8 +726,8 @@ class Ns1Provider(BaseProvider):
|
||||
|
||||
return monitor_id, feed_id
|
||||
|
||||
def _gc_monitors(self, record, active_monitor_ids=None):
|
||||
self.log.debug('_gc_monitors: record=%s, active_monitor_ids=%s',
|
||||
def _monitors_gc(self, record, active_monitor_ids=None):
|
||||
self.log.debug('_monitors_gc: record=%s, active_monitor_ids=%s',
|
||||
record.fqdn, active_monitor_ids)
|
||||
|
||||
if active_monitor_ids is None:
|
||||
@@ -738,7 +738,7 @@ class Ns1Provider(BaseProvider):
|
||||
if monitor_id in active_monitor_ids:
|
||||
continue
|
||||
|
||||
self.log.debug('_gc_monitors: deleting %s', monitor_id)
|
||||
self.log.debug('_monitors_gc: deleting %s', monitor_id)
|
||||
|
||||
feed_id = self._client.feeds_for_monitors.get(monitor_id)
|
||||
if feed_id:
|
||||
@@ -957,7 +957,7 @@ class Ns1Provider(BaseProvider):
|
||||
params, active_monitor_ids = \
|
||||
getattr(self, '_params_for_{}'.format(_type))(new)
|
||||
self._client.records_create(zone, domain, _type, **params)
|
||||
self._gc_monitors(new, active_monitor_ids)
|
||||
self._monitors_gc(new, active_monitor_ids)
|
||||
|
||||
def _apply_Update(self, ns1_zone, change):
|
||||
new = change.new
|
||||
@@ -967,7 +967,7 @@ class Ns1Provider(BaseProvider):
|
||||
params, active_monitor_ids = \
|
||||
getattr(self, '_params_for_{}'.format(_type))(new)
|
||||
self._client.records_update(zone, domain, _type, **params)
|
||||
self._gc_monitors(new, active_monitor_ids)
|
||||
self._monitors_gc(new, active_monitor_ids)
|
||||
|
||||
def _apply_Delete(self, ns1_zone, change):
|
||||
existing = change.existing
|
||||
@@ -975,7 +975,7 @@ class Ns1Provider(BaseProvider):
|
||||
domain = existing.fqdn[:-1]
|
||||
_type = existing._type
|
||||
self._client.records_delete(zone, domain, _type)
|
||||
self._gc_monitors(existing)
|
||||
self._monitors_gc(existing)
|
||||
|
||||
def _apply(self, plan):
|
||||
desired = plan.desired
|
||||
|
@@ -829,6 +829,89 @@ class TestNs1ProviderDynamic(TestCase):
|
||||
monitors_update_mock.assert_has_calls([call('mon-id', other='thing')])
|
||||
feed_create_mock.assert_not_called()
|
||||
|
||||
@patch('octodns.provider.ns1.Ns1Client.notifylists_delete')
|
||||
@patch('octodns.provider.ns1.Ns1Client.monitors_delete')
|
||||
@patch('octodns.provider.ns1.Ns1Client.datafeed_delete')
|
||||
@patch('octodns.provider.ns1.Ns1Provider._monitors_for')
|
||||
def test_monitors_gc(self, monitors_for_mock, datafeed_delete_mock,
|
||||
monitors_delete_mock, notifylists_delete_mock):
|
||||
provider = Ns1Provider('test', 'api-key')
|
||||
|
||||
# pre-fill caches to avoid extranious calls (things we're testing
|
||||
# elsewhere)
|
||||
provider._client._datasource_id = 'foo'
|
||||
provider._client._feeds_for_monitors = {
|
||||
'mon-id': 'feed-id',
|
||||
}
|
||||
|
||||
# No active monitors and no existing, nothing will happen
|
||||
monitors_for_mock.reset_mock()
|
||||
datafeed_delete_mock.reset_mock()
|
||||
monitors_delete_mock.reset_mock()
|
||||
notifylists_delete_mock.reset_mock()
|
||||
monitors_for_mock.side_effect = [{}]
|
||||
provider._monitors_gc(self.record)
|
||||
monitors_for_mock.assert_has_calls([call(self.record)])
|
||||
datafeed_delete_mock.assert_not_called()
|
||||
monitors_delete_mock.assert_not_called()
|
||||
notifylists_delete_mock.assert_not_called()
|
||||
|
||||
# No active monitors and one existing, delete all the things
|
||||
monitors_for_mock.reset_mock()
|
||||
datafeed_delete_mock.reset_mock()
|
||||
monitors_delete_mock.reset_mock()
|
||||
notifylists_delete_mock.reset_mock()
|
||||
monitors_for_mock.side_effect = [{
|
||||
'x': {
|
||||
'id': 'mon-id',
|
||||
'notify_list': 'nl-id',
|
||||
}
|
||||
}]
|
||||
provider._monitors_gc(self.record)
|
||||
monitors_for_mock.assert_has_calls([call(self.record)])
|
||||
datafeed_delete_mock.assert_has_calls([call('foo', 'feed-id')])
|
||||
monitors_delete_mock.assert_has_calls([call('mon-id')])
|
||||
notifylists_delete_mock.assert_has_calls([call('nl-id')])
|
||||
|
||||
# Same existing, this time in active list, should be noop
|
||||
monitors_for_mock.reset_mock()
|
||||
datafeed_delete_mock.reset_mock()
|
||||
monitors_delete_mock.reset_mock()
|
||||
notifylists_delete_mock.reset_mock()
|
||||
monitors_for_mock.side_effect = [{
|
||||
'x': {
|
||||
'id': 'mon-id',
|
||||
'notify_list': 'nl-id',
|
||||
}
|
||||
}]
|
||||
provider._monitors_gc(self.record, {'mon-id'})
|
||||
monitors_for_mock.assert_has_calls([call(self.record)])
|
||||
datafeed_delete_mock.assert_not_called()
|
||||
monitors_delete_mock.assert_not_called()
|
||||
notifylists_delete_mock.assert_not_called()
|
||||
|
||||
# Non-active monitor w/o a feed, and another monitor that's left alone
|
||||
# b/c it's active
|
||||
monitors_for_mock.reset_mock()
|
||||
datafeed_delete_mock.reset_mock()
|
||||
monitors_delete_mock.reset_mock()
|
||||
notifylists_delete_mock.reset_mock()
|
||||
monitors_for_mock.side_effect = [{
|
||||
'x': {
|
||||
'id': 'mon-id',
|
||||
'notify_list': 'nl-id',
|
||||
},
|
||||
'y': {
|
||||
'id': 'mon-id2',
|
||||
'notify_list': 'nl-id2',
|
||||
},
|
||||
}]
|
||||
provider._monitors_gc(self.record, {'mon-id'})
|
||||
monitors_for_mock.assert_has_calls([call(self.record)])
|
||||
datafeed_delete_mock.assert_not_called()
|
||||
monitors_delete_mock.assert_has_calls([call('mon-id2')])
|
||||
notifylists_delete_mock.assert_has_calls([call('nl-id2')])
|
||||
|
||||
|
||||
class TestNs1Client(TestCase):
|
||||
|
||||
|
Reference in New Issue
Block a user