Merge lp:~tribaal/charms/trusty/landscape-client/fix-unit-tests-take-two into lp:charms/trusty/landscape-client

Proposed by Chris Glass
Status: Merged
Merged at revision: 44
Proposed branch: lp:~tribaal/charms/trusty/landscape-client/fix-unit-tests-take-two
Merge into: lp:charms/trusty/landscape-client
Diff against target: 74 lines (+13/-4)
4 files modified
hooks/common.py (+4/-1)
hooks/hooks.py (+4/-3)
hooks/install.py (+1/-0)
hooks/test_hooks.py (+4/-0)
To merge this branch: bzr merge lp:~tribaal/charms/trusty/landscape-client/fix-unit-tests-take-two
Reviewer Review Type Date Requested Status
Adam Collard Approve
Free Ekanayaka (community) Approve
Review via email: mp+232534@code.launchpad.net

Description of the change

Fixes unit tests by making unit_name lazy instead of reading the env var at import time.

To post a comment you must log in.
Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

Tests pass fine here and the diff looks good. +1!

review: Approve
Revision history for this message
Adam Collard (adam-collard) wrote :

One lint issue:

=== pep8 ===

hooks/install.py:45:1: E302 expected 2 blank lines, found 1

Otherwise a big +1

review: Approve
45. By Chris Glass

Lint fix

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/common.py'
2--- hooks/common.py 2014-06-23 11:25:40 +0000
3+++ hooks/common.py 2014-08-28 10:09:37 +0000
4@@ -55,7 +55,10 @@
5
6 def __init__(self):
7 self.config = Configuration()
8- self.local_unit = local_unit()
9+
10+ @property
11+ def local_unit(self):
12+ return local_unit()
13
14 def update_client_config(self, service_config, try_to_register=True):
15 """Update the client config.
16
17=== modified file 'hooks/hooks.py'
18--- hooks/hooks.py 2014-08-22 09:15:59 +0000
19+++ hooks/hooks.py 2014-08-28 10:09:37 +0000
20@@ -6,7 +6,7 @@
21 import base64
22
23 from charmhelpers.core.hookenv import (
24- Hooks, UnregisteredHookError, log, local_unit)
25+ Hooks, UnregisteredHookError, log)
26 from shutil import rmtree
27 from subprocess import CalledProcessError
28
29@@ -41,7 +41,7 @@
30 @param relation_data: data from the context of a relation, it should
31 match the data in the config
32 """
33- log("In config-changed for %s" % local_unit())
34+ juju_broker.log("In config-changed for %s" % landscape_broker.local_unit)
35 if relation_data is None:
36 relation_data = {}
37 service_config = juju_broker.get_service_config()
38@@ -67,7 +67,8 @@
39 @hooks.hook("container-relation-joined", "ceph-client-relation-joined")
40 def container_relation_joined(juju_broker=JUJU_BROKER,
41 landscape_broker=LANDSCAPE_BROKER):
42- log("In container-relation-joined for %s" % local_unit())
43+ juju_broker.log("In container-relation-joined for %s"
44+ "" % landscape_broker.local_unit)
45 landscape_broker.config.reload()
46 relation_conf = juju_broker.get_relation_config()
47 remote_unit_name = juju_broker.environment.get("JUJU_REMOTE_UNIT")
48
49=== modified file 'hooks/install.py'
50--- hooks/install.py 2014-06-17 16:45:42 +0000
51+++ hooks/install.py 2014-08-28 10:09:37 +0000
52@@ -42,6 +42,7 @@
53 "install", "-o", "landscape", "-g", "root", "-m", "755", "-d",
54 data_path])
55
56+
57 def build_from_launchpad(url):
58 """The charm will install the code from the passed lp branch.
59 """
60
61=== modified file 'hooks/test_hooks.py'
62--- hooks/test_hooks.py 2014-06-13 09:18:29 +0000
63+++ hooks/test_hooks.py 2014-08-28 10:09:37 +0000
64@@ -47,6 +47,10 @@
65 def clear_registration(self):
66 self.cleared_registration = True
67
68+ @property
69+ def local_unit(self):
70+ return "test-unit"
71+
72
73 class HookTestCase(TestCase):
74 """Base test class for testing hooks."""

Subscribers

People subscribed via source and target branches