~cjwatson/python-oops/py3

« back to all changes in this revision

Viewing changes to oops/tests/test_config.py

  • Committer: James Westby
  • Date: 2012-06-26 21:14:45 UTC
  • mfrom: (28.1.13 refactor-publishing)
  • Revision ID: james.westby@canonical.com-20120626211445-tjwwenguepcwzig8
Refactor publication to better support publish_only_new.

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
        def pub_1(report):
73
73
            return '1'
74
74
        def pub_2(report):
75
 
            self.assertEqual('1', report['id'])
76
75
            return '2'
77
76
        config = Config()
78
77
        config.publishers.append(pub_1)
79
78
        config.publishers.append(pub_2)
80
79
        report = {}
81
80
        self.assertEqual(['1', '2'], config.publish(report))
82
 
        self.assertEqual({'id': '2'}, report)
83
81
 
84
82
    def test_publish_filters_first(self):
85
83
        calls = []
101
99
        self.assertEqual(['ok', 'block'], calls)
102
100
 
103
101
    def test_publishers_returning_not_published_no_change_to_report(self):
104
 
        # If a publisher returns non-zero (indicating it did not publish) no
 
102
        # If a publisher returns False (indicating it did not publish) no
105
103
        # change is made to the report - this permits chaining publishers as a
106
104
        # primary and fallback: The fallback can choose to do nothing if there
107
105
        # is an id already assigned (and returns None to signal what it did);
114
112
        config.publishers.append(pub_succeed)
115
113
        config.publishers.append(pub_noop)
116
114
        report = {}
117
 
        self.assertEqual(['1', None], config.publish(report))
118
 
        self.assertEqual({'id': '1'}, report)
 
115
        self.assertEqual(['1'], config.publish(report))
 
116
 
 
117
    def test_publish_to_publisher(self):
 
118
        calls = []
 
119
        config = Config()
 
120
        def succeed(report):
 
121
            calls.append(report.copy())
 
122
            return ['a']
 
123
        config.publisher = succeed
 
124
        report = dict(foo='bar')
 
125
        config.publish(report)
 
126
        self.assertEqual([dict(foo='bar')], calls)
 
127
 
 
128
    def test_returns_return_value_of_publisher(self):
 
129
        ids = ['a', 'b']
 
130
        def succeed(report):
 
131
            return ids
 
132
        config = Config()
 
133
        config.publisher = succeed
 
134
        report = dict(foo='bar')
 
135
        self.assertEqual(ids, config.publish(report))
 
136
 
 
137
    def test_publisher_and_publishers_used_together(self):
 
138
        calls = []
 
139
        def nopublish(report):
 
140
            calls.append(report)
 
141
            return []
 
142
        config = Config()
 
143
        config.publisher = nopublish
 
144
        config.publishers.append(nopublish)
 
145
        config.publish({})
 
146
        self.assertEqual(2, len(calls))
 
147
 
 
148
    def test_puts_id_in_report(self):
 
149
        the_id = 'b'
 
150
        def succeed(report):
 
151
            return ['a', the_id]
 
152
        config = Config()
 
153
        config.publisher = succeed
 
154
        report = dict(foo='bar')
 
155
        config.publish(report)
 
156
        self.assertEqual(the_id, report['id'])