Пример #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
            ]))
Пример #2
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]))
Пример #3
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]))
Пример #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]))
Пример #5
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]))
Пример #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
    def test_get_queryset(self):
        """
        The list returned by get_queryset should contain both image
        banners and text banners.
        """
        category = CategoryFactory.create()
        image_banner1, image_banner2 = ImageBannerFactory.create_batch(2, category=category)
        text_banner1, text_banner2 = TextBannerFactory.create_batch(2, category=category)
        self.view.category = category

        eq_(set(self.view.get_queryset()),
            set([image_banner1, image_banner2, text_banner1, text_banner2]))
Пример #8
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]))
Пример #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
    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())
Пример #11
0
    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
    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,
            })
Пример #13
0
    def test_basic(self):
        category = CategoryFactory.create()
        banner1, banner2 = TextBannerFactory.create_batch(2, category=category)
        link1, link2 = LinkFactory.create_batch(2, banner_variation__banner=banner1)
        link3, link4 = LinkFactory.create_batch(2, banner_variation__banner=banner2)

        # Set datapoint totals.
        self._datapoint(link1, 4)
        self._datapoint(link1, 4)
        self._datapoint(link2, 3)
        self._datapoint(link2, 3)
        self._datapoint(link3, 2)
        self._datapoint(link3, 2)
        self._datapoint(link4, 1)
        self._datapoint(link4, 1)

        # Assert that data hasn't been denormalized yet.
        eq_(link1.link_clicks, 0)
        eq_(link2.link_clicks, 0)
        eq_(link3.link_clicks, 0)
        eq_(link4.link_clicks, 0)
        eq_(banner1.link_clicks, 0)
        eq_(banner2.link_clicks, 0)
        eq_(category.link_clicks, 0)

        self.command.handle()

        # Re-fetch data now that is has updated
        category = Category.objects.get(pk=category.pk)
        banner1, banner2 = TextBanner.objects.order_by('id')
        link1, link2, link3, link4 = Link.objects.order_by('id')

        # Assert that counts are now denormalized.
        eq_(link1.link_clicks, 8)
        eq_(link2.link_clicks, 6)
        eq_(link3.link_clicks, 4)
        eq_(link4.link_clicks, 2)
        eq_(banner1.link_clicks, 14)
        eq_(banner2.link_clicks, 6)
        eq_(category.link_clicks, 20)
Пример #14
0
    def test_basic(self):
        category = CategoryFactory.create()
        banner1, banner2 = TextBannerFactory.create_batch(2, category=category)
        link1, link2 = LinkFactory.create_batch(2, banner_variation__banner=banner1)
        link3, link4 = LinkFactory.create_batch(2, banner_variation__banner=banner2)

        # Set datapoint totals.
        self._datapoint(link1, 4)
        self._datapoint(link1, 4)
        self._datapoint(link2, 3)
        self._datapoint(link2, 3)
        self._datapoint(link3, 2)
        self._datapoint(link3, 2)
        self._datapoint(link4, 1)
        self._datapoint(link4, 1)

        # Assert that data hasn't been denormalized yet.
        eq_(link1.link_clicks, 0)
        eq_(link2.link_clicks, 0)
        eq_(link3.link_clicks, 0)
        eq_(link4.link_clicks, 0)
        eq_(banner1.link_clicks, 0)
        eq_(banner2.link_clicks, 0)
        eq_(category.link_clicks, 0)

        self.command.handle()

        # Re-fetch data now that is has updated
        category = Category.objects.get(pk=category.pk)
        banner1, banner2 = TextBanner.objects.order_by('id')
        link1, link2, link3, link4 = Link.objects.order_by('id')

        # Assert that counts are now denormalized.
        eq_(link1.link_clicks, 8)
        eq_(link2.link_clicks, 6)
        eq_(link3.link_clicks, 4)
        eq_(link4.link_clicks, 2)
        eq_(banner1.link_clicks, 14)
        eq_(banner2.link_clicks, 6)
        eq_(category.link_clicks, 20)
Пример #15
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])
Пример #16
0
    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)
Пример #17
0
 def test_generate_banner_code(self):
     banner = TextBannerFactory()
     variation = TextBannerVariationFactory(text='Test')
     eq_(banner.generate_banner_code(variation=variation), '<a href="{href}">Test</a>')
Пример #18
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]))
Пример #19
0
    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)
Пример #20
0
 def test_generate_banner_code(self):
     banner = TextBannerFactory()
     variation = TextBannerVariationFactory(text='Test')
     eq_(banner.generate_banner_code(variation=variation),
         '<a href="{href}">Test</a>')
Пример #21
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])
Пример #22
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]))