1
# Copyright (c) 2010, 2011, Canonical Ltd
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as published by
5
# the Free Software Foundation, either version 3 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU Affero General Public License for more details.
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
# GNU Affero General Public License version 3 (see the file LICENSE).
17
"""Tests for the legacy rfc822 based [de]serializer."""
21
from functools import partial
24
from testtools.matchers import Is
26
from oops.config import Config
29
class TestConfig(testtools.TestCase):
33
self.assertEqual([], config.on_create)
34
self.assertEqual([], config.publishers)
35
self.assertEqual({}, config.template)
37
def test_on_create_called(self):
39
def capture(id, report):
40
calls.append((id, report))
42
config.on_create.append(partial(capture, '1'))
43
config.on_create.append(partial(capture, '2'))
44
report = config.create()
45
self.assertThat(report, Is(calls[0][1]))
46
self.assertThat(report, Is(calls[1][1]))
47
self.assertEqual([('1', {}), ('2', {})], calls)
49
def test_create_template(self):
51
config.template['base'] = True
52
report = config.create()
53
self.assertEqual({'base': True}, report)
55
def test_publish_calls_publishers(self):
60
self.assertEqual('1', report['id'])
63
config.publishers.append(pub_1)
64
config.publishers.append(pub_2)
66
self.assertEqual(['1', '2'], config.publish(report))
67
self.assertEqual({'id': '2'}, report)