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_verify_finds_disqus(self, snippet): self.expect_requests_get( 'http://primary/', f'<html>\nstuff\n{snippet}\n</html>') self.mox.ReplayAll() t = Tumblr.new(auth_entity=self.auth_entity, features=['webmention']) t.verify() self.assertEqual('my-disqus-name', t.disqus_shortname)
def test_verify_without_disqus(self): self.expect_webmention_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_new(self): t = Tumblr.new(auth_entity=self.auth_entity) self.assertEqual(self.auth_entity.key, t.auth_entity) self.assertEqual('name', t.name) self.assertEqual(['http://primary/'], t.domain_urls) self.assertEqual(['primary'], t.domains) self.assertEqual('http://api.tumblr.com/v2/blog/primary/avatar/512', t.picture)
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!') self.mox.ReplayAll() t = Tumblr.new(self.handler, auth_entity=self.auth_entity, features=['webmention']) t.verify() self.assertIsNone(t.disqus_shortname)
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_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(auth_entity=self.auth_entity, blog_name='biff') self.assertEqual(['http://boff/'], got.domain_urls) self.assertEqual(['boff'], got.domains)
def _test_verify_finds_disqus(self, snippet): # this requests.get is called by webmention-tools self.expect_webmention_requests_get( 'http://primary/', '<html>\nstuff\n%s\n</html>' % snippet) 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_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_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_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_no_primary_blog(self): self.auth_entity.user_json = json_dumps({'user': {'blogs': [{'url': 'foo'}]}}) with app.test_request_context(): self.assertIsNone(Tumblr.new(auth_entity=self.auth_entity)) self.assertIn('Tumblr blog not found', get_flashed_messages()[0])