Files
notifications-admin/tests/app/notify_client/test_invite_client.py
Ben Thorner 5bfce61bcf Rename "app_" fixture to "notify_admin"
This naming was introduced in 2016 without explanation [1]. I find it
confusing because:

- It's reminiscent of "_app", which is a Python convention indicating
the variable is internal, so maybe avoid using it.

- It suggests there's some other "app" fixture I should be using (there
isn't, though).

The Python style guide describes using an underscore suffix to avoid
clashes with inbuilt names [1], which is sort of applicable if we need
to import the "app" module [2]. However, we can also avoid clashes by
choosing a different name, without the strange underscore.

[1]: 3b1d521c10
[2]: 78824f54fd/tests/app/main/views/test_forgot_password.py (L5)
2021-05-19 11:44:20 +01:00

58 lines
1.6 KiB
Python

from unittest.mock import ANY
from app import invite_api_client
def test_client_creates_invite(
notify_admin,
mocker,
fake_uuid,
sample_invite,
):
mocker.patch('app.notify_client.current_user')
mock_post = mocker.patch(
'app.invite_api_client.post',
return_value={'data': dict.fromkeys({
'id', 'service', 'from_user', 'email_address',
'permissions', 'status', 'created_at', 'auth_type', 'folder_permissions'
})}
)
invite_api_client.create_invite(
'12345', '67890', 'test@example.com', {'send_messages'}, 'sms_auth', [fake_uuid]
)
mock_post.assert_called_once_with(
url='/service/{}/invite'.format('67890'),
data={
'auth_type': 'sms_auth',
'email_address': 'test@example.com',
'from_user': '12345',
'service': '67890',
'created_by': ANY,
'permissions': 'send_emails,send_letters,send_texts',
'invite_link_host': 'http://localhost:6012',
'folder_permissions': [fake_uuid]
}
)
def test_client_returns_invite(mocker, sample_invite):
sample_invite['status'] = 'pending'
service_id = sample_invite['service']
expected_data = {'data': [sample_invite]}
expected_url = '/service/{}/invite'.format(service_id)
mock_get = mocker.patch('app.notify_client.invite_api_client.InviteApiClient.get', return_value=expected_data)
invites = invite_api_client.get_invites_for_service(service_id)
mock_get.assert_called_once_with(expected_url)
assert len(invites) == 1
assert invites[0]['status'] == 'pending'