Beispiel #1
0
    def test_get_queryset(self):
        """
        The list returned by get_queryset should contain image banners,
        text banners, and upgrade banners.
        """
        category = CategoryFactory.create()
        image_banner1, image_banner2 = ImageBannerFactory.create_batch(
            2, category=category, visible=True)
        text_banner1, text_banner2 = TextBannerFactory.create_batch(
            2, category=category, visible=True)
        upgrade_banner1, upgrade_banner2 = FirefoxUpgradeBannerFactory.create_batch(
            2, category=category, visible=True)
        self.view.category = category

        # Create banners with visible=False that should not show up.
        ImageBannerFactory.create(category=category, visible=False)
        TextBannerFactory.create(category=category, visible=False)
        FirefoxUpgradeBannerFactory.create(category=category, visible=False)

        eq_(
            set(self.view.get_queryset()),
            set([
                image_banner1, image_banner2, text_banner1, text_banner2,
                upgrade_banner1, upgrade_banner2
            ]))
Beispiel #2
0
    def test_get_queryset_visible_banners(self):
        """
        get_queryset should return a queryset with only categories that
        have visible banners.
        """
        parent = CategoryFactory.create()
        category1, category2, category3, category4 = CategoryFactory.create_batch(
            4, parent=parent)

        # category1 has a visible ImageBanner
        ImageBannerFactory.create(category=category1, visible=True)
        TextBannerFactory.create(category=category1, visible=False)
        FirefoxUpgradeBannerFactory.create(category=category1, visible=False)

        # category2 has a visible TextBanner
        ImageBannerFactory.create(category=category2, visible=False)
        TextBannerFactory.create(category=category2, visible=True)
        FirefoxUpgradeBannerFactory.create(category=category2, visible=False)

        # category3 has a visible FirefoxUpgradeBanner
        ImageBannerFactory.create(category=category3, visible=False)
        TextBannerFactory.create(category=category3, visible=False)
        FirefoxUpgradeBannerFactory.create(category=category3, visible=True)

        # category4 has no visible banners
        ImageBannerFactory.create(category=category4, visible=False)
        TextBannerFactory.create(category=category4, visible=False)
        FirefoxUpgradeBannerFactory.create(category=category4, visible=False)

        eq_(set(self.view.get_queryset()),
            set([category1, category2, category3]))
Beispiel #3
0
    def test_queryset_visible_banners(self):
        parent = CategoryFactory.create()
        categories = CategoryFactory.create_batch(5, parent=parent)
        category1, category2, category3, category4, category5 = categories

        # category1 has a visible ImageBanner
        ImageBannerFactory.create(category=category1, visible=True)
        TextBannerFactory.create(category=category1, visible=False)
        FirefoxUpgradeBannerFactory.create(category=category1, visible=False)

        # category2 has a visible TextBanner
        ImageBannerFactory.create(category=category2, visible=False)
        TextBannerFactory.create(category=category2, visible=True)
        FirefoxUpgradeBannerFactory.create(category=category2, visible=False)

        # category3 has a visible FirefoxUpgradeBanner
        ImageBannerFactory.create(category=category3, visible=False)
        TextBannerFactory.create(category=category3, visible=False)
        FirefoxUpgradeBannerFactory.create(category=category3, visible=True)

        # category4 has no visible banners
        ImageBannerFactory.create(category=category4, visible=False)
        TextBannerFactory.create(category=category4, visible=False)
        FirefoxUpgradeBannerFactory.create(category=category4, visible=False)

        # category5 has no banners.
        eq_(set(Category.objects.with_visible_banners()), set([category1, category2, category3]))
Beispiel #4
0
    def test_get_queryset_visible_banners(self):
        """
        get_queryset should return a queryset with only categories that
        have visible banners.
        """
        parent = CategoryFactory.create()
        category1, category2, category3, category4 = CategoryFactory.create_batch(4, parent=parent)

        # category1 has a visible ImageBanner
        ImageBannerFactory.create(category=category1, visible=True)
        TextBannerFactory.create(category=category1, visible=False)
        FirefoxUpgradeBannerFactory.create(category=category1, visible=False)

        # category2 has a visible TextBanner
        ImageBannerFactory.create(category=category2, visible=False)
        TextBannerFactory.create(category=category2, visible=True)
        FirefoxUpgradeBannerFactory.create(category=category2, visible=False)

        # category3 has a visible FirefoxUpgradeBanner
        ImageBannerFactory.create(category=category3, visible=False)
        TextBannerFactory.create(category=category3, visible=False)
        FirefoxUpgradeBannerFactory.create(category=category3, visible=True)

        # category4 has no visible banners
        ImageBannerFactory.create(category=category4, visible=False)
        TextBannerFactory.create(category=category4, visible=False)
        FirefoxUpgradeBannerFactory.create(category=category4, visible=False)

        eq_(set(self.view.get_queryset()), set([category1, category2, category3]))
Beispiel #5
0
    def setUp(self):
        self.banner = ImageBannerFactory.create()
        self.banner.preview_template = 'test_template.html'

        patcher = patch('affiliates.banners.models.render_to_string')
        self.addCleanup(patcher.stop)
        self.render_to_string = patcher.start()
        self.render_to_string.return_value = 'asdf'

        patcher = patch('affiliates.banners.models.translation.get_language')
        self.addCleanup(patcher.stop)
        self.get_language = patcher.start()
Beispiel #6
0
    def setUp(self):
        self.banner = ImageBannerFactory.create()
        self.banner.preview_template = 'test_template.html'

        patcher = patch('affiliates.banners.models.render_to_string')
        self.addCleanup(patcher.stop)
        self.render_to_string = patcher.start()
        self.render_to_string.return_value = 'asdf'

        patcher = patch('affiliates.banners.models.translation.get_language')
        self.addCleanup(patcher.stop)
        self.get_language = patcher.start()
Beispiel #7
0
    def test_get_queryset(self):
        """
        The list returned by get_queryset should contain image banners,
        text banners, and upgrade banners.
        """
        category = CategoryFactory.create()
        image_banner1, image_banner2 = ImageBannerFactory.create_batch(
            2, category=category, visible=True)
        text_banner1, text_banner2 = TextBannerFactory.create_batch(
            2, category=category, visible=True)
        upgrade_banner1, upgrade_banner2 = FirefoxUpgradeBannerFactory.create_batch(
            2, category=category, visible=True)
        self.view.category = category

        # Create banners with visible=False that should not show up.
        ImageBannerFactory.create(category=category, visible=False)
        TextBannerFactory.create(category=category, visible=False)
        FirefoxUpgradeBannerFactory.create(category=category, visible=False)

        eq_(set(self.view.get_queryset()),
            set([image_banner1, image_banner2, text_banner1, text_banner2, upgrade_banner1,
                 upgrade_banner2]))
Beispiel #8
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())
Beispiel #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())