本文整理汇总了Python中models.Publish类的典型用法代码示例。如果您正苦于以下问题:Python Publish类的具体用法?Python Publish怎么用?Python Publish使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Publish类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_already_published
def test_already_published(self):
"""We shouldn't allow duplicating an existing, *completed* publish."""
page = PublishedPage(id='http://foo.com/bar')
# these are all fine
Publish(parent=page.key, source=self.source.key, status='new').put()
Publish(parent=page.key, source=self.source.key, status='failed').put()
Publish(parent=page.key, source=self.source.key, status='complete',
type='preview').put()
for i in range(2):
self.expect_requests_get('http://foo.com/bar', self.post_html % 'foo')
self.mox.ReplayAll()
# first attempt should work
self.assert_created('foo - http://foo.com/bar')
self.assertEquals(4, Publish.query().count())
self.assertEquals(2, Publish.query(Publish.status == 'complete').count())
# now that there's a complete Publish entity, more attempts should fail
self.assert_error("Sorry, you've already published that page")
# try again to test for a bug we had where a second try would succeed
self.assert_error("Sorry, you've already published that page")
# should still be able to preview though
self.assert_success('preview of foo', preview=True)
示例2: test_no_content
def test_no_content(self):
self.expect_requests_get('http://foo.com/bar',
'<article class="h-entry h-as-note"></article>')
self.mox.ReplayAll()
self.assert_error('or no content was found')
self.assertEquals('failed', Publish.query().get().status)
示例3: test_bad_source
def test_bad_source(self):
# no source
self.source.key.delete()
self.assert_error('Could not find <b>FakeSource</b> account for <b>foo.com</b>.')
# source without publish feature
self.source.features = ['listen']
self.source.put()
msg = 'Publish is not enabled'
self.assert_error(msg)
# status disabled
self.source.features = ['publish']
self.source.status = 'disabled'
self.source.put()
self.assert_error(msg)
# two bad sources with same domain
source_2 = self.source = testutil.FakeSource(id='z', **self.source.to_dict())
source_2.status = 'enabled'
source_2.features = ['listen']
source_2.put()
self.assert_error(msg)
# one bad source, one good source, same domain. should automatically use the
# good source.
source_2.features.append('publish')
source_2.put()
self.expect_requests_get('http://foo.com/bar', self.post_html % 'xyz')
self.mox.ReplayAll()
self.assert_created('xyz - http://foo.com/bar')
self.assertEquals(source_2.key, Publish.query().get().source)
示例4: test_facebook_comment_and_like_disabled
def test_facebook_comment_and_like_disabled(self):
self.source = facebook.FacebookPage(id='789', features=['publish'],
domains=['mr.x'])
self.source.put()
self.expect_requests_get('http://mr.x/like', """
<article class="h-entry">
<a class="u-like-of" href="http://facebook.com/789/posts/456">liked this</a>
<a href="http://localhost/publish/facebook"></a>
</article>""")
self.expect_requests_get('http://mr.x/comment', """
<article class="h-entry">
<a class="u-in-reply-to" href="http://facebook.com/789/posts/456">reply</a>
<a href="http://localhost/publish/facebook"></a>
</article>""")
self.mox.ReplayAll()
self.assert_error('Facebook comments and likes are no longer supported',
source='http://mr.x/like',
target='https://brid.gy/publish/facebook')
self.assertEquals('failed', Publish.query().get().status)
self.assert_error('Facebook comments and likes are no longer supported',
source='http://mr.x/comment',
target='https://brid.gy/publish/facebook',
preview=True)
示例5: test_type_not_implemented
def test_type_not_implemented(self):
self.expect_requests_get('http://foo.com/bar',
'<article class="h-entry h-as-like"></article>')
self.mox.ReplayAll()
# FakeSource.create() raises NotImplementedError on likes
self.assert_error('Cannot publish likes')
self.assertEquals('failed', Publish.query().get().status)
示例6: test_source_with_multiple_domains
def test_source_with_multiple_domains(self):
"""Publish domain is second in source's domains list."""
self.source.domains = ['baj.com', 'foo.com']
self.source.domain_urls = ['http://baj.com/', 'http://foo.com/']
self.source.put()
self.expect_requests_get('http://foo.com/bar', self.post_html % 'xyz')
self.mox.ReplayAll()
self.assert_created('xyz - http://foo.com/bar')
self.assertEquals(self.source.key, Publish.query().get().source)
示例7: test_rsvp_without_in_reply_to
def test_rsvp_without_in_reply_to(self):
self.expect_requests_get('http://foo.com/bar', """
<article class="h-entry">
<p class="e-content">
<data class="p-rsvp" value="yes">I'm in!</data>
</p></article>""")
self.mox.ReplayAll()
self.assert_error("looks like an RSVP, but it's missing an in-reply-to link")
self.assertEquals('failed', Publish.query().get().status)
示例8: test_source_missing_mf2
def test_source_missing_mf2(self):
self.expect_requests_get('http://foo.com/bar', '')
self.mox.ReplayAll()
self.assert_error('No microformats2 data found in http://foo.com/')
self.assertTrue(PublishedPage.get_by_id('http://foo.com/bar'))
publish = Publish.query().get()
self.assertEquals('failed', publish.status)
self.assertEquals(self.source.key, publish.source)
示例9: test_interactive_oauth_decline
def test_interactive_oauth_decline(self):
self.auth_entity = None
resp = self.get_response(interactive=True)
self.assertEquals(302, resp.status_int)
self.assertEquals(
'http://localhost/fake/foo.com#!'
'If you want to publish or preview, please approve the prompt.',
urllib.unquote_plus(resp.headers['Location']))
self.assertIsNone(Publish.query().get())
示例10: test_source_with_multiple_domains
def test_source_with_multiple_domains(self):
"""Publish domain is second in source's domains list."""
self.source.domains = ['baj.com', 'foo.com']
self.source.domain_urls = ['http://baj.com/', 'http://foo.com/']
self.source.put()
self.expect_requests_get('http://foo.com/bar', """
<article class="h-entry"><p class="e-content">xyz</p></article>""")
self.mox.ReplayAll()
self.assert_success('xyz - http://foo.com/bar')
self.assertEquals(self.source.key, Publish.query().get().source)
示例11: test_returned_type_overrides
def test_returned_type_overrides(self):
# FakeSource returns type 'post' when it sees 'rsvp'
self.expect_requests_get('http://foo.com/bar', """
<article class="h-entry h-as-rsvp">
<p class="e-content">
<data class="p-rsvp" value="yes"></data>
<a class="u-in-reply-to" href="http://fa.ke/event"></a>
</p></article>""")
self.mox.ReplayAll()
self.assert_created('')
self.assertEquals('post', Publish.query().get().type)
示例12: test_interactive_no_state
def test_interactive_no_state(self):
"""https://github.com/snarfed/bridgy/issues/449"""
self.oauth_state = None
resp = self.get_response(interactive=True)
self.assertEquals(302, resp.status_int)
self.assertEquals(
'http://localhost/#!'
'If you want to publish or preview, please approve the prompt.',
urllib.unquote_plus(resp.headers['Location']))
self.assertIsNone(Publish.query().get())
示例13: get_or_add_publish_entity
def get_or_add_publish_entity(self, source_url):
"""Creates and stores Publish and (if necessary) PublishedPage entities.
Args:
source_url: string
"""
page = PublishedPage.get_or_insert(source_url)
entity = Publish.query(
Publish.status == 'complete', Publish.type != 'preview',
Publish.source == self.source.key,
ancestor=page.key).get()
if entity is None:
entity = Publish(parent=page.key, source=self.source.key)
if self.PREVIEW:
entity.type = 'preview'
entity.put()
logging.debug('Publish entity: %s', entity.key.urlsafe())
return entity
示例14: test_embedded_type_not_implemented
def test_embedded_type_not_implemented(self):
self.expect_requests_get('http://foo.com/bar', """
<article class="h-entry">
<div class="p-like-of">
foo <a class="u-url" href="http://url">bar</a>
</div>
</article>""")
self.mox.ReplayAll()
# FakeSource.create() raises NotImplementedError on likes
self.assert_error("FakeSource doesn't support type(s) like-of")
self.assertEquals('failed', Publish.query().get().status)
示例15: _check_entity
def _check_entity(self):
self.assertTrue(PublishedPage.get_by_id('http://foo.com/bar'))
publish = Publish.query().get()
self.assertEquals(self.source.key, publish.source)
self.assertEquals('complete', publish.status)
self.assertEquals('post', publish.type)
self.assertEquals('FakeSource post label', publish.type_label)
expected_html = (self.post_html % 'foo') + self.backlink
self.assertEquals(expected_html, publish.html)
self.assertEquals({'id': 'fake id', 'url': 'http://fake/url',
'content': 'foo - http://foo.com/bar'},
publish.published)