~james-w/python-oops/update-readme-dependencies

« back to all changes in this revision

Viewing changes to oops/tests/test_config.py

  • Committer: Robert Collins
  • Date: 2011-08-15 06:42:14 UTC
  • Revision ID: robertc@robertcollins.net-20110815064214-ncyynjzdwk0ci1a8
Bump to v4, delete disk based storage - moved that to python-oops-datedir-repo - and add core create/publish functionality.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2010, 2011, Canonical Ltd
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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).
 
16
 
 
17
"""Tests for the legacy rfc822 based [de]serializer."""
 
18
 
 
19
__metaclass__ = type
 
20
 
 
21
from functools import partial
 
22
 
 
23
import testtools
 
24
from testtools.matchers import Is
 
25
 
 
26
from oops.config import Config
 
27
 
 
28
 
 
29
class TestConfig(testtools.TestCase):
 
30
 
 
31
    def test_init(self):
 
32
        config = Config()
 
33
        self.assertEqual([], config.on_create)
 
34
        self.assertEqual([], config.publishers)
 
35
        self.assertEqual({}, config.template)
 
36
 
 
37
    def test_on_create_called(self):
 
38
        calls = []
 
39
        def capture(id, report):
 
40
            calls.append((id, report))
 
41
        config = Config()
 
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)
 
48
 
 
49
    def test_create_template(self):
 
50
        config = Config()
 
51
        config.template['base'] = True
 
52
        report = config.create()
 
53
        self.assertEqual({'base': True}, report)
 
54
 
 
55
    def test_publish_calls_publishers(self):
 
56
        calls = []
 
57
        def pub_1(report):
 
58
            return '1'
 
59
        def pub_2(report):
 
60
            self.assertEqual('1', report['id'])
 
61
            return '2'
 
62
        config = Config()
 
63
        config.publishers.append(pub_1)
 
64
        config.publishers.append(pub_2)
 
65
        report = {}
 
66
        self.assertEqual(['1', '2'], config.publish(report))
 
67
        self.assertEqual({'id': '2'}, report)
 
68