Merge lp:~james-w/python-oops-dictconfig/check-new-only into lp:python-oops-dictconfig

Proposed by James Westby
Status: Merged
Approved by: James Westby
Approved revision: 13
Merged at revision: 13
Proposed branch: lp:~james-w/python-oops-dictconfig/check-new-only
Merge into: lp:python-oops-dictconfig
Diff against target: 48 lines (+19/-1)
2 files modified
oops_dictconfig/dictconfig.py (+1/-1)
oops_dictconfig/tests/test_dictconfig.py (+18/-0)
To merge this branch: bzr merge lp:~james-w/python-oops-dictconfig/check-new-only
Reviewer Review Type Date Requested Status
James Westby (community) Approve
Sidnei da Silva (community) Approve
Review via email: mp+149897@code.launchpad.net

Commit message

Check the value of 'new_only' before deciding whether to wrap the publisher.

Description of the change

Hi,

Currently if the 'new_only' key is in the dict definition then the
resulting publisher will be wrapped. Sometimes it's easier for the
creator to include the key but set it to False, so we check the value
as well before wrapping the publisher.

Thanks,

James

To post a comment you must log in.
Revision history for this message
Sidnei da Silva (sidnei) :
review: Approve
Revision history for this message
James Westby (james-w) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'oops_dictconfig/dictconfig.py'
2--- oops_dictconfig/dictconfig.py 2013-02-06 17:00:45 +0000
3+++ oops_dictconfig/dictconfig.py 2013-02-21 17:48:19 +0000
4@@ -96,7 +96,7 @@
5 raise AssertionError(
6 "Unknown publisher type: %s" % str(publisher_type))
7 publish_method = publisher_factory(publisher_defn)
8- if 'new_only' in publisher_defn:
9+ if 'new_only' in publisher_defn and publisher_defn['new_only']:
10 publish_method = oops.publish_new_only(publish_method)
11 oops_config.publishers.append(publish_method)
12 oops_config.template.update(dict_config.get('template', {}))
13
14=== modified file 'oops_dictconfig/tests/test_dictconfig.py'
15--- oops_dictconfig/tests/test_dictconfig.py 2013-02-06 17:00:45 +0000
16+++ oops_dictconfig/tests/test_dictconfig.py 2013-02-21 17:48:19 +0000
17@@ -93,6 +93,15 @@
18 # publish method was wrapped by oops.publish_new_only
19 self.assertEquals('result', config.publishers[0].func_name)
20
21+ def test_datedir_doesnt_wrap_if_new_only_is_False(self):
22+ publisher_defn = dict(type='datedir', error_dir=self.getUniqueString(),
23+ new_only=False)
24+ config = self.get_config_from_dict([publisher_defn])
25+ # FIXME: brittle test, dependent on implementation details of
26+ # oops.publish_new_only. Find a better way of testing that the
27+ # publish method was not wrapped by oops.publish_new_only
28+ self.assertEquals('publish', config.publishers[0].func_name)
29+
30 def test_amqp_missing_exchange_name_gives_error(self):
31 publisher_defn = dict(type='amqp')
32 e = self.assertRaises(AssertionError,
33@@ -218,6 +227,15 @@
34 # publish method was wrapped by oops.publish_new_only
35 self.assertEquals('result', config.publishers[0].func_name)
36
37+ def test_amqp_doesnt_wrap_if_new_only_is_False(self):
38+ publisher_defn = self.get_basic_ampq_definition()
39+ publisher_defn['new_only'] = False
40+ config = self.get_config_from_dict([publisher_defn])
41+ # FIXME: brittle test, dependent on implementation details of
42+ # oops.publish_new_only. Find a better way of testing that the
43+ # publish method was not wrapped by oops.publish_new_only
44+ self.assertIsInstance(config.publishers[0], oops_amqp.Publisher)
45+
46 def test_no_template_gives_blank_template(self):
47 config = config_from_dict(dict())
48 self.assertEqual({}, config.template)

Subscribers

People subscribed via source and target branches