def test_get_page(self): telegraph = Telegraph() response = telegraph.get_page('Hey-01-17-2', return_html=False) self.assertEqual( response['content'], [{'tag': 'p', 'children': ['Hello, world!']}] )
def get_changelog(obj: Dict): if not obj["changelog"].startswith(TELEGRAPH_DOMAIN): return obj["changelog"] telegraph = Telegraph() html_data: str = None try: request = telegraph.get_page(obj["changelog"].replace( TELEGRAPH_DOMAIN, "")) html_data = request["content"] except TelegraphException: return "Cannot get changelog" return html_data
class TestAPI(TestCase): def setUp(self): self.t = Telegraph( 'd676e590b0c6bac0ea58cfcdd350272691ea9fb10b2aeb33edcf68dbb20d') def tearDown(self): self.t.close() def test_get_page(self): page = self.t.get_page('api') self.assertEqual(page.title, 'Telegraph API') def test_create_page(self): page = self.t.create_page(title="Test Page", return_content=True, content=CONTENT) self.assertEqual(page.content, CONTENT)
def test_get_page_without_content(self): telegraph = Telegraph() response = telegraph.get_page('Hey-01-17-2', return_content=False) self.assertTrue('content' not in response)
def test_get_page_html(self): telegraph = Telegraph() response = telegraph.get_page('Hey-01-17-2') self.assertEqual(response['content'], '<p>Hello, world!</p>')
def __delete_page(self): pass class TelegraphCms(FileHandler): pass if __name__ == '__main__': argparser = argparse.ArgumentParser() argparser.add_argument( 'path', help='Путь до файла, который требуется залить на сайт') path2file = argparser.parse_args().path telegraph = Telegraph() telegraph.create_account(short_name='1338') # response = telegraph.create_page( # 'Hey', # html_content='<p>Hello, world!</p>' # ) # response = telegraph.edit_page('http://telegra.ph/Hey-12-07-3', 'Hey', 'smth new') # print('http://telegra.ph/{}'.format(response['path'])) # print(111) # print(telegraph.get_page('http://telegra.ph/Hey-12-07-3', True)) # print(telegraph.get_page('api', True)) print(telegraph.get_page('api', False)) __docformat__ = 'restructuredtext ru'