当前位置: 首页>>代码示例>>Python>>正文


Python Mock.APP方法代码示例

本文整理汇总了Python中mock.Mock.APP方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.APP方法的具体用法?Python Mock.APP怎么用?Python Mock.APP使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mock.Mock的用法示例。


在下文中一共展示了Mock.APP方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_page_title

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import APP [as 别名]
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)
开发者ID:jaliste,项目名称:zamboni,代码行数:13,代码来源:test_helpers.py

示例2: test_breadcrumbs

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import APP [as 别名]
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")
开发者ID:jaliste,项目名称:zamboni,代码行数:56,代码来源:test_helpers.py

示例3: test_breadcrumbs

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import APP [as 别名]
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')
开发者ID:jsocol,项目名称:zamboni,代码行数:52,代码来源:test_helpers.py

示例4: test_page_title

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import APP [as 别名]
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")})
开发者ID:rtilder,项目名称:zamboni,代码行数:17,代码来源:test_helpers.py

示例5: test_addon_sharing

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import APP [as 别名]
    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)
开发者ID:mccammos,项目名称:zamboni,代码行数:29,代码来源:tests.py

示例6: test_addon_sharing

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import APP [as 别名]
    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.')
开发者ID:chowse,项目名称:zamboni,代码行数:29,代码来源:tests.py

示例7: test_dev_breadcrumbs

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import APP [as 别名]
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")
开发者ID:jsocol,项目名称:zamboni,代码行数:34,代码来源:test_helpers.py

示例8: _test_mobile_persona_ctx

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import APP [as 别名]
 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}
开发者ID:peterkinalex,项目名称:olympia,代码行数:9,代码来源:test_helpers.py

示例9: test_page_title

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import APP [as 别名]
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')})
开发者ID:BavarianTomcat,项目名称:zamboni,代码行数:19,代码来源:test_helpers.py

示例10: test_page_title

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import APP [as 别名]
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')})
开发者ID:atiqueahmedziad,项目名称:addons-server,代码行数:19,代码来源:test_helpers.py

示例11: test_page_title_markup

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import APP [as 别名]
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'
开发者ID:peterkinalex,项目名称:olympia,代码行数:11,代码来源:test_helpers.py

示例12: test_site_nav

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import APP [as 别名]
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
开发者ID:atiqueahmedziad,项目名称:addons-server,代码行数:19,代码来源:test_helpers.py

示例13: test_sharing_box

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import APP [as 别名]
    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.')
开发者ID:abhiii5459,项目名称:olympia,代码行数:20,代码来源:tests.py

示例14: test_hub_page_title

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import APP [as 别名]
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)
开发者ID:mnoorenberghe,项目名称:zamboni,代码行数:22,代码来源:test_helpers.py

示例15: test_dev_page_title

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import APP [as 别名]
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
开发者ID:Prashant-Surya,项目名称:addons-server,代码行数:22,代码来源:test_helpers.py


注:本文中的mock.Mock.APP方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。