本文整理汇总了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)
示例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)