def test_image_artifact_hash(self): """ Test that the correct number of image artifacts are produced """ with open(self.get_fixture_path("valid_tile.json"), 'r') as f: fixture = json.load(f) tile_1 = fixture["STAR/en-US"][0] tile_2 = copy.deepcopy(tile_1) tile_2['title'] = 'Some Other Title' tile_3 = copy.deepcopy(tile_1) tile_3['title'] = 'Yet Another Title' tiles = {'STAR/en-US': [tile_1, tile_2, tile_3]} data = ingest_links(tiles, self.channels[0].id) artifacts = generate_artifacts(data, self.channels[0].name, True) # even if there are 3 tiles, there should only be 2 images image_count = 0 for a in artifacts: mime = a.get('mime') if mime and mime == 'image/png': image_count += 1 assert_equal(2, image_count)
def test_generate_artifacts(self): """ Tests that the correct number of artifacts are generated """ with open(self.get_fixture_path("tiles_suggested.json"), 'r') as f: fixture = json.load(f) tile = fixture["STAR/en-US"][4] data = ingest_links({"STAR/en-US": [tile]}, self.channels[0].id) artifacts = generate_artifacts(data, self.channels[0].name, True) # tile index, v2, v3 and 2 image files are generated assert_equal(6, len(artifacts)) data = ingest_links({ "STAR/en-US": [tile], "CA/en-US": [tile] }, self.channels[0].id) artifacts = generate_artifacts(data, self.channels[0].name, True) # includes two more file: the locale data payload for each version assert_equal(8, len(artifacts))
def test_image_content(self): with open(self.get_fixture_path("valid_tile.json"), 'r') as f: tiles = json.load(f) data = ingest_links(tiles, self.channels[0].id) artifacts = generate_artifacts(data, self.channels[0].name, True) found_image = False for file in artifacts: if "mime" in file: found_image = True assert_equal(file["mime"], magic.from_buffer(file["data"], mime=True)) assert_true(found_image)
def test_generate_artifacts_tile_count(self): """ Tests that the correct number of tiles are produced """ with open(self.get_fixture_path('mozilla-tiles.fennec.sg.json'), 'r') as f: tiles = json.load(f) data = ingest_links(tiles, self.channels[0].id) artifacts = generate_artifacts(data, self.channels[0].name, True) assertions_run = False for a in artifacts: m = DESKTOP_LOCALE_DISTRO_PATTERN.match(a['key']) if m: country_locale = m.groups()[0] distro_data = json.loads(a['data']) assert_equal(len(tiles[country_locale]) - 1, len(distro_data['directory'])) assert_equal(1, len(distro_data['suggested'])) assertions_run = True assert(assertions_run)