def index(): """Данная функция генерирует главную страницу для пользователя :return: Главная страница с чатами пользователя, является ли человек \ в сессии, формой входа(Если человек не зарегистрирован, заголовок чата """ find_chat_form = FindChatForm() chat_create_form = CreateChatForm() login_form = LoginForm() if login_form.validate_on_submit(): User.login(login_form.login.data) if chat_create_form.validate_on_submit(): name = chat_create_form.name.data code_type = chat_create_form.code_type.data code = chat_create_form.code.data access_key = chat_create_form.access_key.data if chat_create_form.is_file_valid(): code = chat_create_form.file.data.read() chat_id = Chat.create(name, code, code_type, access_key) return redirect('/chat/' + str(chat_id)) return render_template('index.html', chats=Chat.find(find_chat_form.chat_title.data), login_form=login_form, chat_create_form=chat_create_form, find_chat_form=find_chat_form, login=User.get_login(), allowed_ex=",".join([ '.' + i for i in app.config["ALLOWED_EXTENSIONS"] ]), allowed_languages=app.config["ALLOWED_LANGUAGES"])
def test_find_with_page(self): CHAT_COUNT = 6 LIMIT = 5 PAGE = 2 self.__create_mock_chats(CHAT_COUNT) chats = Chat.find('', limit=LIMIT, page=PAGE) self.assertEqual(len(chats), CHAT_COUNT - LIMIT)
def api_chat_list(): """Получение списка созданных чатов :return: список созданных чатов """ search = request.args.get('search', '') limit = int(request.args.get('limit', 0)) page = int(request.args.get('page', 1)) chats = Chat.find(search, limit, page) data = [chat.to_dict() for chat in chats] return jsonify(data)
def test_find_with_limit(self): CHAT_COUNT = 10 LIMIT = 5 self.__create_mock_chats(CHAT_COUNT) chats = Chat.find('', limit=LIMIT) self.assertEqual(len(chats), LIMIT)
def test_find_chat_all(self): CHAT_COUNT = 15 INFINITELY_LIMIT = 0 self.__create_mock_chats(CHAT_COUNT) chats = Chat.find('', limit=INFINITELY_LIMIT) self.assertEqual(len(chats), CHAT_COUNT)
def test_find_chat_by_id(self): search_id = str(self.chat_id) found_chat_list = Chat.find(search_id) self.assertEqual(len(found_chat_list), 1) self.assertEqual(found_chat_list[0].id, int(search_id))
def test_find_chat_by_name(self): search_name = CHAT_NAME[2:-2] found_chat_list = Chat.find(search_name) self.assertGreaterEqual(len(found_chat_list), 1) self.assertIn(search_name, found_chat_list[0].name)
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))