Example #1
0
    def test_create_link(self):
        """
        create_link should create a Link object using this banner's
        description and generated code.
        """
        banner = Banner(destination="https://www.mozilla.org")
        banner.generate_banner_code = Mock(
            return_value="""
            <a href="{href}">Link!</a>
        """
        )
        banner.get_banner_type = Mock(return_value="generic_banner")
        user = UserFactory.create()
        variation = TextBannerVariationFactory.create()

        with patch.object(Link, "get_referral_url") as get_referral_url:
            get_referral_url.return_value = "asdf"
            link = banner.create_link(user, variation)

        ok_(isinstance(link, Link))
        eq_(link.user, user)
        eq_(link.banner_variation, variation)
        self.assertHTMLEqual(
            link.html,
            """
            <a href="asdf">Link!</a>
        """,
        )
        banner.generate_banner_code.assert_called_with(variation)
Example #2
0
    def test_create_link(self):
        """
        create_link should create a Link object using this banner's
        description and generated code.
        """
        banner = Banner(destination='https://www.mozilla.org')
        banner.generate_banner_code = Mock(return_value="""
            <a href="{href}">Link!</a>
        """)
        banner.get_banner_type = Mock(return_value='generic_banner')
        user = UserFactory.create()
        variation = TextBannerVariationFactory.create()

        with patch.object(Link, 'get_referral_url') as get_referral_url:
            get_referral_url.return_value = 'asdf'
            link = banner.create_link(user, variation)

        ok_(isinstance(link, Link))
        eq_(link.user, user)
        eq_(link.banner_variation, variation)
        self.assertHTMLEqual(
            link.html, """
            <a href="asdf">Link!</a>
        """)
        banner.generate_banner_code.assert_called_with(variation)
Example #3
0
    def test_links_filters(self):
        category = CategoryFactory.create()
        user = UserFactory.create()

        text_banner_variation = TextBannerVariationFactory.create(banner__category=category)
        upgrade_banner_variation = FirefoxUpgradeBannerVariationFactory.create(
            banner__category=category)

        text_link = LinkFactory.create(banner_variation=text_banner_variation, user=user)
        LinkFactory.create(banner_variation=upgrade_banner_variation)

        eq_(list(category.links(user=user)), [text_link])
Example #4
0
    def test_links_filters(self):
        category = CategoryFactory.create()
        user = UserFactory.create()

        text_banner_variation = TextBannerVariationFactory.create(banner__category=category)
        upgrade_banner_variation = FirefoxUpgradeBannerVariationFactory.create(
            banner__category=category)

        text_link = LinkFactory.create(banner_variation=text_banner_variation, user=user)
        LinkFactory.create(banner_variation=upgrade_banner_variation)

        eq_(list(category.links(user=user)), [text_link])
Example #5
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())
Example #6
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())
    def test_creation_milestone_close_to_next_milestone(self):
        """
        If the user is within 1 link of the next milestone, return
        yesterday's date with the close_to_milestone message.
        """
        variation = TextBannerVariationFactory.create()
        LinkFactory.create_batch(2, banner_variation=variation, user=self.user)
        self.display.surrounding_milestones.return_value = (None, 3)

        with patch('affiliates.base.milestones.date_yesterday') as date_yesterday:
            milestone = self.display.creation_milestone(TextBanner, self.messages)
            eq_(milestone, (date_yesterday.return_value, 'close_to_milestone_3'))

            self.display.surrounding_milestones.assert_called_with(
                2, self.display.creation_milestones)
    def test_creation_milestone_no_previous_links_created(self):
        """
        If there is no previous milestone, but the user has created at
        least one link (which is normally impossible, as the default
        milestones start at 1), show when their last link was created.
        """
        variation = TextBannerVariationFactory.create()
        links = LinkFactory.create_batch(2, banner_variation=variation, user=self.user)
        links[0].created = aware_datetime(2014, 1, 1, 5)
        links[1].created = aware_datetime(2014, 1, 2, 8)
        for link in links:
            link.save()

        self.display.surrounding_milestones.return_value = (None, 5)

        milestone = self.display.creation_milestone(TextBanner, self.messages)
        eq_(milestone, (aware_date(2014, 1, 2), 'link_created'))
    def test_creation_milestone_no_next_milestone(self):
        """
        If there is no next milestone, show the date of their last
        milestone.
        """
        variation = TextBannerVariationFactory.create()
        links = LinkFactory.create_batch(4, banner_variation=variation, user=self.user)
        links[0].created = aware_datetime(2014, 1, 1, 5)
        links[1].created = aware_datetime(2014, 1, 1, 8)
        links[2].created = aware_datetime(2014, 1, 2, 5)  # Winner!
        links[3].created = aware_datetime(2014, 1, 3, 5)
        for link in links:
            link.save()

        self.display.surrounding_milestones.return_value = (3, None)

        milestone = self.display.creation_milestone(TextBanner, self.messages)
        eq_(milestone, (aware_date(2014, 1, 2), 'achieved_milestone_3'))
Example #10
0
    def test_creation_milestone_close_to_next_milestone(self):
        """
        If the user is within 1 link of the next milestone, return
        yesterday's date with the close_to_milestone message.
        """
        variation = TextBannerVariationFactory.create()
        LinkFactory.create_batch(2, banner_variation=variation, user=self.user)
        self.display.surrounding_milestones.return_value = (None, 3)

        with patch(
                'affiliates.base.milestones.date_yesterday') as date_yesterday:
            milestone = self.display.creation_milestone(
                TextBanner, self.messages)
            eq_(milestone,
                (date_yesterday.return_value, 'close_to_milestone_3'))

            self.display.surrounding_milestones.assert_called_with(
                2, self.display.creation_milestones)
Example #11
0
    def test_creation_milestone_no_previous_links_created(self):
        """
        If there is no previous milestone, but the user has created at
        least one link (which is normally impossible, as the default
        milestones start at 1), show when their last link was created.
        """
        variation = TextBannerVariationFactory.create()
        links = LinkFactory.create_batch(2,
                                         banner_variation=variation,
                                         user=self.user)
        links[0].created = aware_datetime(2014, 1, 1, 5)
        links[1].created = aware_datetime(2014, 1, 2, 8)
        for link in links:
            link.save()

        self.display.surrounding_milestones.return_value = (None, 5)

        milestone = self.display.creation_milestone(TextBanner, self.messages)
        eq_(milestone, (aware_date(2014, 1, 2), 'link_created'))
Example #12
0
    def test_creation_milestone_no_next_milestone(self):
        """
        If there is no next milestone, show the date of their last
        milestone.
        """
        variation = TextBannerVariationFactory.create()
        links = LinkFactory.create_batch(4,
                                         banner_variation=variation,
                                         user=self.user)
        links[0].created = aware_datetime(2014, 1, 1, 5)
        links[1].created = aware_datetime(2014, 1, 1, 8)
        links[2].created = aware_datetime(2014, 1, 2, 5)  # Winner!
        links[3].created = aware_datetime(2014, 1, 3, 5)
        for link in links:
            link.save()

        self.display.surrounding_milestones.return_value = (3, None)

        milestone = self.display.creation_milestone(TextBanner, self.messages)
        eq_(milestone, (aware_date(2014, 1, 2), 'achieved_milestone_3'))
Example #13
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))
Example #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]))