本文整理汇总了Python中models.BlogWebmention类的典型用法代码示例。如果您正苦于以下问题:Python BlogWebmention类的具体用法?Python BlogWebmention怎么用?Python BlogWebmention使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BlogWebmention类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_domain_not_found
def test_domain_not_found(self):
# no source
msg = 'Could not find FakeSource account for foo.com.'
self.source.key.delete()
self.assert_error(msg)
self.assertEquals(0, BlogWebmention.query().count())
# source without webmention feature
self.source.features = ['listen']
self.source.put()
self.assert_error(msg)
self.assertEquals(0, BlogWebmention.query().count())
# source without domain
self.source.features = ['webmention']
self.source.domains = ['asdfoo.com', 'foo.comedy']
self.source.put()
self.assert_error(msg)
self.assertEquals(0, BlogWebmention.query().count())
# source is disabled
self.source.domains = ['foo.com']
self.source.status = 'disabled'
self.source.put()
self.assert_error(msg)
self.assertEquals(0, BlogWebmention.query().count())
示例2: test_domain_not_found
def test_domain_not_found(self):
self.expect_requests_get('http://foo.com/post/1', status_code=404)
for i in range(4):
self.expect_requests_get('http://foo.com/post/1', '')
self.mox.ReplayAll()
# couldn't fetch source URL
self.source.key.delete()
self.assert_error('Could not fetch source URL http://foo.com/post/1')
self.assertEquals(0, BlogWebmention.query().count())
# no source
msg = 'Could not find FakeSource account for foo.com.'
self.assert_error(msg)
self.assertEquals(0, BlogWebmention.query().count())
# source without webmention feature
self.source.features = ['listen']
self.source.put()
self.assert_error(msg)
self.assertEquals(0, BlogWebmention.query().count())
# source without domain
self.source.features = ['webmention']
self.source.domains = ['asdfoo.com', 'foo.comedy']
self.source.put()
self.assert_error(msg)
self.assertEquals(0, BlogWebmention.query().count())
# source is disabled
self.source.domains = ['foo.com']
self.source.status = 'disabled'
self.source.put()
self.assert_error(msg)
self.assertEquals(0, BlogWebmention.query().count())
示例3: test_rel_canonical_different_domain
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_link_not_found
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)
示例5: test_success
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)
示例6: test_source_missing_mf2
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)
示例7: test_create_comment_exception
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)
示例8: test_create_comment_404s
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)
示例9: test_strip_utm_query_params
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)
示例10: test_create_comment_401_disables_source
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)
示例11: test_repeated
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)
示例12: test_source_link_check_ignores_fragment
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)
示例13: test_target_redirects
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)
示例14: test_create_comment_exception
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)
示例15: test_strip_utm_query_params
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)