示例#1
0
    def test_get_background_images_with_additional_imgs(self):
        self.file_obj = os.path.join(
            settings.ROOT,
            'src/olympia/devhub/tests/addons/static_theme_tiled.zip')
        data = {
            'images': {
                'theme_frame':
                'empty.png',
                'additional_backgrounds': [
                    'transparent.gif', 'missing_&_ignored.png',
                    'weta_for_tiling.png'
                ]
            }
        }

        images = utils.get_background_images(self.file_obj, data)
        assert len(images.items()) == 3
        assert len(images['empty.png']) == 332
        assert len(images['transparent.gif']) == 42
        assert len(images['weta_for_tiling.png']) == 93371

        # And again but only with the header image
        images = utils.get_background_images(self.file_obj,
                                             data,
                                             header_only=True)
        assert len(images.items()) == 1
        assert len(images['empty.png']) == 332
示例#2
0
    def test_get_background_deprecated(self):
        data = {'images': {'headerURL': 'weta.png'}}

        images = utils.get_background_images(self.file_obj_dep, data)
        assert 'weta.png' in images
        assert len(images.items()) == 1
        assert len(images['weta.png']) == 126447
示例#3
0
    def test_get_background_images(self):
        data = {'images': {'theme_frame': 'weta.png'}}

        images = utils.get_background_images(self.file_obj, data)
        assert 'weta.png' in images
        assert len(images.items()) == 1
        assert len(images['weta.png']) == 126447
    def test_get_background_images(self):
        data = {'images': {'headerURL': 'weta.png'}}

        images = utils.get_background_images(self.file_obj, data)
        assert 'weta.png' in images
        assert len(images.items()) == 1
        assert len(images['weta.png']) == 126447
示例#5
0
def _build_static_theme_preview_context(theme_manifest, file_):
    # First build the context shared by both the main preview and the thumb
    context = {'amo': amo}
    context.update(
        dict(
            process_color_value(prop, color)
            for prop, color in theme_manifest.get('colors', {}).items()))
    images_dict = theme_manifest.get('images', {})
    header_url = images_dict.get('headerURL',
                                 images_dict.get('theme_frame', ''))
    file_ext = os.path.splitext(header_url)[1]
    backgrounds = get_background_images(file_, theme_manifest)
    header_src, header_width, header_height = encode_header(
        backgrounds.get(header_url), file_ext)
    context.update(header_src=header_src,
                   header_src_height=header_height,
                   header_width=header_width)
    # Limit the srcs rendered to 15 to ameliorate DOSing somewhat.
    # https://bugzilla.mozilla.org/show_bug.cgi?id=1435191 for background.
    additional_srcs = images_dict.get('additional_backgrounds', [])[:15]
    additional_alignments = (theme_manifest.get('properties', {}).get(
        'additional_backgrounds_alignment', []))
    additional_tiling = (theme_manifest.get('properties', {}).get(
        'additional_backgrounds_tiling', []))
    additional_backgrounds = [
        AdditionalBackground(path, alignment, tiling, backgrounds.get(path))
        for (path, alignment, tiling) in izip_longest(
            additional_srcs, additional_alignments, additional_tiling)
        if path is not None
    ]
    context.update(additional_backgrounds=additional_backgrounds)
    return context
示例#6
0
 def get_background_images_encoded(self, header_only=False):
     file_obj = self.file
     return {
         name: force_str(b64encode(background))
         for name, background in utils.get_background_images(
             file_obj, theme_data=None, header_only=header_only).items()
     }
示例#7
0
def _build_static_theme_preview_context(theme_manifest, file_):
    # First build the context shared by both the main preview and the thumb
    context = {'amo': amo}
    context.update(dict(
        process_color_value(prop, color)
        for prop, color in theme_manifest.get('colors', {}).items()))
    images_dict = theme_manifest.get('images', {})
    header_url = images_dict.get(
        'theme_frame', images_dict.get('headerURL', ''))
    file_ext = os.path.splitext(header_url)[1]
    backgrounds = get_background_images(file_, theme_manifest)
    header_src, header_width, header_height = encode_header(
        backgrounds.get(header_url), file_ext)
    context.update(
        header_src=header_src,
        header_src_height=header_height,
        header_width=header_width)
    # Limit the srcs rendered to 15 to ameliorate DOSing somewhat.
    # https://bugzilla.mozilla.org/show_bug.cgi?id=1435191 for background.
    additional_srcs = images_dict.get('additional_backgrounds', [])[:15]
    additional_alignments = (theme_manifest.get('properties', {})
                             .get('additional_backgrounds_alignment', []))
    additional_tiling = (theme_manifest.get('properties', {})
                         .get('additional_backgrounds_tiling', []))
    additional_backgrounds = [
        AdditionalBackground(path, alignment, tiling, backgrounds.get(path))
        for (path, alignment, tiling) in six.moves.zip_longest(
            additional_srcs, additional_alignments, additional_tiling)
        if path is not None]
    context.update(additional_backgrounds=additional_backgrounds)
    return context
示例#8
0
    def test_get_background_images_not_image(self):
        self.file_obj = os.path.join(
            settings.ROOT,
            'src/olympia/devhub/tests/addons/static_theme_non_image.zip')
        data = {'images': {'theme_frame': 'not_an_image.js'}}

        images = utils.get_background_images(self.file_obj, data)
        assert not images
示例#9
0
 def get_background_images_encoded(self, header_only=False):
     if not self.has_files:
         return {}
     file_obj = self.all_files[0]
     return {
         name: force_text(b64encode(background))
         for name, background in utils.get_background_images(
             file_obj, theme_data=None, header_only=header_only).items()}
    def test_get_background_images_not_image(self):
        self.file_obj = os.path.join(
            settings.ROOT,
            'src/olympia/devhub/tests/addons/static_theme_non_image.zip')
        data = {'images': {'headerURL': 'not_an_image.js'}}

        images = utils.get_background_images(self.file_obj, data)
        assert not images
示例#11
0
 def get_background_images_encoded(self, header_only=False):
     if not self.has_files:
         return {}
     file_obj = self.all_files[0]
     return {
         name: b64encode(background)
         for name, background in utils.get_background_images(
             file_obj, theme_data=None, header_only=header_only).items()}
示例#12
0
    def test_get_background_images_with_additional_imgs(self):
        self.file_obj = os.path.join(
            settings.ROOT,
            'src/olympia/devhub/tests/addons/static_theme_tiled.zip')
        data = {'images': {
            'theme_frame': 'empty.png',
            'additional_backgrounds': [
                'transparent.gif', 'missing_&_ignored.png',
                'weta_for_tiling.png']
        }}

        images = utils.get_background_images(self.file_obj, data)
        assert len(images.items()) == 3
        assert len(images['empty.png']) == 332
        assert len(images['transparent.gif']) == 42
        assert len(images['weta_for_tiling.png']) == 93371

        # And again but only with the header image
        images = utils.get_background_images(
            self.file_obj, data, header_only=True)
        assert len(images.items()) == 1
        assert len(images['empty.png']) == 332
示例#13
0
    def test_get_background_images_missing(self):
        data = {'images': {'theme_frame': 'missing_file.png'}}

        images = utils.get_background_images(self.file_obj, data)
        assert not images
示例#14
0
 def test_get_background_images_no_theme_data_provided(self):
     images = utils.get_background_images(self.file_obj, theme_data=None)
     assert 'weta.png' in images
     assert len(images.items()) == 1
     assert len(images['weta.png']) == 126447
    def test_get_background_images_missing(self):
        data = {'images': {'headerURL': 'missing_file.png'}}

        images = utils.get_background_images(self.file_obj, data)
        assert not images
 def test_get_background_images_no_theme_data_provided(self):
     images = utils.get_background_images(self.file_obj, theme_data=None)
     assert 'weta.png' in images
     assert len(images.items()) == 1
     assert len(images['weta.png']) == 126447