1
"""Common test classes and functions used by unit tests"""
5
class TestHookenv(object):
7
Testing object to intercept juju calls and inject data, or make sure
12
_incoming_relation_data = ()
13
_outgoing_relation_data = ()
23
def __init__(self, config={}):
24
for key, value in config.iteritems():
25
self._config = self._config + ((key, value),)
27
def config(self, scope=None):
28
"""Return our initialized config information or a specific value"""
30
for key, value in self._config:
34
return dict((key, value) for key, value in self._config)
36
def relation_set(self, relid=None, relation_settings={}):
38
Capture result of relation_set into _outgoing_relation_data, which
39
can then be checked later.
41
for key, value in relation_settings.iteritems():
42
self._outgoing_relation_data = (
43
self._outgoing_relation_data + ((key, value),))
45
def relation_ids(self, relation_name="website"):
47
Hardcode expected relation_ids for tests. Feel free to expand
48
as more tests are added.
50
return ["%s:1" % relation_name]
52
def related_units(self, relation_id="website:1"):
54
Hardcode expected related_units for tests. Feel free to expand
55
as more tests are added.
57
return ["%s/0" % relation_id.split(":")[0]]
59
def relation_list(self):
61
Hardcode expected relation_list for tests. Feel free to expand
62
as more tests are added.
64
return list(self._relation_list)
66
def unit_get(self, *args):
68
for now the only thing this is called for is "public-address",
69
so it's a simplistic return.
74
return os.environ["JUJU_UNIT_NAME"]
76
def log(self, message, level):
77
self._log = self._log + (message,)
79
def is_logged(self, message):
80
for line in self._log:
85
def config_get(self, scope=None):
87
for key, value in self._config:
91
return dict((key, value) for key, value in self._config)
93
def relation_get(self, scope=None, unit=None, rid=None):
94
data = self._incoming_relation_data
96
for (rel_id, key, value) in data:
97
if rel_id == rid and key == scope:
101
(key, value) for (rel_id, key, value) in data if rel_id == rid)