Beispiel #1
0
def test_page_title():
    request = Mock()
    request.APP = amo.THUNDERBIRD
    title = "Oh hai!"
    s = render('{{ page_title("%s") }}' % title, {"request": request})
    eq_(s, "%s :: Add-ons for Thunderbird" % title)

    # pages without app should show a default
    request.APP = None
    s = render('{{ page_title("%s") }}' % title, {"request": request})
    eq_(s, "%s :: Add-ons" % title)
Beispiel #2
0
def test_breadcrumbs():
    req_noapp = Mock()
    req_noapp.APP = None
    req_app = Mock()
    req_app.APP = amo.FIREFOX

    # default, no app
    s = render("{{ breadcrumbs() }}", {"request": req_noapp})
    doc = PyQuery(s)
    crumbs = doc("li>a")
    eq_(len(crumbs), 1)
    eq_(crumbs.text(), "Add-ons")
    eq_(crumbs.attr("href"), urlresolvers.reverse("home"))

    # default, with app
    s = render("{{ breadcrumbs() }}", {"request": req_app})
    doc = PyQuery(s)
    crumbs = doc("li>a")
    eq_(len(crumbs), 1)
    eq_(crumbs.text(), "Add-ons for Firefox")
    eq_(crumbs.attr("href"), urlresolvers.reverse("home"))

    # no default, no items => no breadcrumbs for you
    s = render("{{ breadcrumbs(add_default=False) }}", {"request": req_app})
    eq_(len(s), 0)

    # no default, some items
    s = render(
        """{{ breadcrumbs([('/foo', 'foo'),
                                  ('/bar', 'bar')],
                                 add_default=False) }}'""",
        {"request": req_app},
    )
    doc = PyQuery(s)
    crumbs = doc("li>a")
    eq_(len(crumbs), 2)
    eq_(crumbs.eq(0).text(), "foo")
    eq_(crumbs.eq(0).attr("href"), "/foo")
    eq_(crumbs.eq(1).text(), "bar")
    eq_(crumbs.eq(1).attr("href"), "/bar")

    # default, some items
    s = render(
        """{{ breadcrumbs([('/foo', 'foo'),
                                  ('/bar', 'bar')]) }}'""",
        {"request": req_app},
    )
    doc = PyQuery(s)
    crumbs = doc("li>a")
    eq_(len(crumbs), 3)
    eq_(crumbs.eq(1).text(), "foo")
    eq_(crumbs.eq(1).attr("href"), "/foo")
    eq_(crumbs.eq(2).text(), "bar")
    eq_(crumbs.eq(2).attr("href"), "/bar")
Beispiel #3
0
def test_breadcrumbs():
    req_noapp = Mock()
    req_noapp.APP = None
    req_app = Mock()
    req_app.APP = amo.FIREFOX

    # default, no app
    s = render('{{ breadcrumbs() }}', {'request': req_noapp})
    doc = PyQuery(s)
    crumbs = doc('li>a')
    eq_(len(crumbs), 1)
    eq_(crumbs.text(), 'Add-ons')
    eq_(crumbs.attr('href'), urlresolvers.reverse('home'))

    # default, with app
    s = render('{{ breadcrumbs() }}', {'request': req_app})
    doc = PyQuery(s)
    crumbs = doc('li>a')
    eq_(len(crumbs), 1)
    eq_(crumbs.text(), 'Add-ons for Firefox')
    eq_(crumbs.attr('href'), urlresolvers.reverse('home'))

    # no default, no items => no breadcrumbs for you
    s = render('{{ breadcrumbs(add_default=False) }}', {'request': req_app})
    eq_(len(s), 0)

    # no default, some items
    s = render("""{{ breadcrumbs([('/foo', 'foo'),
                                  ('/bar', 'bar')],
                                 add_default=False) }}'""",
               {'request': req_app})
    doc = PyQuery(s)
    crumbs = doc('li>a')
    eq_(len(crumbs), 2)
    eq_(crumbs.eq(0).text(), 'foo')
    eq_(crumbs.eq(0).attr('href'), '/foo')
    eq_(crumbs.eq(1).text(), 'bar')
    eq_(crumbs.eq(1).attr('href'), '/bar')

    # default, some items
    s = render("""{{ breadcrumbs([('/foo', 'foo'),
                                  ('/bar', 'bar')]) }}'""",
               {'request': req_app})
    doc = PyQuery(s)
    crumbs = doc('li>a')
    eq_(len(crumbs), 3)
    eq_(crumbs.eq(1).text(), 'foo')
    eq_(crumbs.eq(1).attr('href'), '/foo')
    eq_(crumbs.eq(2).text(), 'bar')
    eq_(crumbs.eq(2).attr('href'), '/bar')
Beispiel #4
0
def test_page_title():
    request = Mock()
    request.APP = amo.THUNDERBIRD
    title = "Oh hai!"
    s = render('{{ page_title("%s") }}' % title, {"request": request})
    eq_(s, "%s :: Add-ons for Thunderbird" % title)

    # pages without app should show a default
    request.APP = None
    s = render('{{ page_title("%s") }}' % title, {"request": request})
    eq_(s, "%s :: Add-ons" % title)

    # Check the dirty unicodes.
    request.APP = amo.FIREFOX
    s = render("{{ page_title(x) }}", {"request": request, "x": encoding.smart_str(u"\u05d0\u05d5\u05e1\u05e3")})
Beispiel #5
0
    def test_addon_sharing(self):
        addon = Addon.objects.get(id=7172)

        jingo.load_helpers()
        # mock helpers
        locale_url = lambda url: url
        locale_url.__name__ = 'locale_url'
        jingo.register.function(locale_url)

        request = Mock()
        request.user = DjangoUser()
        request.APP = amo.FIREFOX
        ctx = {'request': request}

        # disable cake csrf token
        cake_csrf_token = lambda: ''
        cake_csrf_token.__name__ = 'cake_csrf_token'
        jingo.register.function(cake_csrf_token)

        doc = pq(addon_sharing(ctx, addon))
        self.assert_(doc.html())
        self.assertEquals(doc('li').length, len(sharing.SERVICES_LIST))

        # Make sure services are in the right order.
        for i in range(len(sharing.SERVICES_LIST)):
            self.assertEquals(doc('li').eq(i).attr('class'),
                              sharing.SERVICES_LIST[i].shortname)
Beispiel #6
0
    def test_addon_sharing(self):
        addon = Addon.objects.get(id=7172)

        jingo.load_helpers()

        request = Mock()
        request.user = DjangoUser()
        request.APP = amo.FIREFOX
        ctx = {'request': request,
               'APP': request.APP,
               'LANG': translation.get_language()}

        # disable cake csrf token
        cake_csrf_token = lambda: ''
        cake_csrf_token.__name__ = 'cake_csrf_token'
        jingo.register.function(cake_csrf_token)

        doc = pq(addon_sharing(ctx, addon))
        self.assert_(doc.html())
        self.assertEquals(doc('li').length, len(sharing.SERVICES_LIST))

        # Make sure services are in the right order.
        for i in range(len(sharing.SERVICES_LIST)):
            self.assertEquals(doc('li').eq(i).attr('class'),
                              sharing.SERVICES_LIST[i].shortname)
            assert doc('li a').eq(i).attr('target') in ('_blank', '_self'), (
                'Sharing link target must either be blank or self.')
Beispiel #7
0
def test_dev_breadcrumbs():
    request = Mock()
    request.APP = None

    # Default, ``add_default`` argument defaults to False.
    s = render("{{ dev_breadcrumbs() }}", {"request": request})
    doc = pq(s)
    crumbs = doc("li>a")
    eq_(len(crumbs), 2)
    eq_(crumbs.text(), "Developer Hub My Add-ons")
    eq_(crumbs.attr("href"), reverse("devhub.index"))

    s = render("{{ dev_breadcrumbs(add_default=True) }}", {"request": request})
    doc = pq(s)
    crumbs = doc("li>a")
    eq_(len(crumbs), 3)
    eq_(crumbs.text(), "Add-ons Developer Hub My Add-ons")
    eq_(crumbs.eq(1).attr("href"), reverse("devhub.index"))

    # N default, some items.
    s = render(
        """{{ dev_breadcrumbs(items=[('/foo', 'foo'),
                                           ('/bar', 'bar')]) }}'""",
        {"request": request},
    )
    doc = pq(s)
    crumbs = doc("li>a")
    eq_(len(crumbs), 4)
    eq_(crumbs.eq(2).text(), "foo")
    eq_(crumbs.eq(2).attr("href"), "/foo")
    eq_(crumbs.eq(3).text(), "bar")
    eq_(crumbs.eq(3).attr("href"), "/bar")
Beispiel #8
0
 def _test_mobile_persona_ctx(self):
     request = Mock()
     request.APP = amo.FIREFOX
     request.GET = {}
     request.user.is_authenticated.return_value = False
     request.user.mobile_addons = []
     return {'APP': amo.FIREFOX, 'LANG': 'en-US', 'request': request}
Beispiel #9
0
def test_page_title():
    request = Mock()
    request.APP = amo.THUNDERBIRD
    title = 'Oh hai!'
    s = render('{{ page_title("%s") }}' % title, {'request': request})
    eq_(s, '%s :: Add-ons for Thunderbird' % title)

    # pages without app should show a default
    request.APP = None
    s = render('{{ page_title("%s") }}' % title, {'request': request})
    eq_(s, '%s :: Add-ons' % title)

    # Check the dirty unicodes.
    request.APP = amo.FIREFOX
    s = render('{{ page_title(x) }}',
               {'request': request,
                'x': encoding.smart_str(u'\u05d0\u05d5\u05e1\u05e3')})
def test_page_title():
    request = Mock()
    request.APP = amo.ANDROID
    title = 'Oh hai!'
    s = render('{{ page_title("%s") }}' % title, {'request': request})
    assert s == '%s :: Add-ons for Firefox for Android' % title

    # pages without app should show a default
    request.APP = None
    s = render('{{ page_title("%s") }}' % title, {'request': request})
    assert s == '%s :: Add-ons' % title

    # Check the dirty unicodes.
    request.APP = amo.FIREFOX
    s = render('{{ page_title(x) }}',
               {'request': request,
                'x': force_bytes(u'\u05d0\u05d5\u05e1\u05e3')})
Beispiel #11
0
def test_page_title_markup():
    """If the title passed to page_title is a jinja2 Markup object, don't cast
    it back to a string or it'll get double escaped. See issue #1062."""
    request = Mock()
    request.APP = amo.FIREFOX
    # Markup isn't double escaped.
    res = render(
        '{{ page_title("{0}"|fe("It\'s all text")) }}', {'request': request})
    assert res == 'It's all text :: Add-ons for Firefox'
def test_site_nav():
    request = Mock()
    request.APP = amo.FIREFOX
    request.LANG = 'en-US'
    content = jinja_helpers.site_nav({'request': request})
    assert 'id="site-nav"' in content

    assert 'Extensions' in content

    with translation.override('de'):
        request.LANG = 'de'
        content_de = jinja_helpers.site_nav({'request': request})
        assert 'id="site-nav"' in content_de

    assert content_de != content

    assert 'Erweiterungen' in content_de
Beispiel #13
0
    def test_sharing_box(self):
        request = Mock()
        request.user = UserProfile()
        request.APP = amo.FIREFOX
        ctx = {'request': request,
               'APP': request.APP,
               'LANG': translation.get_language()}

        doc = pq(sharing_box(ctx))
        self.assert_(doc.html())
        self.assertEquals(doc('li').length, len(sharing.SERVICES_LIST))

        # Make sure services are in the right order.
        for i in range(len(sharing.SERVICES_LIST)):
            self.assertEquals(doc('li').eq(i).attr('class'),
                              sharing.SERVICES_LIST[i].shortname)
            assert doc('li a').eq(i).attr('target') in ('_blank', '_self'), (
                'Sharing link target must either be blank or self.')
Beispiel #14
0
def test_hub_page_title():
    translation.activate('en-US')
    request = Mock()
    request.APP = None
    addon = Mock()
    addon.name = 'name'
    ctx = {'request': request, 'addon': addon}

    title = 'Oh hai!'
    s1 = render('{{ hub_page_title("%s") }}' % title, ctx)
    s2 = render('{{ mkt_page_title("%s | Developer Hub") }}' % title, ctx)
    eq_(s1, s2)

    s1 = render('{{ hub_page_title() }}', ctx)
    s2 = render('{{ mkt_page_title("Developer Hub") }}', ctx)
    eq_(s1, s2)

    s1 = render('{{ hub_page_title("%s", addon) }}' % title, ctx)
    s2 = render('{{ mkt_page_title("%s | %s") }}' % (title, addon.name), ctx)
    eq_(s1, s2)
def test_dev_page_title():
    translation.activate('en-US')
    request = Mock()
    request.APP = None
    addon = Mock()
    addon.name = 'name'
    ctx = {'request': request, 'addon': addon}

    title = 'Oh hai!'
    s1 = render('{{ dev_page_title("%s") }}' % title, ctx)
    s2 = render('{{ page_title("%s :: Developer Hub") }}' % title, ctx)
    assert s1 == s2

    s1 = render('{{ dev_page_title() }}', ctx)
    s2 = render('{{ page_title("Developer Hub") }}', ctx)
    assert s1 == s2

    s1 = render('{{ dev_page_title("%s", addon) }}' % title, ctx)
    s2 = render('{{ page_title("%s :: %s") }}' % (title, addon.name), ctx)
    assert s1 == s2
Beispiel #16
0
def test_dev_page_title():
    translation.activate("en-US")
    request = Mock()
    request.APP = None
    addon = Mock()
    addon.name = "name"
    ctx = {"request": request, "addon": addon}

    title = "Oh hai!"
    s1 = render('{{ dev_page_title("%s") }}' % title, ctx)
    s2 = render('{{ page_title("%s :: Developer Hub") }}' % title, ctx)
    eq_(s1, s2)

    s1 = render("{{ dev_page_title() }}", ctx)
    s2 = render('{{ page_title("Developer Hub") }}', ctx)
    eq_(s1, s2)

    s1 = render('{{ dev_page_title("%s", addon) }}' % title, ctx)
    s2 = render('{{ page_title("%s :: %s") }}' % (title, addon.name), ctx)
    eq_(s1, s2)
Beispiel #17
0
def test_site_nav():
    r = Mock()
    r.APP = amo.FIREFOX
    assert 'id="site-nav"' in helpers.site_nav({'request': r})
Beispiel #18
0
def test_page_title_unicode():
    t = Translation(localized_string=u'\u30de\u30eb\u30c1\u30d712\u30eb')
    request = Mock()
    request.APP = amo.FIREFOX
    helpers.editor_page_title({'request': request}, title=t)
Beispiel #19
0
 def setUp(self):
     request_mock = Mock()
     request_mock.APP = amo.FIREFOX
     self.ctx = {'request': request_mock, 'amo': amo}
Beispiel #20
0
def test_site_nav():
    amo.tests.default_prefixer()
    r = Mock()
    r.APP = amo.FIREFOX
    assert 'id="site-nav"' in helpers.site_nav({'request': r})
Beispiel #21
0
 def setUp(self):
     super(TestPerformanceNote, self).setUp()
     request_mock = Mock()
     request_mock.APP = amo.FIREFOX
     self.ctx = {'request': request_mock, 'amo': amo}