本文整理汇总了Python中models.BlogWebmention.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python BlogWebmention.get_by_id方法的具体用法?Python BlogWebmention.get_by_id怎么用?Python BlogWebmention.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.BlogWebmention
的用法示例。
在下文中一共展示了BlogWebmention.get_by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_success
# 需要导入模块: from models import BlogWebmention [as 别名]
# 或者: from models.BlogWebmention import get_by_id [as 别名]
def test_success(self):
html = """
<article class="h-entry">
<p class="p-author">my name</p>
<p class="e-content">
i hereby reply
<a class="u-in-reply-to" href="http://foo.com/post/1"></a>
</p></article>"""
self.expect_requests_get('http://bar.com/reply', html)
testutil.FakeSource.create_comment(
'http://foo.com/post/1', 'my name', 'http://foo.com/',
'i hereby reply\n<a class="u-in-reply-to" href="http://foo.com/post/1"></a>'
' <br /> <a href="http://bar.com/reply">via bar.com</a>'
).AndReturn({'id': 'fake id'})
self.mox.ReplayAll()
resp = self.get_response()
self.assertEquals(200, resp.status_int, resp.body)
self.assertEquals({'id': 'fake id'}, json.loads(resp.body))
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals(self.source.key, bw.source)
self.assertEquals('complete', bw.status)
self.assertEquals('comment', bw.type)
self.assertEquals(html, bw.html)
self.assertEquals({'id': 'fake id'}, bw.published)
示例2: test_source_link_not_found
# 需要导入模块: from models import BlogWebmention [as 别名]
# 或者: from models.BlogWebmention import get_by_id [as 别名]
def test_source_link_not_found(self):
html = '<article class="h-entry"></article>'
self.expect_requests_get('http://bar.com/reply', html)
self.mox.ReplayAll()
self.assert_error('Could not find target URL')
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('failed', bw.status)
示例3: test_rel_canonical_different_domain
# 需要导入模块: from models import BlogWebmention [as 别名]
# 或者: from models.BlogWebmention import get_by_id [as 别名]
def test_rel_canonical_different_domain(self):
self.expect_requests_get('http://foo.zz/post/1', """
<head>
<link href='http://foo.com/post/1' rel='canonical'/>
</head>
foo bar""")
html = """
<article class="h-entry"><p class="e-content">
<a href="http://bar.com/mention">this post</a>
i hereby <a href="http://foo.zz/post/1">mention</a>
</p></article>"""
self.expect_requests_get('http://bar.com/mention', html)
testutil.FakeSource.create_comment(
'http://foo.zz/post/1', 'foo.zz', 'http://foo.zz/',
'mentioned this in <a href="http://bar.com/mention">bar.com/mention</a>. <br /> <a href="http://bar.com/mention">via bar.com</a>')
self.mox.ReplayAll()
resp = self.get_response('http://bar.com/mention', 'http://foo.zz/post/1')
self.assertEquals(200, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id('http://bar.com/mention http://foo.zz/post/1')
self.assertEquals('complete', bw.status)
self.assertEquals(html, bw.html)
示例4: test_source_missing_mf2
# 需要导入模块: from models import BlogWebmention [as 别名]
# 或者: from models.BlogWebmention import get_by_id [as 别名]
def test_source_missing_mf2(self):
html = 'no microformats here, run along'
self.expect_requests_get('http://bar.com/reply', html)
self.mox.ReplayAll()
self.assert_error('No microformats2 data found')
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('failed', bw.status)
self.assertEquals(html, bw.html)
示例5: test_create_comment_404s
# 需要导入模块: from models import BlogWebmention [as 别名]
# 或者: from models.BlogWebmention import get_by_id [as 别名]
def test_create_comment_404s(self):
self.expect_mention().AndRaise(exc.HTTPNotFound('gone baby gone'))
self.mox.ReplayAll()
self.assert_error('gone baby gone', status=404)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('failed', bw.status)
self.assertEquals(self.mention_html, bw.html)
示例6: test_create_comment_exception
# 需要导入模块: from models import BlogWebmention [as 别名]
# 或者: from models.BlogWebmention import get_by_id [as 别名]
def test_create_comment_exception(self):
self.expect_mention().AndRaise(exc.HTTPPaymentRequired())
self.mox.ReplayAll()
resp = self.get_response()
self.assertEquals(402, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('failed', bw.status)
self.assertEquals(self.mention_html, bw.html)
示例7: test_strip_utm_query_params
# 需要导入模块: from models import BlogWebmention [as 别名]
# 或者: from models.BlogWebmention import get_by_id [as 别名]
def test_strip_utm_query_params(self):
"""utm_* query params should be stripped from target URLs."""
self.expect_mention()
self.mox.ReplayAll()
resp = self.get_response(target=urllib.quote(
'http://foo.com/post/1?utm_source=x&utm_medium=y'))
self.assertEquals(200, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('complete', bw.status)
示例8: test_create_comment_401_disables_source
# 需要导入模块: from models import BlogWebmention [as 别名]
# 或者: from models.BlogWebmention import get_by_id [as 别名]
def test_create_comment_401_disables_source(self):
self.expect_mention().AndRaise(exc.HTTPUnauthorized('no way'))
self.mox.ReplayAll()
self.assert_error('no way', status=401)
source = self.source.key.get()
self.assertEquals('disabled', source.status)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('failed', bw.status)
self.assertEquals(self.mention_html, bw.html)
示例9: test_repeated
# 需要导入模块: from models import BlogWebmention [as 别名]
# 或者: from models.BlogWebmention import get_by_id [as 别名]
def test_repeated(self):
# 1) first a failure
self.expect_requests_get('http://bar.com/reply', '')
# 2) should allow retrying, this one will succeed
self.expect_requests_get('http://bar.com/reply', """
<article class="h-entry">
<a class="u-url" href="http://bar.com/reply"></a>
<a class="u-repost-of" href="http://foo.com/post/1"></a>
</article>""")
testutil.FakeSource.create_comment(
'http://foo.com/post/1', 'foo.com', 'http://foo.com/',
'reposted this. <br /> <a href="http://bar.com/reply">via bar.com</a>')
# 3) after success, another is a noop and returns 200
# TODO: check for "updates not supported" message
self.mox.ReplayAll()
# now the webmention requests. 1) failure
self.assert_error('No microformats2 data found')
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('failed', bw.status)
# 2) success
resp = self.get_response()
self.assertEquals(200, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('complete', bw.status)
self.assertEquals('repost', bw.type)
# 3) noop repeated success
# source without webmention feature
resp = self.get_response()
self.assertEquals(200, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('complete', bw.status)
示例10: test_source_link_check_ignores_fragment
# 需要导入模块: from models import BlogWebmention [as 别名]
# 或者: from models.BlogWebmention import get_by_id [as 别名]
def test_source_link_check_ignores_fragment(self):
html = """\
<article class="h-entry"><p class="e-content">
<span class="p-name">my post</span>
<a href="http://foo.com/post/1"></a>
</p></article>"""
self.expect_requests_get('http://bar.com/reply', html)
testutil.FakeSource.create_comment(
'http://foo.com/post/1', 'foo.com', 'http://foo.com/',
'mentioned this in <a href="http://bar.com/reply">my post</a>. <br /> <a href="http://bar.com/reply">via bar.com</a>')
self.mox.ReplayAll()
resp = self.get_response()
self.assertEquals(200, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('complete', bw.status)
示例11: test_target_redirects
# 需要导入模块: from models import BlogWebmention [as 别名]
# 或者: from models.BlogWebmention import get_by_id [as 别名]
def test_target_redirects(self):
html = """\
<article class="h-entry"><p class="e-content">
http://second/
</p></article>"""
redirects = ['http://second/', 'http://foo.com/final']
self.expect_requests_head('http://first/', redirected_url=redirects)
self.expect_requests_get('http://bar.com/reply', html)
testutil.FakeSource.create_comment(
'http://foo.com/final', 'foo.com', 'http://foo.com/', mox.IgnoreArg())
self.mox.ReplayAll()
resp = self.get_response(target='http://first/')
self.assertEquals(200, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/final')
self.assertEquals('complete', bw.status)
self.assertEquals(['http://first/', 'http://second/'], bw.redirected_target_urls)
示例12: test_create_comment_exception
# 需要导入模块: from models import BlogWebmention [as 别名]
# 或者: from models.BlogWebmention import get_by_id [as 别名]
def test_create_comment_exception(self):
html = """\
<article class="h-entry"><p class="e-content">
<span class="p-name">my post</span>
http://foo.com/post/1
</p></article>"""
self.expect_requests_get('http://bar.com/reply', html)
testutil.FakeSource.create_comment(
'http://foo.com/post/1', 'foo.com', 'http://foo.com/', mox.IgnoreArg()
).AndRaise(exc.HTTPPaymentRequired())
self.mox.ReplayAll()
resp = self.get_response()
self.assertEquals(402, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('failed', bw.status)
self.assertEquals(html, bw.html)
示例13: test_strip_utm_query_params
# 需要导入模块: from models import BlogWebmention [as 别名]
# 或者: from models.BlogWebmention import get_by_id [as 别名]
def test_strip_utm_query_params(self):
"""utm_* query params should be stripped from target URLs."""
html = """\
<article class="h-entry"><p class="e-content">
<span class="p-name">my post</span>
http://foo.com/post/1
</p></article>"""
self.expect_requests_get('http://bar.com/reply', html)
testutil.FakeSource.create_comment(
'http://foo.com/post/1', 'foo.com', 'http://foo.com/',
'mentioned this in <a href="http://bar.com/reply">my post</a>. <br /> <a href="http://bar.com/reply">via bar.com</a>')
self.mox.ReplayAll()
resp = self.get_response(target=urllib.quote(
'http://foo.com/post/1?utm_source=x&utm_medium=y'))
self.assertEquals(200, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('complete', bw.status)
示例14: test_unicode_in_target_and_source_urls
# 需要导入模块: from models import BlogWebmention [as 别名]
# 或者: from models.BlogWebmention import get_by_id [as 别名]
def test_unicode_in_target_and_source_urls(self):
"""Unicode chars in target and source URLs should work."""
# note the … and ✁ chars
target = u'http://foo.com/2014/11/23/england-german…iendly-wembley'
source = u'http://bar.com/✁/1'
html = u"""\
<meta charset="utf-8">
<article class="h-entry"><p class="e-content">
<span class="p-name">my post</span>
%s
</p></article>""" % target
self.expect_requests_get(source, html)
comment = u'mentioned this in <a href="%s">my post</a>. <br /> <a href="%s">via bar.com</a>' % (source, source)
testutil.FakeSource.create_comment(target, 'foo.com', 'http://foo.com/', comment)
self.mox.ReplayAll()
resp = self.get_response(source=source, target=target)
self.assertEquals(200, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id(' '.join((source, target)))
self.assertEquals('complete', bw.status)
示例15: test_reply_outside_e_content
# 需要导入模块: from models import BlogWebmention [as 别名]
# 或者: from models.BlogWebmention import get_by_id [as 别名]
def test_reply_outside_e_content(self):
html = """
<article class="h-entry">
<p class="p-author">my name</p>
<p class="p-in-reply-to h-cite"><a href="http://foo.com/post/1"></a></p>
<div class="e-content">
i hereby reply
</div></article>"""
self.expect_requests_get('http://bar.com/reply', html)
testutil.FakeSource.create_comment(
'http://foo.com/post/1', 'my name', 'http://foo.com/',
'i hereby reply <br /> <a href="http://bar.com/reply">via bar.com</a>'
).AndReturn({'id': 'fake id'})
self.mox.ReplayAll()
resp = self.get_response()
self.assertEquals(200, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('complete', bw.status)
self.assertEquals({'id': 'fake id'}, bw.published)