Add mocked get_services to test_client.login

Because the redirect after logging in checks the number of services a user has,
this now needs to be mocked.

Right now this means adding `mock_get_login` to any tests that need a login.
This must be one of the first mocks, so that it can be overridden by any use
of `mock_get_services`, for tests that specifically want to rely on a quantity
of mocked services, or their contents.

This is a bit fragile, but there’s already a TODO in the code to make it better
so ¯\_(ツ)_/¯
This commit is contained in:
Chris Hill-Scott
2016-02-05 15:08:36 +00:00
parent 939954cd64
commit d5656a4dc2
4 changed files with 27 additions and 13 deletions

View File

@@ -398,11 +398,23 @@ def mock_get_no_api_keys(mocker):
@pytest.fixture(scope='function')
def mock_login(mocker, mock_get_user, mock_update_user):
def _verify_code(user_id, code, code_type):
return True, ''
return mocker.patch(
'app.user_api_client.check_verify_code',
side_effect=_verify_code)
def _no_services(user_id=None):
return {'data': []}
return (
mocker.patch(
'app.user_api_client.check_verify_code',
side_effect=_verify_code
),
mocker.patch(
'app.notifications_api_client.get_services',
side_effect=_no_services
)
)
@pytest.fixture(scope='function')