Example #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
            ]))
Example #2
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]))
    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)
Example #4
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)
Example #5
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]))