|
6 | 6 | import asyncio |
7 | 7 | import logging |
8 | 8 | from contextlib import AsyncExitStack |
9 | | -from unittest.mock import Mock |
10 | 9 |
|
11 | 10 | import pytest |
12 | 11 | import sqlalchemy as sa |
13 | 12 | from aiohttp.test_utils import TestClient, make_mocked_request |
14 | 13 | from faker import Faker |
15 | 14 | from models_library.authentification import TwoFactorAuthentificationMethod |
16 | | -from pytest_mock import MockerFixture |
| 15 | +from pytest_mock import MockerFixture, MockType |
17 | 16 | from pytest_simcore.helpers.assert_checks import assert_status |
18 | 17 | from pytest_simcore.helpers.monkeypatch_envs import EnvVarsDict, setenvs_from_dict |
19 | 18 | from pytest_simcore.helpers.webserver_login import NewUser, parse_link, parse_test_marks |
@@ -76,16 +75,20 @@ def postgres_db(postgres_db: sa.engine.Engine): |
76 | 75 |
|
77 | 76 |
|
78 | 77 | @pytest.fixture |
79 | | -def mocked_twilio_service(mocker: MockerFixture) -> dict[str, Mock]: |
| 78 | +def mocked_twilio_service(mocker: MockerFixture) -> dict[str, MockType]: |
| 79 | + mock = mocker.patch( |
| 80 | + "simcore_service_webserver.login._controller.registration_rest._twofa_service.send_sms_code", |
| 81 | + autospec=True, |
| 82 | + ) |
| 83 | + |
| 84 | + mock2 = mocker.patch( |
| 85 | + "simcore_service_webserver.login._controller.auth_rest._twofa_service.send_sms_code", |
| 86 | + autospec=False, |
| 87 | + ) |
| 88 | + |
80 | 89 | return { |
81 | | - "send_sms_code_for_registration": mocker.patch( |
82 | | - "simcore_service_webserver.login._controller.registration_rest.twofa_service.send_sms_code", |
83 | | - autospec=True, |
84 | | - ), |
85 | | - "send_sms_code_for_login": mocker.patch( |
86 | | - "simcore_service_webserver.login._controller.auth_rest.twofa_service.send_sms_code", |
87 | | - autospec=True, |
88 | | - ), |
| 90 | + "send_sms_code_for_registration": mock, |
| 91 | + "send_sms_code_for_login": mock, |
89 | 92 | } |
90 | 93 |
|
91 | 94 |
|
@@ -120,7 +123,7 @@ async def test_workflow_register_and_login_with_2fa( |
120 | 123 | fake_user_email: str, |
121 | 124 | fake_user_password: str, |
122 | 125 | fake_user_phone_number: str, |
123 | | - mocked_twilio_service: dict[str, Mock], |
| 126 | + mocked_twilio_service: dict[str, MockType], |
124 | 127 | mocked_email_core_remove_comments: None, |
125 | 128 | cleanup_db_tables: None, |
126 | 129 | ): |
@@ -309,7 +312,7 @@ async def test_can_register_same_phone_in_different_accounts( |
309 | 312 | fake_user_email: str, |
310 | 313 | fake_user_password: str, |
311 | 314 | fake_user_phone_number: str, |
312 | | - mocked_twilio_service: dict[str, Mock], |
| 315 | + mocked_twilio_service: dict[str, MockType], |
313 | 316 | cleanup_db_tables: None, |
314 | 317 | ): |
315 | 318 | """ |
@@ -421,7 +424,7 @@ async def test_2fa_sms_failure_during_login( |
421 | 424 |
|
422 | 425 | mocker.patch( |
423 | 426 | # MD: Emulates error in graylog https://monitoring.osparc.io/graylog/search/649e7619ce6e0838a96e9bf1?q=%222FA%22&rangetype=relative&from=172800 |
424 | | - "simcore_service_webserver.login.twofa_service.twilio.rest.Client", |
| 427 | + "simcore_service_webserver.login._twofa_service.twilio.rest.Client", |
425 | 428 | autospec=True, |
426 | 429 | side_effect=TwilioRestException( |
427 | 430 | status=400, |
|
0 commit comments