Skip to content

Commit

Permalink
test: add admin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elizaveta-andreeva committed Jul 18, 2024
1 parent f2867e5 commit ee5db8c
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
16 changes: 14 additions & 2 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,22 @@ def test_change_pronoun(app_and_username):
def test_change_mode(app_and_username):
app, username = app_and_username
msg = app.send_message(username, '/change_mode')
sleep(10)
sleep(20)
msg = app.get_messages(username, msg.id + 1)
if msg.text:
msg = app.send_message(username, '/change_mode')
sleep(10)
sleep(20)
msg = app.get_messages(username, msg.id + 1)
assert msg.media == pyrogram.enums.MessageMediaType.VOICE


def test_add_question(app_and_username):
app, username = app_and_username
msg = app.send_message(username, '/add_question')
sleep(2)
msg = app.get_messages(username, msg.id + 1)
assert msg.text == 'Введите вопрос:'
msg = app.send_message(username, 'Как долго ждать ответ?')
sleep(2)
msg = app.get_messages(username, msg.id + 1)
assert msg.text == 'Вопрос успешно создан!'
51 changes: 51 additions & 0 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from time import sleep
import pytest
from create_app import create_app


@pytest.fixture(scope='module')
def app_and_username():
app, username = create_app()
app.start()
yield app, username
app.stop()


def test_add_admin(app_and_username):
app, username = app_and_username
msg = app.send_message(username, '/add_admin 1234567')
sleep(1)
msg = app.get_messages(username, msg.id + 1)
assert msg.text == 'Выданы права администратора пользователю с id: 1234567'


def test_update_info(app_and_username):
app, username = app_and_username
msg = app.send_message(username, '/update_info')
sleep(1)
msg = app.get_messages(username, msg.id + 1)
assert msg.text == 'Информация успешно обновлена.'


def test_get_and_answer_support_questions(app_and_username):
app, username = app_and_username
msg = app.send_message(username, '/get_support_questions')
sleep(1)
msg = app.get_messages(username, msg.id + 1)
assert msg.text.startswith('Всего страниц:') is True
msg = app.get_messages(username, msg.id + 1)
if msg:
questions_info = msg.text
question_id = questions_info.split()[1]
msg = app.send_message(username, '/answer_support_question')
sleep(1)
msg = app.get_messages(username, msg.id + 1)
assert msg.text == 'Введите идентификатор вопроса:'
msg = app.send_message(username, question_id)
sleep(1)
msg = app.get_messages(username, msg.id + 1)
assert msg.text == 'Выбранный вопрос: "Как долго ждать ответ?"'
msg = app.send_message(username, 'Не долго')
sleep(1)
msg = app.get_messages(username, msg.id + 1)
assert msg.text == 'Ответ успешно создан!'
4 changes: 4 additions & 0 deletions tests/test_admin_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#! /bin/bash

pytest -s test_admin.py
echo Pytest exited $?

0 comments on commit ee5db8c

Please sign in to comment.