oncall-engine/engine/apps/telegram/tests/test_models.py
Innokentii Konstantinov 2c6a27154f
Support mutliregion telegram (#676)
* Support mutliregion telegram

* Fix test_personal_message

* Fix tg verification code tests

* Simplify /start cmd handler

* Comment about link with org_id in tg msg
2022-10-25 14:53:07 +08:00

45 lines
1.5 KiB
Python

import pytest
from apps.telegram.models.verification.personal import TelegramVerificationCode
@pytest.mark.django_db
def test_user_verification_handler_process_update_another_account_already_linked(
make_organization,
make_user_for_organization,
make_telegram_user_connector,
make_telegram_verification_code,
):
organization = make_organization()
chat_id = 123
user_1 = make_user_for_organization(organization)
make_telegram_user_connector(user_1, telegram_chat_id=chat_id)
user_2 = make_user_for_organization(organization)
code = make_telegram_verification_code(user_2)
connector, created = TelegramVerificationCode.verify_user(code.uuid_with_org_id, chat_id, "nickname")
assert created
assert connector.telegram_chat_id == chat_id
assert connector.user == user_2
@pytest.mark.django_db
def test_user_verification_handler_process_update_user_already_linked(
make_organization,
make_user_for_organization,
make_telegram_user_connector,
make_telegram_verification_code,
):
organization = make_organization()
chat_id = 123
user_1 = make_user_for_organization(organization)
make_telegram_user_connector(user_1, telegram_chat_id=chat_id)
other_chat_id = 321
code = make_telegram_verification_code(user_1)
connector, created = TelegramVerificationCode.verify_user(code.uuid_with_org_id, other_chat_id, "nickname")
assert created is False
assert connector.user == user_1
assert connector.telegram_chat_id == chat_id