コード例 #1
0
ファイル: test_views.py プロジェクト: tyler46/affiliates
    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
            ]))
コード例 #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]))
コード例 #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]))
コード例 #4
0
ファイル: test_views.py プロジェクト: Balachan/affiliates
    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]))
コード例 #5
0
ファイル: test_models.py プロジェクト: stevenjenn/affiliates
    def test_banners(self):
        category = CategoryFactory.create()
        image_banner1, image_banner2 = ImageBannerFactory.create_batch(2, category=category)
        text_banner = TextBannerFactory.create(category=category)
        upgrade_banner = FirefoxUpgradeBannerFactory.create(category=category)

        eq_(set(category.banners()),
            set([image_banner1, image_banner2, text_banner, upgrade_banner]))
コード例 #6
0
    def test_banners(self):
        category = CategoryFactory.create()
        image_banner1, image_banner2 = ImageBannerFactory.create_batch(2, category=category)
        text_banner = TextBannerFactory.create(category=category)
        upgrade_banner = FirefoxUpgradeBannerFactory.create(category=category)

        eq_(set(category.banners()),
            set([image_banner1, image_banner2, text_banner, upgrade_banner]))
コード例 #7
0
ファイル: test_views.py プロジェクト: Balachan/affiliates
    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]))
コード例 #8
0
ファイル: test_forms.py プロジェクト: hoosteeno/affiliates
    def test_variation_queryset(self):
        """
        The variation field queryset should be limited to variations
        from the text banner passed in the constructor.
        """
        banner = TextBannerFactory.create()

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

        non_matching_variation = TextBannerVariationFactory.create()
        invalid_form = CustomizeTextBannerForm(banner, {'variation': non_matching_variation.pk})
        ok_(not invalid_form.is_valid())
コード例 #9
0
    def test_variation_queryset(self):
        """
        The variation field queryset should be limited to variations
        from the text banner passed in the constructor.
        """
        banner = TextBannerFactory.create()

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

        non_matching_variation = TextBannerVariationFactory.create()
        invalid_form = CustomizeTextBannerForm(banner, {'variation': non_matching_variation.pk})
        ok_(not invalid_form.is_valid())
コード例 #10
0
ファイル: test_views.py プロジェクト: Balachan/affiliates
    def test_get_context_data_variations(self):
        view = views.CustomizeTextBannerView()
        view.banner = TextBannerFactory.create()

        variation1, variation2 = TextBannerVariationFactory.create_batch(2, banner=view.banner)

        ctx = view.get_context_data(foo='bar', baz=1)
        eq_(ctx['foo'], 'bar')
        eq_(ctx['baz'], 1)

        variations = json.loads(ctx['variations_text_json'])
        eq_(variations, {
            unicode(variation1.pk): variation1.text,
            unicode(variation2.pk): variation2.text,
        })
コード例 #11
0
ファイル: test_views.py プロジェクト: tyler46/affiliates
    def test_get_context_data_variations(self):
        view = views.CustomizeTextBannerView()
        view.banner = TextBannerFactory.create()

        variation1, variation2 = TextBannerVariationFactory.create_batch(
            2, banner=view.banner)

        ctx = view.get_context_data(foo='bar', baz=1)
        eq_(ctx['foo'], 'bar')
        eq_(ctx['baz'], 1)

        variations = json.loads(ctx['variations_text_json'])
        eq_(
            variations, {
                unicode(variation1.pk): variation1.text,
                unicode(variation2.pk): variation2.text,
            })
コード例 #12
0
ファイル: test_models.py プロジェクト: stevenjenn/affiliates
    def test_banners_filters(self):
        category = CategoryFactory.create()
        text_banner = TextBannerFactory.create(category=category, visible=True)
        FirefoxUpgradeBannerFactory.create(category=category, visible=False)

        eq_(category.banners(visible=True), [text_banner])
コード例 #13
0
ファイル: test_views.py プロジェクト: Balachan/affiliates
    def test_dispatch_invisible(self):
        self.view.banner_class = TextBanner
        banner = TextBannerFactory.create(visible=False)

        with self.assertRaises(Http404):
            self.view.dispatch(pk=banner.pk)
コード例 #14
0
ファイル: test_models.py プロジェクト: stevenjenn/affiliates
    def test_links(self):
        banner = TextBannerFactory.create()
        link1, link2 = LinkFactory.create_batch(2, banner_variation__banner=banner)

        eq_(set(banner.links), set([link1, link2]))
コード例 #15
0
ファイル: test_views.py プロジェクト: tyler46/affiliates
    def test_dispatch_invisible(self):
        self.view.banner_class = TextBanner
        banner = TextBannerFactory.create(visible=False)

        with self.assertRaises(Http404):
            self.view.dispatch(pk=banner.pk)
コード例 #16
0
    def test_links(self):
        banner = TextBannerFactory.create()
        link1, link2 = LinkFactory.create_batch(2, banner_variation__banner=banner)

        eq_(set(banner.links), set([link1, link2]))
コード例 #17
0
    def test_banners_filters(self):
        category = CategoryFactory.create()
        text_banner = TextBannerFactory.create(category=category, visible=True)
        FirefoxUpgradeBannerFactory.create(category=category, visible=False)

        eq_(category.banners(visible=True), [text_banner])