Skip to content

Instantly share code, notes, and snippets.

@bodepd
Created September 19, 2014 19:48
Show Gist options
  • Save bodepd/768cf3f293007225337d to your computer and use it in GitHub Desktop.
Save bodepd/768cf3f293007225337d to your computer and use it in GitHub Desktop.
def test_get_failures(self):
with mock.patch.object(self.do, '_etcd') as etcd:
results = {
'should_pass': [
[],
{'puppet': [self.EtcdKey('/status/puppet/failed')]},
{'validation': [self.EtcdKey('/status/validation/failed')]},
],
'should_fail': [
{'puppet': [self.EtcdKey('/status/puppet/failed/foo')]},
{'validation': [self.EtcdKey('/status/validation/failed/bar')]},
]
}
for k,v in results.iteritems():
for data in v:
def mock_read(arg):
if arg == '/status/puppet/failed':
return self.EtcdResult(data['puppet'])
if arg == '/status/validation/failed':
return self.EtcdResult(data['validation'])
if data == []:
etcd.read.return_value = self.EtcdResult(data)
else:
etcd.read.side_effect = mock_read
if k == 'should_pass':
self.assertEquals(True, self.do.get_failures(self))
else:
self.assertEquals(False, self.do.get_failures(self))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment