本文整理汇总了Python中tumblr.Tumblr.create_comment方法的典型用法代码示例。如果您正苦于以下问题:Python Tumblr.create_comment方法的具体用法?Python Tumblr.create_comment怎么用?Python Tumblr.create_comment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tumblr.Tumblr
的用法示例。
在下文中一共展示了Tumblr.create_comment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TumblrTest
# 需要导入模块: from tumblr import Tumblr [as 别名]
# 或者: from tumblr.Tumblr import create_comment [as 别名]
class TumblrTest(testutil.HandlerTest):
def setUp(self):
super(TumblrTest, self).setUp()
self.auth_entity = TumblrAuth(id='name', user_json=json.dumps({
'user': {'blogs': [{'url': 'other'},
{'url': 'http://primary/', 'primary': True}]}}))
self.tumblr = Tumblr(id='my id', disqus_shortname='my-disqus-name')
appengine_config.DISQUS_API_KEY = 'my key'
appengine_config.DISQUS_API_SECRET = 'my secret'
appengine_config.DISQUS_ACCESS_TOKEN = 'my token'
def disqus_params(self, params):
params.update({
'api_key': 'my key',
'api_secret': 'my secret',
'access_token': 'my token',
})
return params
def expect_thread_details(self, resp=None, **kwargs):
if resp is None:
resp = {'response': {'id': '87654'}}
self.expect_requests_get(
tumblr.DISQUS_API_THREAD_DETAILS_URL,
json.dumps(resp),
params=self.disqus_params({'forum': 'my-disqus-name',
'thread':'link:http://primary/post/123999'}),
**kwargs)
def test_new(self):
t = Tumblr.new(self.handler, auth_entity=self.auth_entity)
self.assertEquals(self.auth_entity.key, t.auth_entity)
self.assertEquals('name', t.name)
self.assertEquals(['http://primary/'], t.domain_urls)
self.assertEquals(['primary'], t.domains)
self.assertEquals('http://api.tumblr.com/v2/blog/primary/avatar/512', t.picture)
def test_new_no_primary_blog(self):
self.auth_entity.user_json = json.dumps({'user': {'blogs': [{'url': 'foo'}]}})
self.assertIsNone(Tumblr.new(self.handler, auth_entity=self.auth_entity))
self.assertIn('Tumblr blog not found', next(iter(self.handler.messages)))
def test_new_with_blog_name(self):
self.auth_entity.user_json = json.dumps({
'user': {'blogs': [{'url': 'foo'},
{'name': 'bar', 'url': 'baz'},
{'name': 'biff', 'url': 'http://boff/'},
]}})
got = Tumblr.new(self.handler, auth_entity=self.auth_entity, blog_name='biff')
self.assertEquals(['http://boff/'], got.domain_urls)
self.assertEquals(['boff'], got.domains)
def test_verify_default(self):
# based on http://snarfed.tumblr.com/
self._test_verify_finds_disqus('<script src="http://disqus.com/forums/my-disqus-name/get_num_replies.js?url131=...&"></script>')
def test_verify_inspirewell_theme_1(self):
# based on http://circusriot.tumblr.com/
self._test_verify_finds_disqus(" var disqus_shortname = 'my-disqus-name';")
def test_verify_inspirewell_theme_2(self):
# based on http://circusriot.tumblr.com/
self._test_verify_finds_disqus(' disqusUsername = "my-disqus-name";')
def test_verify_require_aorcsik_theme(self):
# based on http://require.aorcsik.com/
self._test_verify_finds_disqus(
' dsq.src = "http://my-disqus-name.disqus.com/embed.js";')
def _test_verify_finds_disqus(self, snippet):
# this requests.get is called by webmention-tools
self.expect_requests_get(
'http://primary/', '<html>\nstuff\n%s\n</html>' % snippet, verify=False)
self.mox.ReplayAll()
t = Tumblr.new(self.handler, auth_entity=self.auth_entity, features=['webmention'])
t.verify()
self.assertEquals('my-disqus-name', t.disqus_shortname)
def test_verify_without_disqus(self):
self.expect_requests_get('http://primary/', 'no disqus here!', verify=False)
self.mox.ReplayAll()
t = Tumblr.new(self.handler, auth_entity=self.auth_entity, features=['webmention'])
t.verify()
self.assertIsNone(t.disqus_shortname)
def test_create_comment(self):
self.expect_thread_details()
self.expect_requests_post(
tumblr.DISQUS_API_CREATE_POST_URL,
json.dumps({'response': {'ok': 'sgtm'}}),
params=self.disqus_params({
'thread': '87654',
'message': '<a href="http://who">who</a>: foo bar'}))
self.mox.ReplayAll()
resp = self.tumblr.create_comment('http://primary/post/123999/xyz_abc?asdf',
'who', 'http://who', 'foo bar')
self.assertEquals({'ok': 'sgtm'}, resp)
#.........这里部分代码省略.........
示例2: TumblrTest
# 需要导入模块: from tumblr import Tumblr [as 别名]
# 或者: from tumblr.Tumblr import create_comment [as 别名]
class TumblrTest(testutil.HandlerTest):
def setUp(self):
super(TumblrTest, self).setUp()
self.auth_entity = TumblrAuth(id='name', user_json=json.dumps({
'user': {'blogs': [{'url': 'other'},
{'url': 'http://primary/', 'primary': True}]}}))
self.tumblr = Tumblr(disqus_shortname='my-disqus-name')
appengine_config.DISQUS_API_KEY = 'my key'
appengine_config.DISQUS_API_SECRET = 'my secret'
appengine_config.DISQUS_ACCESS_TOKEN = 'my token'
def disqus_params(self, params):
params.update({
'api_key': 'my key',
'api_secret': 'my secret',
'access_token': 'my token',
})
return params
def expect_thread_details(self, resp=None, **kwargs):
if resp is None:
resp = {'response': {'id': '87654'}}
self.expect_requests_get(
tumblr.DISQUS_API_THREAD_DETAILS_URL,
json.dumps(resp),
params=self.disqus_params({'forum': 'my-disqus-name',
'thread':'link:http://primary/post/123999'}),
**kwargs)
def test_new(self):
t = Tumblr.new(self.handler, auth_entity=self.auth_entity)
self.assertEquals(self.auth_entity.key, t.auth_entity)
self.assertEquals('name', t.name)
self.assertEquals(['http://primary/'], t.domain_urls)
self.assertEquals(['primary'], t.domains)
self.assertEquals('http://api.tumblr.com/v2/blog/primary/avatar/512', t.picture)
def test_new_no_primary_blog(self):
self.auth_entity.user_json = json.dumps({'user': {'blogs': [{'url': 'foo'}]}})
self.assertIsNone(Tumblr.new(self.handler, auth_entity=self.auth_entity))
self.assertIn('Tumblr blog not found', next(iter(self.handler.messages)))
def test_new_with_blog_name(self):
self.auth_entity.user_json = json.dumps({
'user': {'blogs': [{'url': 'foo'},
{'name': 'bar', 'url': 'baz'},
{'name': 'biff', 'url': 'http://boff/'},
]}})
got = Tumblr.new(self.handler, auth_entity=self.auth_entity, blog_name='biff')
self.assertEquals(['http://boff/'], got.domain_urls)
self.assertEquals(['boff'], got.domains)
def test_verify(self):
# based on http://snarfed.tumblr.com/
# this requests.get is called by webmention-tools
self.expect_requests_get('http://primary/', """
<html><body>
some stuff
<script charset="utf-8" type="text/javascript" src="http://disqus.com/forums/my-disqus-name/get_num_replies.js?url131=...&"></script>
</body></html>""", verify=False)
self.mox.ReplayAll()
t = Tumblr.new(self.handler, auth_entity=self.auth_entity, features=['webmention'])
t.verify()
self.assertEquals('my-disqus-name', t.disqus_shortname)
def test_verify_without_disqus(self):
self.expect_requests_get('http://primary/', 'no disqus here!', verify=False)
self.mox.ReplayAll()
t = Tumblr.new(self.handler, auth_entity=self.auth_entity, features=['webmention'])
t.verify()
self.assertIsNone(t.disqus_shortname)
def test_create_comment(self):
self.expect_thread_details()
self.expect_requests_post(
tumblr.DISQUS_API_CREATE_POST_URL,
json.dumps({'response': {'ok': 'sgtm'}}),
params=self.disqus_params({
'thread': '87654',
'message': '<a href="http://who">who</a>: foo bar'}))
self.mox.ReplayAll()
resp = self.tumblr.create_comment('http://primary/post/123999/xyz_abc?asdf',
'who', 'http://who', 'foo bar')
self.assertEquals({'ok': 'sgtm'}, resp)
def test_create_comment_with_unicode_chars(self):
self.expect_thread_details()
self.expect_requests_post(
tumblr.DISQUS_API_CREATE_POST_URL,
json.dumps({}),
params=self.disqus_params({
'thread': '87654',
'message': '<a href="http://who">Degenève</a>: foo Degenève bar'}))
self.mox.ReplayAll()
resp = self.tumblr.create_comment('http://primary/post/123999/xyz_abc',
u'Degenève', 'http://who', u'foo Degenève bar')