def test_contains_ignores_similar_items(self): product_dict = ProductMapping() resource = make_boot_resource() subarch = factory.make_name("subarch") product_dict.add(resource.copy(), subarch) resource["product_name"] = factory.make_name("other") self.assertFalse(product_dict.contains(resource))
def test_inserts_generic_link_for_generic_kflavor(self): product_mapping = ProductMapping() product = self.make_product(subarch='ga-16.04', kflavor='generic') product_mapping.add(product, 'ga-16.04') repo_writer = download_resources.RepoWriter(None, None, product_mapping) self.patch(download_resources, 'products_exdata').return_value = product # Prevent MAAS from trying to actually write the file. mock_insert_file = self.patch(download_resources, 'insert_file') mock_link_resources = self.patch(download_resources, 'link_resources') # We only need to provide the product as the other fields are only used # when writing the actual files to disk. repo_writer.insert_item(product, None, None, None, None) # None is used for the store and the content source as we're not # writing anything to disk. self.assertThat( mock_insert_file, MockCalledOnceWith(None, os.path.basename(product['path']), product['sha256'], {'sha256': product['sha256']}, product['size'], None)) # links are mocked out by the mock_insert_file above. self.assertThat( mock_link_resources, MockCalledOnceWith(snapshot_path=None, links=mock.ANY, osystem=product['os'], arch=product['arch'], release=product['release'], label=product['label'], subarches={'ga-16.04', 'generic'}, bootloader_type=None))
def test_contains_ignores_extraneous_keys(self): product_dict = ProductMapping() resource = make_boot_resource() subarch = factory.make_name("subarch") product_dict.add(resource.copy(), subarch) resource["other_item"] = factory.make_name("other") self.assertTrue(product_dict.contains(resource))
def test_get_ignores_extraneous_keys(self): product_dict = ProductMapping() resource = make_boot_resource() subarch = factory.make_name("subarch") product_dict.add(resource, subarch) resource["other_item"] = factory.make_name("other") self.assertEqual([subarch], product_dict.get(resource))
def test_get_fails_for_unstored_item(self): product_dict = ProductMapping() resource = make_boot_resource() subarch = factory.make_name("subarch") product_dict.add(resource.copy(), subarch) resource["content_id"] = factory.make_name("other") self.assertRaises(KeyError, product_dict.get, resource)
def test_only_creates_links_for_its_own_subarch(self): # Regression test for LP:1656425 product_name = factory.make_name("product_name") version_name = factory.make_name("version_name") product_mapping = ProductMapping() for subarch in [ "hwe-p", "hwe-q", "hwe-r", "hwe-s", "hwe-t", "hwe-u", "hwe-v", "hwe-w", "ga-16.04", ]: product = self.make_product( product_name=product_name, version_name=version_name, subarch=subarch, ) product_mapping.add(product, subarch) repo_writer = download_resources.RepoWriter(None, None, product_mapping) self.patch(download_resources, "products_exdata").return_value = product # Prevent MAAS from trying to actually write the file. mock_insert_file = self.patch(download_resources, "insert_file") mock_link_resources = self.patch(download_resources, "link_resources") # We only need to provide the product as the other fields are only used # when writing the actual files to disk. repo_writer.insert_item(product, None, None, None, None) # None is used for the store and the content source as we're not # writing anything to disk. self.assertThat( mock_insert_file, MockCalledOnceWith( None, os.path.basename(product["path"]), product["sha256"], {"sha256": product["sha256"]}, product["size"], None, ), ) # links are mocked out by the mock_insert_file above. self.assertThat( mock_link_resources, MockCalledOnceWith( snapshot_path=None, links=mock.ANY, osystem=product["os"], arch=product["arch"], release=product["release"], label=product["label"], subarches={"ga-16.04"}, bootloader_type=None, ), )
def test_add_creates_subarches_list_if_needed(self): product_dict = ProductMapping() resource = make_boot_resource() subarch = factory.make_name("subarch") product_dict.add(resource, subarch) self.assertEqual( {product_dict.make_key(resource): [subarch]}, product_dict.mapping )
def test_add_appends_to_existing_list(self): product_dict = ProductMapping() resource = make_boot_resource() subarches = [factory.make_name("subarch") for _ in range(2)] for subarch in subarches: product_dict.add(resource, subarch) self.assertEqual( {product_dict.make_key(resource): subarches}, product_dict.mapping )
def test_inserts_generic_link_for_generic_kflavor_old_hwe_style_ga(self): # Regression test for LP:1768323 product_mapping = ProductMapping() product = self.make_product( subarch="hwe-p", kflavor="generic", release="precise" ) product_mapping.add(product, "hwe-p") repo_writer = download_resources.RepoWriter( None, None, product_mapping ) self.patch( download_resources, "products_exdata" ).return_value = product # Prevent MAAS from trying to actually write the file. mock_insert_file = self.patch(download_resources, "insert_file") mock_link_resources = self.patch(download_resources, "link_resources") # We only need to provide the product as the other fields are only used # when writing the actual files to disk. repo_writer.insert_item(product, None, None, None, None) # None is used for the store and the content source as we're not # writing anything to disk. self.assertThat( mock_insert_file, MockCalledOnceWith( None, os.path.basename(product["path"]), product["sha256"], {"sha256": product["sha256"]}, product["size"], None, ), ) # links are mocked out by the mock_insert_file above. self.assertThat( mock_link_resources, MockCalledOnceWith( snapshot_path=None, links=mock.ANY, osystem=product["os"], arch=product["arch"], release=product["release"], label=product["label"], subarches={"hwe-p", "generic"}, bootloader_type=None, ), )
def test_inserts_archive(self): product_mapping = ProductMapping() subarch = factory.make_name("subarch") product = self.make_product(ftype="archive.tar.xz", subarch=subarch) product_mapping.add(product, subarch) repo_writer = download_resources.RepoWriter( None, None, product_mapping ) self.patch( download_resources, "products_exdata" ).return_value = product # Prevent MAAS from trying to actually write the file. mock_extract_archive_tar = self.patch( download_resources, "extract_archive_tar" ) mock_link_resources = self.patch(download_resources, "link_resources") # We only need to provide the product as the other fields are only used # when writing the actual files to disk. repo_writer.insert_item(product, None, None, None, None) # None is used for the store and the content source as we're not # writing anything to disk. self.assertThat( mock_extract_archive_tar, MockCalledOnceWith( None, os.path.basename(product["path"]), product["sha256"], {"sha256": product["sha256"]}, product["size"], None, ), ) # links are mocked out by the mock_insert_file above. self.assertThat( mock_link_resources, MockCalledOnceWith( snapshot_path=None, links=mock.ANY, osystem=product["os"], arch=product["arch"], release=product["release"], label=product["label"], subarches={subarch}, bootloader_type=None, ), )
def test_only_creates_links_for_its_own_subarch(self): # Regression test for LP:1656425 product_name = factory.make_name('product_name') version_name = factory.make_name('version_name') product_mapping = ProductMapping() for subarch in [ 'hwe-p', 'hwe-q', 'hwe-r', 'hwe-s', 'hwe-t', 'hwe-u', 'hwe-v', 'hwe-w', 'ga-16.04' ]: product = self.make_product(product_name=product_name, version_name=version_name, subarch=subarch) product_mapping.add(product, subarch) repo_writer = download_resources.RepoWriter(None, None, product_mapping) self.patch(download_resources, 'products_exdata').return_value = product # Prevent MAAS from trying to actually write the file. mock_insert_file = self.patch(download_resources, 'insert_file') mock_link_resources = self.patch(download_resources, 'link_resources') # We only need to provide the product as the other fields are only used # when writing the actual files to disk. repo_writer.insert_item(product, None, None, None, None) # None is used for the store and the content source as we're not # writing anything to disk. self.assertThat( mock_insert_file, MockCalledOnceWith(None, os.path.basename(product['path']), product['sha256'], {'sha256': product['sha256']}, product['size'], None)) # links are mocked out by the mock_insert_file above. self.assertThat( mock_link_resources, MockCalledOnceWith(snapshot_path=None, links=mock.ANY, osystem=product['os'], arch=product['arch'], release=product['release'], label=product['label'], subarches={'ga-16.04'}, bootloader_type=None))
def test_contains_returns_true_for_stored_item(self): product_dict = ProductMapping() resource = make_boot_resource() subarch = factory.make_name("subarch") product_dict.add(resource, subarch) self.assertTrue(product_dict.contains(resource))
def test_get_returns_stored_item(self): product_dict = ProductMapping() resource = make_boot_resource() subarch = factory.make_name("subarch") product_dict.add(resource, subarch) self.assertEqual([subarch], product_dict.get(resource))