Ejemplo n.º 1
0
    def test_sort_order(self):
        # sortorder--not db row order--sets the order of the
        # suggestions.
        rules = [
            TriggerRuleFactory(
                sortorder=10, locales=['en-US'], slug='a', is_enabled=True
            ),
            TriggerRuleFactory(
                sortorder=1, locales=['en-US'], slug='b', is_enabled=True
            ),
        ]
        resp = self.post_feedback(
            locale='en-US',
            data={'happy': 0, 'description': u'rc4 is awesome'}
        )

        links = resp.context['suggestions']

        # The disabled one won't match, but the other two will match in the
        # sort order.
        assert len(links) == 2

        assert (
            links[0].url == build_redirect_url(format_redirect(rules[1].slug))
        )
        assert (
            links[1].url == build_redirect_url(format_redirect(rules[0].slug))
        )
Ejemplo n.º 2
0
    def test_sort_order(self):
        # sortorder--not db row order--sets the order of the
        # suggestions.
        rules = [
            TriggerRuleFactory(
                sortorder=10, locales=['en-US'], slug='a', is_enabled=True
            ),
            TriggerRuleFactory(
                sortorder=1, locales=['en-US'], slug='b', is_enabled=True
            ),
        ]
        resp = self.post_feedback(
            locale='en-US',
            data={'happy': 0, 'description': u'rc4 is awesome'}
        )

        links = resp.jinja_context['suggestions']

        # The disabled one won't match, but the other two will match in the
        # sort order.
        assert len(links) == 2

        assert (
            links[0].url == build_redirect_url(format_redirect(rules[1].slug))
        )
        assert (
            links[1].url == build_redirect_url(format_redirect(rules[0].slug))
        )
Ejemplo n.º 3
0
    def test_with_multiple_rules(self):
        rules = [
            TriggerRuleFactory(
                sortorder=0, locales=['en-US'], slug='a', is_enabled=False
            ),
            TriggerRuleFactory(
                sortorder=1, locales=['en-US'], slug='b', is_enabled=True
            ),
            TriggerRuleFactory(
                sortorder=2, locales=['en-US'], slug='c', is_enabled=True
            ),
        ]
        resp = self.post_feedback(
            locale='en-US',
            data={'happy': 0, 'description': u'rc4 is awesome'}
        )

        links = resp.jinja_context['suggestions']

        # The disabled one won't match, but the other two will match in the
        # sort order.
        assert len(links) == 2
        assert (
            links[0].url == build_redirect_url(format_redirect(rules[1].slug))
        )
        assert (
            links[1].url == build_redirect_url(format_redirect(rules[2].slug))
        )
Ejemplo n.º 4
0
    def test_redirector(self):
        tr = TriggerRuleFactory(url=u'http://example.com/', is_enabled=True)
        resp = self.post_feedback(
            locale='en-US',
            data={'happy': 0, 'description': u'rc4 is awesome'}
        )

        links = resp.context['suggestions']

        assert len(links) == 1
        assert links[0].url == build_redirect_url(format_redirect(tr.slug))

        resp = self.client.get(links[0].url)
        assert resp.status_code == 302
        assert resp.url == 'http://example.com/'
Ejemplo n.º 5
0
    def test_enabled_rule_matches_and_returns_correct_data(self):
        tr = TriggerRuleFactory(locales=['en-US'], is_enabled=True)
        resp = self.post_feedback(
            locale='en-US',
            data={'happy': 0, 'description': u'rc4 is awesome'}
        )

        links = resp.context['suggestions']

        assert len(links) == 1
        assert links[0].provider == PROVIDER
        assert links[0].provider_version == PROVIDER_VERSION
        assert links[0].summary == tr.title
        assert links[0].description == tr.description
        assert links[0].url == build_redirect_url(format_redirect(tr.slug))
Ejemplo n.º 6
0
    def test_redirector(self):
        tr = TriggerRuleFactory(url=u'http://example.com/', is_enabled=True)
        resp = self.post_feedback(
            locale='en-US',
            data={'happy': 0, 'description': u'rc4 is awesome'}
        )

        links = resp.jinja_context['suggestions']

        assert len(links) == 1
        assert links[0].url == build_redirect_url(format_redirect(tr.slug))

        resp = self.client.get(links[0].url)
        assert resp.status_code == 302
        assert resp.url == 'http://example.com/'
Ejemplo n.º 7
0
    def test_enabled_rule_matches_and_returns_correct_data(self):
        tr = TriggerRuleFactory(locales=['en-US'], is_enabled=True)
        resp = self.post_feedback(
            locale='en-US',
            data={'happy': 0, 'description': u'rc4 is awesome'}
        )

        links = resp.jinja_context['suggestions']

        assert len(links) == 1
        assert links[0].provider == PROVIDER
        assert links[0].provider_version == PROVIDER_VERSION
        assert links[0].summary == tr.title
        assert links[0].description == tr.description
        assert links[0].url == build_redirect_url(format_redirect(tr.slug))