Merge lp:~mew/charm-helpers/relationset-withdict into lp:charm-helpers

Proposed by Matthew Wedgwood
Status: Merged
Approved by: Haw Loeung
Approved revision: 14
Merged at revision: 13
Proposed branch: lp:~mew/charm-helpers/relationset-withdict
Merge into: lp:charm-helpers
Diff against target: 41 lines (+10/-2)
2 files modified
charmhelpers/core/hookenv.py (+3/-1)
tests/core/test_hookenv.py (+7/-1)
To merge this branch: bzr merge lp:~mew/charm-helpers/relationset-withdict
Reviewer Review Type Date Requested Status
Haw Loeung Approve
Review via email: mp+166678@code.launchpad.net

Commit message

Accommodate relation setting keys that are not valid python identifiers

Description of the change

**kwargs only accepts keys that are valid python identifiers. This change allows relation-set to take settings that, for example, contain dashes. It maintains backward compatibility with **kwargs settings.

To post a comment you must log in.
Revision history for this message
Haw Loeung (hloeung) wrote :

Looks good to me, +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/core/hookenv.py'
2--- charmhelpers/core/hookenv.py 2013-05-21 21:01:31 +0000
3+++ charmhelpers/core/hookenv.py 2013-05-31 08:38:25 +0000
4@@ -124,10 +124,12 @@
5 return None
6
7
8-def relation_set(relation_id=None, **kwargs):
9+def relation_set(relation_id=None, relation_settings={}, **kwargs):
10 relation_cmd_line = ['relation-set']
11 if relation_id is not None:
12 relation_cmd_line.extend(('-r', relation_id))
13+ for k, v in relation_settings.items():
14+ relation_cmd_line.append('{}={}'.format(k, v))
15 for k, v in kwargs.items():
16 relation_cmd_line.append('{}={}'.format(k, v))
17 subprocess.check_call(relation_cmd_line)
18
19=== modified file 'tests/core/test_hookenv.py'
20--- tests/core/test_hookenv.py 2013-05-21 21:01:31 +0000
21+++ tests/core/test_hookenv.py 2013-05-31 08:38:25 +0000
22@@ -497,12 +497,18 @@
23 123, 'baz-scope', 'baz-unit'])
24
25 @patch('subprocess.check_call')
26- def test_sets_relation(self, check_call_):
27+ def test_sets_relation_with_kwargs(self, check_call_):
28 hookenv.relation_set(foo="bar")
29 check_call_.assert_called_with(['relation-set','foo=bar'])
30
31
32 @patch('subprocess.check_call')
33+ def test_sets_relation_with_dict(self, check_call_):
34+ hookenv.relation_set(relation_settings={"foo":"bar"})
35+ check_call_.assert_called_with(['relation-set','foo=bar'])
36+
37+
38+ @patch('subprocess.check_call')
39 def test_sets_relation_with_relation_id(self, check_call_):
40 hookenv.relation_set(relation_id="foo", bar="baz")
41 check_call_.assert_called_with(['relation-set', '-r', 'foo',

Subscribers

People subscribed via source and target branches