|
| 1 | +from time import sleep |
| 2 | +import pytest |
| 3 | +from create_app import create_app |
| 4 | + |
| 5 | + |
| 6 | +@pytest.fixture(scope='module') |
| 7 | +def app_and_username(): |
| 8 | + app, username = create_app() |
| 9 | + app.start() |
| 10 | + yield app, username |
| 11 | + app.stop() |
| 12 | + |
| 13 | + |
| 14 | +def test_add_admin(app_and_username): |
| 15 | + app, username = app_and_username |
| 16 | + msg = app.send_message(username, '/add_admin 1234567') |
| 17 | + sleep(1) |
| 18 | + msg = app.get_messages(username, msg.id + 1) |
| 19 | + assert msg.text == 'Выданы права администратора пользователю с id: 1234567' |
| 20 | + |
| 21 | + |
| 22 | +def test_update_info(app_and_username): |
| 23 | + app, username = app_and_username |
| 24 | + msg = app.send_message(username, '/update_info') |
| 25 | + sleep(1) |
| 26 | + msg = app.get_messages(username, msg.id + 1) |
| 27 | + assert msg.text == 'Информация успешно обновлена.' |
| 28 | + |
| 29 | + |
| 30 | +def test_get_and_answer_support_questions(app_and_username): |
| 31 | + app, username = app_and_username |
| 32 | + msg = app.send_message(username, '/get_support_questions') |
| 33 | + sleep(1) |
| 34 | + msg = app.get_messages(username, msg.id + 1) |
| 35 | + assert msg.text.startswith('Всего страниц:') is True |
| 36 | + msg = app.get_messages(username, msg.id + 1) |
| 37 | + if msg: |
| 38 | + questions_info = msg.text |
| 39 | + question_id = questions_info.split()[1] |
| 40 | + msg = app.send_message(username, '/answer_support_question') |
| 41 | + sleep(1) |
| 42 | + msg = app.get_messages(username, msg.id + 1) |
| 43 | + assert msg.text == 'Введите идентификатор вопроса:' |
| 44 | + msg = app.send_message(username, question_id) |
| 45 | + sleep(1) |
| 46 | + msg = app.get_messages(username, msg.id + 1) |
| 47 | + assert msg.text == 'Выбранный вопрос: "Как долго ждать ответ?"' |
| 48 | + msg = app.send_message(username, 'Не долго') |
| 49 | + sleep(1) |
| 50 | + msg = app.get_messages(username, msg.id + 1) |
| 51 | + assert msg.text == 'Ответ успешно создан!' |
0 commit comments