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


Python FakeSource.get_by_id方法代码示例

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


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

示例1: test_registration_callback

# 需要导入模块: from testutil import FakeSource [as 别名]
# 或者: from testutil.FakeSource import get_by_id [as 别名]
    def test_registration_callback(self):
        """Run through an authorization back and forth and make sure that
    the external callback makes it all the way through.
    """
        encoded_state = urllib.quote_plus(
            '{"callback":"http://withknown.com/bridgy_callback",' '"feature":"listen","operation":"add"}'
        )

        application = webapp2.WSGIApplication(
            [("/fakesource/start", testutil.FakeStartHandler), ("/fakesource/add", testutil.FakeAddHandler)]
        )

        self.expect_webmention_requests_get(
            u"http://fakeuser.com/", response='<html><link rel="webmention" href="/webmention"></html>', verify=False
        )

        self.mox.ReplayAll()

        resp = application.get_response(
            "/fakesource/start",
            method="POST",
            body=urllib.urlencode({"feature": "listen", "callback": "http://withknown.com/bridgy_callback"}),
        )

        expected_auth_url = "http://fake/auth/url?" + urllib.urlencode(
            {"redirect_uri": "http://localhost/fakesource/add?state=" + encoded_state}
        )

        self.assert_equals(302, resp.status_code)
        self.assert_equals(expected_auth_url, resp.headers["location"])

        resp = application.get_response(
            "/fakesource/add?state=" + encoded_state + "&oauth_token=fake-token&oauth_token_secret=fake-secret"
        )

        self.assert_equals(302, resp.status_code)
        self.assert_equals(
            "http://withknown.com/bridgy_callback?"
            + urllib.urlencode(
                [
                    ("result", "success"),
                    ("key", ndb.Key("FakeSource", "0123456789").urlsafe()),
                    ("user", "http://localhost/fake/0123456789"),
                ]
            ),
            resp.headers["location"],
        )
        self.assertEquals(
            'logins="/fake/0123456789?Fake+User"; expires=2001-12-31 00:00:00; Path=/', resp.headers["Set-Cookie"]
        )

        source = FakeSource.get_by_id("0123456789")
        self.assertTrue(source)
        self.assert_equals("Fake User", source.name)
        self.assert_equals(["listen"], source.features)
开发者ID:singpolyma,项目名称:bridgy,代码行数:57,代码来源:test_util.py

示例2: test_registration_callback

# 需要导入模块: from testutil import FakeSource [as 别名]
# 或者: from testutil.FakeSource import get_by_id [as 别名]
  def test_registration_callback(self):
    """Run through an authorization back and forth and make sure that
    the external callback makes it all the way through.
    """
    encoded_state = urllib.quote_plus(
      '{"callback":"http://withknown.com/bridgy_callback",'
      '"feature":"listen","operation":"add"}')

    application = webapp2.WSGIApplication([
      ('/fakesource/start', testutil.FakeStartHandler),
      ('/fakesource/add', testutil.FakeAddHandler),
    ])

    self.expect_requests_get(
      u'http://fakeuser.com/',
      response='<html><link rel="webmention" href="/webmention"></html>',
      verify=False)

    self.mox.ReplayAll()

    resp = application.get_response(
      '/fakesource/start', method='POST', body=urllib.urlencode({
        'feature': 'listen',
        'callback': 'http://withknown.com/bridgy_callback',
      }))

    expected_auth_url = 'http://fake/auth/url?' + urllib.urlencode({
      'redirect_uri': 'http://localhost/fakesource/add?state='
      + encoded_state,
    })

    self.assert_equals(302, resp.status_code)
    self.assert_equals(expected_auth_url, resp.headers['location'])

    resp = application.get_response(
      '/fakesource/add?state=' + encoded_state +
      '&oauth_token=fake-token&oauth_token_secret=fake-secret')

    self.assert_equals(302, resp.status_code)
    self.assert_equals(
      'http://withknown.com/bridgy_callback?' + urllib.urlencode([
        ('result', 'success'),
        ('key', ndb.Key('FakeSource', '0123456789').urlsafe()),
        ('user', 'http://localhost/fake/0123456789')]),
      resp.headers['location'])

    source = FakeSource.get_by_id('0123456789')
    self.assertTrue(source)
    self.assert_equals('Fake User', source.name)
    self.assert_equals(['listen'], source.features)
开发者ID:uniteddiversity,项目名称:bridgy,代码行数:52,代码来源:test_util.py


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