~julian-edwards/maas/clickjacking-bug-1298784

« back to all changes in this revision

Viewing changes to src/provisioningserver/import_images/tests/test_product_mapping.py

  • Committer: MaaS Lander
  • Author(s): jtv at canonical
  • Date: 2014-04-28 09:33:58 UTC
  • mfrom: (2291.1.3 split-out-repowriter)
  • Revision ID: maas_lander-20140428093358-2rv11jn3odtikqyh
[r=gmb][bug=][author=jtv] Split the RepoWriter code out of its module, narrowing down its API so we can better understand and work with the code.  Document many unknown things, and rename mysterious variables and functions to reflect improved understanding.  We're hoping to make substantial changes to how we use the data coming out of Simplestreams, so we must understand what it is and how it works.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
from maastesting.factory import factory
18
18
from maastesting.testcase import MAASTestCase
19
 
from provisioningserver.import_images.product_mapping import ProductMapping
 
19
from provisioningserver.import_images.boot_image_mapping import (
 
20
    BootImageMapping,
 
21
    )
 
22
from provisioningserver.import_images.product_mapping import (
 
23
    map_products,
 
24
    ProductMapping,
 
25
    )
20
26
from provisioningserver.import_images.testing.factory import (
21
27
    make_boot_resource,
 
28
    make_image_spec,
 
29
    set_resource,
22
30
    )
23
31
 
24
32
 
123
131
        product_dict.add(resource, subarch)
124
132
        resource['other_item'] = factory.make_name('other')
125
133
        self.assertEqual([subarch], product_dict.get(resource))
 
134
 
 
135
 
 
136
class TestMapProducts(MAASTestCase):
 
137
    """Tests for `map_products`."""
 
138
 
 
139
    def test_maps_empty_dict_to_empty_dict(self):
 
140
        empty_boot_image_dict = BootImageMapping()
 
141
        self.assertEqual({}, map_products(empty_boot_image_dict).mapping)
 
142
 
 
143
    def test_maps_boot_resource_by_content_id_product_name_and_version(self):
 
144
        image = make_image_spec()
 
145
        resource = make_boot_resource()
 
146
        boot_dict = set_resource(resource=resource.copy(), image_spec=image)
 
147
        self.assertEqual(
 
148
            {
 
149
                (
 
150
                    resource['content_id'],
 
151
                    resource['product_name'],
 
152
                    resource['version_name'],
 
153
                ): [image.subarch],
 
154
            },
 
155
            map_products(boot_dict).mapping)
 
156
 
 
157
    def test_concatenates_similar_resources(self):
 
158
        image1 = make_image_spec()
 
159
        image2 = make_image_spec()
 
160
        resource = make_boot_resource()
 
161
        boot_dict = BootImageMapping()
 
162
        # Create two images in boot_dict, both containing the same resource.
 
163
        for image in [image1, image2]:
 
164
            set_resource(
 
165
                boot_dict=boot_dict, resource=resource.copy(),
 
166
                image_spec=image)
 
167
 
 
168
        products_mapping = map_products(boot_dict)
 
169
        key = (
 
170
            resource['content_id'],
 
171
            resource['product_name'],
 
172
            resource['version_name'],
 
173
            )
 
174
        self.assertEqual([key], products_mapping.mapping.keys())
 
175
        self.assertItemsEqual(
 
176
            [image1.subarch, image2.subarch],
 
177
            products_mapping.get(resource))