示例#1
0
    def test_preview_html_fallback(self):
        """
        If there are no previews available in the current locale, but
        are available in en-US, use them.
        """
        ImageBannerVariationFactory.create(banner=self.banner,
                                           width=125,
                                           height=125,
                                           locale='en-us',
                                           image='uploads/banners/test.png')
        ImageBannerVariationFactory.create(banner=self.banner,
                                           width=300,
                                           height=125,
                                           locale='fr',
                                           image='uploads/banners/test.png')

        self.get_language.return_value = 'fr'
        eq_(self.banner.preview_html('http://example.com', foo='bar'), 'asdf')
        self.render_to_string.assert_called_with(
            'test_template.html', {
                'href': 'http://example.com',
                'foo': 'bar',
                'banner': self.banner,
                'preview_img': '/media/uploads/banners/test.png',
            })
示例#2
0
    def test_variation_queryset(self):
        """
        The variation field queryset should be limited to variations
        from the image banner passed in the constructor.
        """
        banner = ImageBannerFactory.create()

        variation1, variation2 = ImageBannerVariationFactory.create_batch(2, banner=banner)
        ok_(CustomizeImageBannerForm(banner, {'variation': variation1.pk}).is_valid())
        ok_(CustomizeImageBannerForm(banner, {'variation': variation2.pk}).is_valid())

        non_matching_variation = ImageBannerVariationFactory.create()
        invalid_form = CustomizeImageBannerForm(banner, {'variation': non_matching_variation.pk})
        ok_(not invalid_form.is_valid())
示例#3
0
    def test_preview_html_localized_variations(self):
        """
        If 125x125 variations in the correct locale are available, use
        the first one as the preview image.
        """
        ImageBannerVariationFactory.create(banner=self.banner, width=125, height=125, locale='fr',
                                           image='uploads/banners/test.png')

        self.get_language.return_value = 'fr'
        eq_(self.banner.preview_html('http://example.com', foo='bar'), 'asdf')
        self.render_to_string.assert_called_with('test_template.html', {
            'href': 'http://example.com',
            'foo': 'bar',
            'banner': self.banner,
            'preview_img': '/media/uploads/banners/test.png',
        })
示例#4
0
    def test_preview_html_localized_variations(self):
        """
        If 125x125 variations in the correct locale are available, use
        the first one as the preview image.
        """
        ImageBannerVariationFactory.create(banner=self.banner, width=125, height=125, locale='fr',
                                           image='uploads/banners/test.png')

        self.get_language.return_value = 'fr'
        eq_(self.banner.preview_html('http://example.com', foo='bar'), 'asdf')
        self.render_to_string.assert_called_with('test_template.html', {
            'href': 'http://example.com',
            'foo': 'bar',
            'banner': self.banner,
            'preview_img': '/media/uploads/banners/test.png',
        })
示例#5
0
    def test_preview_html_none(self):
        """
        If no variations are available at the right size and locale, and
        no fallbacks are available either, don't include a preview_img.
        """
        ImageBannerVariationFactory.create(banner=self.banner, width=125, height=125,
                                           locale='de', image='uploads/banners/test.png')
        ImageBannerVariationFactory.create(banner=self.banner, width=300, height=125,
                                           locale='fr', image='uploads/banners/test.png')

        self.get_language.return_value = 'fr'
        eq_(self.banner.preview_html('http://example.com', foo='bar'), 'asdf')
        self.render_to_string.assert_called_with('test_template.html', {
            'href': 'http://example.com',
            'foo': 'bar',
            'banner': self.banner,
        })
示例#6
0
    def test_preview_html_none(self):
        """
        If no variations are available at the right size and locale, and
        no fallbacks are available either, don't include a preview_img.
        """
        ImageBannerVariationFactory.create(
            banner=self.banner, width=125, height=125, locale="de", image="uploads/banners/test.png"
        )
        ImageBannerVariationFactory.create(
            banner=self.banner, width=300, height=125, locale="fr", image="uploads/banners/test.png"
        )

        self.get_language.return_value = "fr"
        eq_(self.banner.preview_html("http://example.com", foo="bar"), "asdf")
        self.render_to_string.assert_called_with(
            "test_template.html", {"href": "http://example.com", "foo": "bar", "banner": self.banner}
        )
示例#7
0
    def test_preview_html_none(self):
        """
        If no variations are available at the right size and locale, and
        no fallbacks are available either, don't include a preview_img.
        """
        ImageBannerVariationFactory.create(banner=self.banner, width=125, height=125,
                                           locale='de', image='uploads/banners/test.png')
        ImageBannerVariationFactory.create(banner=self.banner, width=300, height=125,
                                           locale='fr', image='uploads/banners/test.png')

        self.get_language.return_value = 'fr'
        eq_(self.banner.preview_html('http://example.com', foo='bar'), 'asdf')
        self.render_to_string.assert_called_with('test_template.html', {
            'href': 'http://example.com',
            'foo': 'bar',
            'banner': self.banner,
        })
示例#8
0
    def test_preview_html_fallback(self):
        """
        If there are no previews available in the current locale, but
        are available in en-US, use them.
        """
        ImageBannerVariationFactory.create(banner=self.banner, width=125, height=125,
                                           locale='en-us', image='uploads/banners/test.png')
        ImageBannerVariationFactory.create(banner=self.banner, width=300, height=125,
                                           locale='fr', image='uploads/banners/test.png')

        self.get_language.return_value = 'fr'
        eq_(self.banner.preview_html('http://example.com', foo='bar'), 'asdf')
        self.render_to_string.assert_called_with('test_template.html', {
            'href': 'http://example.com',
            'foo': 'bar',
            'banner': self.banner,
            'preview_img': '/media/uploads/banners/test.png',
        })
示例#9
0
    def test_variation_queryset(self):
        """
        The variation field queryset should be limited to variations
        from the image banner passed in the constructor.
        """
        banner = ImageBannerFactory.create()

        variation1, variation2 = ImageBannerVariationFactory.create_batch(2, banner=banner)

        # Mute post_init to avoid ImageField attempting to open a file
        # when the form creates variations as part of validation.
        with mute_signals(post_init):
            ok_(CustomizeImageBannerForm(banner, {'variation': variation1.pk}).is_valid())
            ok_(CustomizeImageBannerForm(banner, {'variation': variation2.pk}).is_valid())

        non_matching_variation = ImageBannerVariationFactory.create()
        with mute_signals(post_init):
            invalid_form = CustomizeImageBannerForm(banner, {'variation': non_matching_variation.pk})
        ok_(not invalid_form.is_valid())
示例#10
0
    def test_preview_html_localized_variations(self):
        """
        If 125x125 variations in the correct locale are available, use
        the first one as the preview image.
        """
        ImageBannerVariationFactory.create(
            banner=self.banner, width=125, height=125, locale="fr", image="uploads/banners/test.png"
        )

        self.get_language.return_value = "fr"
        eq_(self.banner.preview_html("http://example.com", foo="bar"), "asdf")
        self.render_to_string.assert_called_with(
            "test_template.html",
            {
                "href": "http://example.com",
                "foo": "bar",
                "banner": self.banner,
                "preview_img": "/media/uploads/banners/test.png",
            },
        )
示例#11
0
    def test_links(self):
        """
        links should return a queryset of links related to any type of
        banner variation within the category.
        """
        category = CategoryFactory.create()

        # Test against several variations, and multiple variations.
        image_banner_variation1 = ImageBannerVariationFactory.create(banner__category=category)
        image_banner_variation2 = ImageBannerVariationFactory.create(banner__category=category)
        text_banner_variation = TextBannerVariationFactory.create(banner__category=category)
        upgrade_banner_variation = FirefoxUpgradeBannerVariationFactory.create(banner__category=category)

        # Create links from the variations.
        image_link1 = LinkFactory.create(banner_variation=image_banner_variation1)
        image_link2 = LinkFactory.create(banner_variation=image_banner_variation1)
        image_link3 = LinkFactory.create(banner_variation=image_banner_variation2)
        text_link = LinkFactory.create(banner_variation=text_banner_variation)
        upgrade_link = LinkFactory.create(banner_variation=upgrade_banner_variation)

        eq_(set([image_link1, image_link2, image_link3, text_link, upgrade_link]), set(category.links))
示例#12
0
    def test_generate_banner_code(self):
        # This is less a test of initial correctness and more to alert
        # us of unexpected changes to banner code generation.
        variation = ImageBannerVariationFactory(banner__destination='https://www.mozilla.org',
                                                image='uploads/banners/test.png')
        banner = variation.banner

        with self.settings(MEDIA_URL='/media/', SITE_URL='https://example.com'):
            self.assertHTMLEqual(banner.generate_banner_code(variation), """
              <a href="{href}">
                <img src="https://example.com/media/uploads/banners/test.png" alt="">
              </a>
            """)
示例#13
0
    def test_preview_html_fallback(self):
        """
        If there are no previews available in the current locale, but
        are available in en-US, use them.
        """
        ImageBannerVariationFactory.create(
            banner=self.banner, width=125, height=125, locale="en-us", image="uploads/banners/test.png"
        )
        ImageBannerVariationFactory.create(
            banner=self.banner, width=300, height=125, locale="fr", image="uploads/banners/test.png"
        )

        self.get_language.return_value = "fr"
        eq_(self.banner.preview_html("http://example.com", foo="bar"), "asdf")
        self.render_to_string.assert_called_with(
            "test_template.html",
            {
                "href": "http://example.com",
                "foo": "bar",
                "banner": self.banner,
                "preview_img": "/media/uploads/banners/test.png",
            },
        )
示例#14
0
    def test_links(self):
        """
        links should return a queryset of links related to any type of
        banner variation within the category.
        """
        category = CategoryFactory.create()

        # Test against several variations, and multiple variations.
        image_banner_variation1 = ImageBannerVariationFactory.create(banner__category=category)
        image_banner_variation2 = ImageBannerVariationFactory.create(banner__category=category)
        text_banner_variation = TextBannerVariationFactory.create(banner__category=category)
        upgrade_banner_variation = FirefoxUpgradeBannerVariationFactory.create(
            banner__category=category)

        # Create links from the variations.
        image_link1 = LinkFactory.create(banner_variation=image_banner_variation1)
        image_link2 = LinkFactory.create(banner_variation=image_banner_variation1)
        image_link3 = LinkFactory.create(banner_variation=image_banner_variation2)
        text_link = LinkFactory.create(banner_variation=text_banner_variation)
        upgrade_link = LinkFactory.create(banner_variation=upgrade_banner_variation)

        eq_(set(category.links()),
            set([image_link1, image_link2, image_link3, text_link, upgrade_link]))