def test_message_sending(self): message = Message.send(self.chat_id, MESSAGE, MESSAGE_TYPE) self.assertIsInstance(message, Message) self.assertEqual(message.content, MarkdownMixin.decode(MESSAGE)) self.assertEqual(message.author, USERNAME) self.assertEqual(message.chat_link, self.chat_id) self.assertEqual(message.type, MESSAGE_TYPE)
def test_change_chat_name(self): new_chat_name = CHAT_NAME * 2 chat_id = Chat.create(CHAT_NAME, CHAT_CODE, CODE_TYPE, CHAT_ACCESS_KEY) chat = Chat.get(chat_id) chat.set_name(new_chat_name) chat = Chat.get(chat_id) self.assertEqual(chat.name, MarkdownMixin.decode(new_chat_name))
def __init__(self, **params): self.content = params.get('content', "") self.author = User.get_login() self.chat_link = params.get('chat_link') self.parent_link = params.get('parent_link') self.message = MarkdownMixin.decode(params.get('message')) self.number = Code.get_count_in_chat(params.get('chat_link')) + 1
def set_name(self, name): """Установка названия чата :param name: новое название чата :return: объект в разных написаниях названия чата: \ оригинальное, без тегов, экрнированные теги """ self.name = MarkdownMixin.decode(name) db.session.commit() Message.send_about_change_chat_name(self.id, MarkdownMixin.plain(self.name)) return { "original": self.name, "plain": MarkdownMixin.plain(self.name), "escaped": MarkdownMixin.escape_html(self.name) }
def test_get_commits_tree_with_single_code(self): tree = Code.get_commits_tree(self.chat_id) self.assertEqual(tree.get('text').get('name'), 1) self.assertEqual( tree.get('text').get('title'), MarkdownMixin.decode(START_COMMIT_MESSAGE)) self.assertEqual(tree.get('children'), []) self.assertEqual(tree.get('innerHTML'), NODE_MARKUP.format(id=1))
def test_get_root_in_chat_with_single_code(self): code = Code.get_root_in_chat(self.chat_id) self.assertIsInstance(code, Code) self.assertEquals(code.author, USERNAME) self.assertEquals(code.content, CHAT_CODE) self.assertEquals(code.chat_link, self.chat_id) self.assertEquals(code.parent_link, None) self.assertEquals(code.message, MarkdownMixin.decode(START_COMMIT_MESSAGE))
def test_plain_text(self): self.assertEqual(MarkdownMixin.plain(BASE_TEXT), TEXT_WITHOUT_HTML_TAG)
def test_text_markdown(self): self.assertEqual(MarkdownMixin.decode(BASE_TEXT), TEXT_MARKDOWN_DECODED)
def test_text_escape_html(self): self.assertEqual(MarkdownMixin.escape_html(BASE_TEXT), TEXT_WITH_ESCAPE_HTML)
def test_find_chat_by_full_name(self): search_name = CHAT_NAME found_chat_list = Chat.find(search_name) self.assertGreaterEqual(len(found_chat_list), 1) self.assertEqual(found_chat_list[0].name, MarkdownMixin.decode(CHAT_NAME))
def test_create_chat(self): chat = Chat.get(self.chat_id) chat_info = chat.get_info() self.assertEquals(chat_info.get('name'), MarkdownMixin.decode(CHAT_NAME)) self.assertEquals(chat_info.get('code_type'), CODE_TYPE)
def __init__(self, name, code_type, access_key): self.name = MarkdownMixin.decode(name) self.code_type = code_type self.access_key = access_key
def __init__(self, content, chat_link, message_type): self.content = MarkdownMixin.decode(content) self.author = User.get_login() self.chat_link = chat_link self.type = message_type