make test folder structure align with app folder structure

This commit is contained in:
Leo Hemsted
2016-07-15 15:23:40 +01:00
parent 1cd2841c17
commit 5bd90bba64
8 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
from app.notify_client.events_api_client import EventsApiClient
def test_events_client_calls_correct_api_endpoint(mocker):
expected_url = '/events'
event_type = 'anything'
event_data = {'does_not': 'matter'}
expected_data = {'event_type': event_type, 'data': event_data}
client = EventsApiClient()
mock_post = mocker.patch('app.notify_client.events_api_client.EventsApiClient.post')
client.create_event(event_type, event_data)
mock_post.assert_called_once_with(url=expected_url, data=expected_data)

View File

@@ -0,0 +1,20 @@
from app.notify_client.invite_api_client import InviteApiClient
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)
client = InviteApiClient()
mock_get = mocker.patch('app.notify_client.invite_api_client.InviteApiClient.get', return_value=expected_data)
invites = client.get_invites_for_service(service_id)
mock_get.assert_called_once_with(expected_url)
assert len(invites) == 1
assert invites[0].status == 'pending'

View File

@@ -0,0 +1,28 @@
from app.notify_client.job_api_client import JobApiClient
def test_client_creates_job_data_correctly(mocker, fake_uuid):
job_id = fake_uuid
service_id = fake_uuid
template_id = fake_uuid
original_file_name = 'test.csv'
notification_count = 1
expected_data = {
"id": job_id,
"template": template_id,
"original_file_name": original_file_name,
"notification_count": 1
}
expected_url = '/service/{}/job'.format(service_id)
client = JobApiClient()
mock_attach_user = mocker.patch(
'app.notify_client.job_api_client._attach_current_user',
return_value={'created_by': fake_uuid})
mock_post = mocker.patch('app.notify_client.job_api_client.JobApiClient.post')
client.create_job(job_id, service_id, template_id, original_file_name, notification_count)
mock_post.assert_called_once_with(url=expected_url, data=expected_data)

View File

@@ -0,0 +1,41 @@
import pytest
from app.notify_client.notification_api_client import NotificationApiClient
def test_client_gets_notifications(mocker):
mock_get = mocker.patch('app.notify_client.notification_api_client.NotificationApiClient.get')
NotificationApiClient().get_all_notifications()
mock_get.assert_called_once_with(url='/notifications', params={})
def test_client_gets_notifications_with_page(mocker):
mock_get = mocker.patch('app.notify_client.notification_api_client.NotificationApiClient.get')
NotificationApiClient().get_all_notifications(page=99)
mock_get.assert_called_once_with(url='/notifications', params={'page': 99})
@pytest.mark.parametrize("arguments,expected_call", [
(
{},
{'url': '/service/abcd1234/notifications', 'params': {}}
),
(
{'page': 99},
{'url': '/service/abcd1234/notifications', 'params': {'page': 99}}
),
(
{'job_id': 'efgh5678'},
{'url': '/service/abcd1234/job/efgh5678/notifications', 'params': {}}
),
(
{'job_id': 'efgh5678', 'page': 48},
{'url': '/service/abcd1234/job/efgh5678/notifications', 'params': {'page': 48}}
)
])
def test_client_gets_notifications_for_service_and_job_by_page(mocker, arguments, expected_call):
mock_get = mocker.patch('app.notify_client.notification_api_client.NotificationApiClient.get')
NotificationApiClient().get_notifications_for_service('abcd1234', **arguments)
mock_get.assert_called_once_with(**expected_call)

View File

@@ -0,0 +1,48 @@
import uuid
from datetime import datetime
from app.notify_client.statistics_api_client import StatisticsApiClient
def test_notifications_statistics_client_calls_correct_api_endpoint(mocker, api_user_active):
some_service_id = uuid.uuid4()
expected_url = '/service/{}/notifications-statistics'.format(some_service_id)
client = StatisticsApiClient()
mock_get = mocker.patch('app.notify_client.statistics_api_client.StatisticsApiClient.get')
client.get_statistics_for_service(some_service_id)
mock_get.assert_called_once_with(url=expected_url, params={})
def test_notifications_statistics_client_calls_correct_api_endpoint_with_params(mocker, api_user_active):
some_service_id = uuid.uuid4()
expected_url = '/service/{}/notifications-statistics'.format(some_service_id)
client = StatisticsApiClient()
mock_get = mocker.patch('app.notify_client.statistics_api_client.StatisticsApiClient.get')
client.get_statistics_for_service(some_service_id, limit_days=99)
mock_get.assert_called_once_with(url=expected_url, params={'limit_days': 99})
def test_notifications_statistics_client_for_stats_by_day_calls_correct_api_endpoint(mocker, api_user_active):
some_service_id = uuid.uuid4()
today = datetime.today().date().strftime('%Y-%m-%d')
expected_url = '/service/{}/notifications-statistics/day/{}'.format(some_service_id, today)
client = StatisticsApiClient()
mock_get = mocker.patch('app.notify_client.statistics_api_client.StatisticsApiClient.get')
client.get_statistics_for_service_for_day(some_service_id, today)
mock_get.assert_called_once_with(url=expected_url)

View File

@@ -0,0 +1,30 @@
import uuid
from app.notify_client.template_statistics_api_client import TemplateStatisticsApiClient
def test_template_statistics_client_calls_correct_api_endpoint_for_service(mocker, api_user_active):
some_service_id = uuid.uuid4()
expected_url = '/service/{}/template-statistics'.format(some_service_id)
client = TemplateStatisticsApiClient()
mock_get = mocker.patch('app.notify_client.template_statistics_api_client.TemplateStatisticsApiClient.get')
client.get_template_statistics_for_service(some_service_id)
mock_get.assert_called_once_with(url=expected_url, params={})
def test_template_statistics_client_calls_correct_api_endpoint_for_template(mocker, api_user_active):
some_service_id = uuid.uuid4()
some_template_id = uuid.uuid4()
expected_url = '/service/{}/template-statistics/{}'.format(some_service_id, some_template_id)
client = TemplateStatisticsApiClient()
mock_get = mocker.patch('app.notify_client.template_statistics_api_client.TemplateStatisticsApiClient.get')
client.get_template_statistics_for_template(some_service_id, some_template_id)
mock_get.assert_called_once_with(url=expected_url)

View File

@@ -0,0 +1,15 @@
from app.notify_client.user_api_client import UserApiClient
def test_client_uses_correct_find_by_email(mocker, api_user_active):
expected_url = '/user/email'
expected_params = {'email': api_user_active.email_address}
client = UserApiClient()
client.max_failed_login_count = 1 # doesn't matter for this test
mock_get = mocker.patch('app.notify_client.user_api_client.UserApiClient.get')
client.get_user_by_email(api_user_active.email_address)
mock_get.assert_called_once_with(expected_url, params=expected_params)