Skip to content

Commit

Permalink
Add TestingHarold to testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Logan Hanks committed Jan 18, 2012
1 parent 85284e1 commit 32d3234
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions testing.py
@@ -1,5 +1,7 @@
import tempfile

import wessex

import alerts

def stub(namespace, name):
Expand All @@ -24,7 +26,20 @@ def wrapped(*args, **kwargs):
return wrapped
return decorator

class TestingHarold(wessex.Harold):
def __init__(self, *args, **kwargs):
super(TestingHarold, self).__init__(*args, **kwargs)
self.reset_for_testing()

def _post_to_harold(self, path, data):
self.post_log.append((path, data))

def reset_for_testing(self):
self.post_log = []

@stub(wessex, 'Harold')
def init_alerts(**sections):
wessex.Harold = TestingHarold
config = dict(
harold=dict(host='localhost', port=8888, secret='secret'),
)
Expand All @@ -37,3 +52,5 @@ def init_alerts(**sections):
f.write('\n')
f.flush()
alerts.init(config_path=f.name)


1 change: 1 addition & 0 deletions testing_test.py
Expand Up @@ -49,6 +49,7 @@ def test_init(self):
self.assertEquals(8888, alerts.harold.port)
self.assertEquals('secret', alerts.harold.secret)
self.assertEquals(1, alerts.config.getint('custom1', 'a'))
self.assertTrue(isinstance(alerts.harold, testing.TestingHarold))

if __name__ == '__main__':
unittest.main()

0 comments on commit 32d3234

Please sign in to comment.