mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-24 04:10:57 -05:00
81 lines
2.5 KiB
Python
81 lines
2.5 KiB
Python
import pytest
|
||
|
||
from app.notify_client.service_api_client import ServiceAPIClient
|
||
from tests.conftest import fake_uuid
|
||
|
||
|
||
def test_client_posts_archived_true_when_deleting_template(mocker):
|
||
service_id = fake_uuid
|
||
template_id = fake_uuid
|
||
mocker.patch('app.notify_client.current_user', id='1')
|
||
|
||
expected_data = {
|
||
'archived': True,
|
||
'created_by': '1'
|
||
}
|
||
expected_url = '/service/{}/template/{}'.format(service_id, template_id)
|
||
|
||
client = ServiceAPIClient()
|
||
mock_post = mocker.patch('app.notify_client.service_api_client.ServiceAPIClient.post')
|
||
|
||
client.delete_service_template(service_id, template_id)
|
||
mock_post.assert_called_once_with(expected_url, data=expected_data)
|
||
|
||
|
||
@pytest.mark.parametrize(
|
||
'function,params', [
|
||
(ServiceAPIClient.get_service, {}),
|
||
(ServiceAPIClient.get_detailed_service, {'detailed': True}),
|
||
(ServiceAPIClient.get_detailed_service_for_today, {'detailed': True, 'today_only': True})
|
||
],
|
||
ids=lambda x: x.__name__
|
||
)
|
||
def test_client_gets_service(mocker, function, params):
|
||
client = ServiceAPIClient()
|
||
mock_get = mocker.patch.object(client, 'get')
|
||
|
||
function(client, 'foo')
|
||
mock_get.assert_called_once_with('/service/foo', params=params)
|
||
|
||
|
||
def test_client_only_updates_allowed_attributes(mocker):
|
||
mocker.patch('app.notify_client.current_user', id='1')
|
||
with pytest.raises(TypeError) as error:
|
||
ServiceAPIClient().update_service('service_id', foo='bar')
|
||
assert str(error.value) == 'Not allowed to update service attributes: foo'
|
||
|
||
|
||
def test_client_creates_service_with_correct_data(
|
||
mocker,
|
||
active_user_with_permissions,
|
||
fake_uuid,
|
||
):
|
||
client = ServiceAPIClient()
|
||
mock_post = mocker.patch.object(client, 'post')
|
||
mocker.patch('app.notify_client.current_user', id='123')
|
||
|
||
client.create_service(
|
||
service_name='My first service',
|
||
organisation_type='central_government',
|
||
message_limit=1,
|
||
restricted=True,
|
||
user_id=fake_uuid,
|
||
email_from='test@example.com',
|
||
)
|
||
mock_post.assert_called_once_with(
|
||
'/service',
|
||
dict(
|
||
# Autogenerated arguments
|
||
created_by='123',
|
||
active=True,
|
||
# ‘service_name’ argument is coerced to ‘name’
|
||
name='My first service',
|
||
# The rest pass through with the same names
|
||
organisation_type='central_government',
|
||
message_limit=1,
|
||
restricted=True,
|
||
user_id=fake_uuid,
|
||
email_from='test@example.com',
|
||
),
|
||
)
|