~jcsackett/charmworld/bac-tag-constraints

« back to all changes in this revision

Viewing changes to charmworld/views/tests/test_bundles.py

  • Committer: Tarmac
  • Author(s): Brad Crittenden
  • Date: 2013-08-19 18:23:50 UTC
  • mfrom: (344.4.8 bundle-page)
  • Revision ID: tarmac-20130819182350-4gwm2u2xinrzd6l8
[r=benji][bug=][author=bac] Add support for a bundle description page at an URL like
~abentley/bundles/wiki-bundle/wiki.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2013 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
from charmworld.testing import (
 
5
    factory,
 
6
    TestCase,
 
7
    ViewTestBase,
 
8
)
 
9
from charmworld.views.bundles import (
 
10
    BundleDetail,
 
11
    find_bundle,
 
12
)
 
13
 
 
14
 
 
15
class TestBundleDetail(TestCase):
 
16
 
 
17
    @staticmethod
 
18
    def make_service_list(name):
 
19
        keys = sorted(BundleDetail.service_keys)
 
20
        svcs = {name: dict(zip(keys, range(len(keys))))}
 
21
        svcs[name]['options'] = {}
 
22
        return svcs
 
23
 
 
24
    def test_empty_lists(self):
 
25
        data = factory.get_bundle_data()
 
26
        bd = BundleDetail(data)
 
27
        self.assertEqual({}, bd.data['services'])
 
28
        self.assertEqual({}, bd.data['relations'])
 
29
 
 
30
    def test_flattened_services(self):
 
31
        services = self.make_service_list('svc1')
 
32
        data = factory.get_bundle_data(services=services)
 
33
        bd = BundleDetail(data)
 
34
        self.assertEqual(services, bd.data['services'])
 
35
        expected = [dict(name='svc1',
 
36
                         branch=0,
 
37
                         charm=1,
 
38
                         constraints=2,
 
39
                         num_units=3,
 
40
                         options=[])]
 
41
        self.assertEqual(expected, bd.services_list)
 
42
 
 
43
    def test_flattened_services_with_options(self):
 
44
        services = self.make_service_list('svc1')
 
45
        services['svc1']['options'] = dict(a=1, b=2)
 
46
        data = factory.get_bundle_data(services=services)
 
47
 
 
48
        bd = BundleDetail(data)
 
49
        self.assertEqual(services, bd.data['services'])
 
50
        expected = [dict(name='svc1',
 
51
                         branch=0,
 
52
                         charm=1,
 
53
                         constraints=2,
 
54
                         num_units=3,
 
55
                         options=[
 
56
                             dict(name='a', value=1),
 
57
                             dict(name='b', value=2),
 
58
                         ])
 
59
                    ]
 
60
        self.assertEqual(expected, bd.services_list)
 
61
 
 
62
    def test_flattened_relations(self):
 
63
        rels = [['a', 'b'],
 
64
                ['c', ['d', 'e']]]
 
65
        data = factory.get_bundle_data(relations=rels)
 
66
 
 
67
        bd = BundleDetail(data)
 
68
        self.assertEqual(rels, bd.data['relations'])
 
69
 
 
70
        expected = [dict(left='a',
 
71
                         right='b'),
 
72
                    dict(left='c',
 
73
                         right='d, e'),
 
74
                    ]
 
75
        self.assertEqual(expected, bd.relations_list)
 
76
 
 
77
 
 
78
class TestBundles(ViewTestBase):
 
79
 
 
80
    def test_found_bundle(self):
 
81
        bundle, bundle_data = factory.makeBundle(self.db)
 
82
        request = self.getRequest()
 
83
        request.matchdict = dict(bundle=bundle.name,
 
84
                                 owner=bundle.owner)
 
85
        found = find_bundle(request)
 
86
        self.assertEqual(bundle_data, found)
 
87
 
 
88
    def test_found_bundle_promulgated(self):
 
89
        bundle, bundle_data = factory.makeBundle(self.db, promulgated=True)
 
90
        request = self.getRequest()
 
91
        request.matchdict = dict(bundle=bundle.name)
 
92
        found = find_bundle(request, promulgated=True)
 
93
        self.assertEqual(bundle_data, found)