mirror of
https://github.com/Balshgit/gpt_chat_bot.git
synced 2025-12-16 21:20:39 +03:00
add ban user action (#77)
* add ban user action * fix tests * send message through update.effective_message
This commit is contained in:
@@ -57,7 +57,7 @@ def engine(test_settings: AppSettings) -> Generator[Engine, None, None]:
|
||||
engine.dispose()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture(autouse=True)
|
||||
def dbsession(engine: Engine) -> Generator[Session, None, None]:
|
||||
"""
|
||||
Get session to database.
|
||||
@@ -69,7 +69,6 @@ def dbsession(engine: Engine) -> Generator[Session, None, None]:
|
||||
:yields: async session.
|
||||
"""
|
||||
connection = engine.connect()
|
||||
trans = connection.begin()
|
||||
|
||||
session_maker = sessionmaker(
|
||||
connection,
|
||||
@@ -83,7 +82,6 @@ def dbsession(engine: Engine) -> Generator[Session, None, None]:
|
||||
finally:
|
||||
meta.drop_all(engine)
|
||||
session.close()
|
||||
trans.rollback()
|
||||
connection.close()
|
||||
|
||||
|
||||
|
||||
@@ -261,6 +261,23 @@ async def test_bug_report_action(
|
||||
)
|
||||
|
||||
|
||||
async def test_get_developer_action(
|
||||
main_application: Application,
|
||||
test_settings: AppSettings,
|
||||
) -> None:
|
||||
with (
|
||||
mock.patch.object(telegram._message.Message, "reply_text") as mocked_reply_text,
|
||||
mock.patch.object(telegram._bot.Bot, "send_message", return_value=lambda *args, **kwargs: (args, kwargs)),
|
||||
):
|
||||
bot_update = BotUpdateFactory(message=BotMessageFactory.create_instance(text="/developer"))
|
||||
|
||||
await main_application.bot_app.application.process_update(
|
||||
update=Update.de_json(data=bot_update, bot=main_application.bot_app.bot)
|
||||
)
|
||||
|
||||
assert mocked_reply_text.call_args.args == ("Автор бота: *Дмитрий Афанасьев*\n\nTg nickname: *Balshtg*",)
|
||||
|
||||
|
||||
async def test_ask_question_action(
|
||||
dbsession: Session,
|
||||
main_application: Application,
|
||||
|
||||
20
bot_microservice/tests/integration/factories/user.py
Normal file
20
bot_microservice/tests/integration/factories/user.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import factory
|
||||
|
||||
from core.auth.models.users import User
|
||||
from tests.integration.factories.utils import BaseModelFactory
|
||||
|
||||
|
||||
class UserFactory(BaseModelFactory):
|
||||
id = factory.Sequence(lambda n: n + 1)
|
||||
email = factory.Faker("email")
|
||||
username = factory.Faker("user_name", locale="en_EN")
|
||||
first_name = factory.Faker("word")
|
||||
last_name = factory.Faker("word")
|
||||
ban_reason = factory.Faker("text", max_nb_chars=100)
|
||||
hashed_password = factory.Faker("word")
|
||||
is_active = True
|
||||
is_superuser = False
|
||||
created_at = factory.Faker("past_datetime")
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
Reference in New Issue
Block a user