def test_get_commits_tree_with_many_codes(self): parent_code = Code.get_root_in_chat(self.chat_id) child_code_id = Code.send(self.chat_id, CHAT_CODE, parent_code.id, COMMIT_MESSAGE) tree = Code.get_commits_tree(self.chat_id) self.assertIsInstance(tree.get('children'), list) self.assertIsInstance(tree['children'][0], dict) self.assertIsInstance(tree['children'][0].get('text'), dict) self.assertEqual(tree['children'][0]['text'].get('name'), child_code_id)
def create(chat_name, code, code_type, access_key=''): """Создаёт чат :param chat_name: Имя чата :param code: Код чата :param code_type: Язык программирования :param access_key: Ключ доступа :return: Номер чата """ chat_to_create = Chat(chat_name, code_type, access_key) db.session.add(chat_to_create) db.session.commit() chat_id = chat_to_create.id Code.send(chat_id, code, None, u'Начальная версия') return chat_id
def tree(): """Данная функция создаёт дерево коммитов чата :return: Страницу дерева коммитов """ get_tree_form = GetTreeForm(request.args) chat_id = get_tree_form.chat.data return dumps(Code.get_commits_tree(chat_id))
def get_code(): """Данная функция отправляет код с сервера к клиенту :return: Код """ get_code_form = GetCodeForm(request.args) index = get_code_form.index.data return dumps(Code.get(index))
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 get_info(self): """Возвращает форматированный чат в виде словаря :return: Имя чата и язык программирования чата """ return { 'name': self.name, 'code_type': self.code_type, 'start_code': Code.get_root_in_chat(self.id) }
def send_code(): """Данная функция отправляет код на сервер от клиента :return: Отправлен ли код """ send_code_form = SendCodeForm() chat_id = send_code_form.chat.data code = send_code_form.code.data parent = send_code_form.parent.data message = send_code_form.message.data code_id = Code.send(chat_id, code, parent, message) return dumps({"success": True, "error": "", "commit": code_id})
def test_available_code(self): code_params = { "content": "content", "author": "author", "chat_link": 1, "parent_link": None, "create_time": 123 } code = Code(**code_params) self.assertTrue(hasattr(code, "id")) self.assertTrue(hasattr(code, "content")) self.assertTrue(hasattr(code, "author")) self.assertTrue(hasattr(code, "message")) self.assertTrue(hasattr(code, "number")) self.assertTrue(hasattr(code, "chat_link")) self.assertTrue(hasattr(code, "parent_link")) self.assertTrue(hasattr(code, "create_time")) self.assertTrue(hasattr(code, "remove_time"))
def test_get_code(self): chat_id = Chat.create(CHAT_NAME, CHAT_CODE, CODE_TYPE) code_id = Code.send(chat_id, CODE, 1, COMMIT_MESSAGE) response = self.app.get(CODE_GET_PAGE_URL.format(code_id=code_id)) self.assertEqual(response.status_code, 200)
def test_chat_has_code(self): chat = Chat.get(self.chat_id) code_id = Code.send(self.chat_id, CODE, PARENT_CODE_ID, COMMIT_MESSAGE) - 1 self.assertTrue(chat.has_code(str(code_id))) self.assertFalse(chat.has_code(str(code_id + 1)))
def test_get_count_in_chat(self): self.assertEqual(Code.get_count_in_chat(self.chat_id), 1) Code.send(self.chat_id, CHAT_CODE, None, COMMIT_MESSAGE) self.assertEqual(Code.get_count_in_chat(self.chat_id), 2)
def test_get_root_in_chat_with_many_codes(self): parent_code = Code.get_root_in_chat(self.chat_id) Code.send(self.chat_id, CHAT_CODE, parent_code.id, COMMIT_MESSAGE) got_root_code = Code.get_root_in_chat(self.chat_id) self.assertIsInstance(got_root_code, Code) self.assertEquals(got_root_code.id, parent_code.id)
def test_code_sending(self): send_code_id = Code.send(self.chat_id, CODE, PARENT_CODE_ID, COMMIT_MESSAGE) sent_code = Code.get(send_code_id) self.assertEquals(sent_code.get('author'), USERNAME) self.assertEquals(sent_code.get('code'), CODE)