mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 22:40:31 -04:00
Add a component for picking the time to send a job
Users need to pick a time in the next 24hrs, or send a file immediately. Rationale for this is a bit lost in time-before-holiday, but generally: ‘Now’ and ‘later’ as the inital choices makes it really clear what this feature is about conceptually. The choice of times is absolute, eg ‘1pm’ not ‘in 3 hours’
This commit is contained in:
22
tests/app/main/test_choose_time_form.py
Normal file
22
tests/app/main/test_choose_time_form.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import pytest
|
||||
|
||||
from app.main.forms import ChooseTimeForm
|
||||
from freezegun import freeze_time
|
||||
|
||||
|
||||
@freeze_time("2016-01-01 11:09:00.061258")
|
||||
def test_form_contains_next_24h(app_):
|
||||
|
||||
choices = ChooseTimeForm().scheduled_for.choices
|
||||
|
||||
assert choices[0] == ('', 'Now')
|
||||
assert choices[1] == ('2016-01-01T12:00:00.061258', 'Midday')
|
||||
assert choices[23] == ('2016-01-02T10:00:00.061258', '10am')
|
||||
|
||||
with pytest.raises(IndexError):
|
||||
assert choices[24]
|
||||
|
||||
|
||||
@freeze_time("2016-01-01 11:09:00.061258")
|
||||
def test_form_defaults_to_now(app_):
|
||||
assert ChooseTimeForm().scheduled_for.data == ''
|
||||
@@ -322,6 +322,11 @@ def test_upload_csvfile_with_valid_phone_shows_all_numbers(
|
||||
mock_get_detailed_service_for_today.assert_called_once_with(fake_uuid)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'when', [
|
||||
'', '2016-08-25T13:04:21.767198'
|
||||
]
|
||||
)
|
||||
def test_create_job_should_call_api(
|
||||
app_,
|
||||
service_one,
|
||||
@@ -331,7 +336,8 @@ def test_create_job_should_call_api(
|
||||
mock_get_notifications,
|
||||
mock_get_service_template,
|
||||
mocker,
|
||||
fake_uuid
|
||||
fake_uuid,
|
||||
when
|
||||
):
|
||||
service_id = service_one['id']
|
||||
data = mock_get_job(service_one['id'], fake_uuid)['data']
|
||||
@@ -348,11 +354,18 @@ def test_create_job_should_call_api(
|
||||
'notification_count': notification_count,
|
||||
'valid': True}
|
||||
url = url_for('main.start_job', service_id=service_one['id'], upload_id=job_id)
|
||||
response = client.post(url, data={}, follow_redirects=True)
|
||||
response = client.post(url, data={'scheduled_for': when}, follow_redirects=True)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert original_file_name in response.get_data(as_text=True)
|
||||
mock_create_job.assert_called_with(job_id, service_id, template_id, original_file_name, notification_count)
|
||||
mock_create_job.assert_called_with(
|
||||
job_id,
|
||||
service_id,
|
||||
template_id,
|
||||
original_file_name,
|
||||
notification_count,
|
||||
scheduled_for=when
|
||||
)
|
||||
|
||||
|
||||
def test_check_messages_should_revalidate_file_when_uploading_file(
|
||||
|
||||
@@ -27,6 +27,21 @@ def test_client_creates_job_data_correctly(mocker, fake_uuid):
|
||||
mock_post.assert_called_once_with(url=expected_url, data=expected_data)
|
||||
|
||||
|
||||
def test_client_schedules_job(mocker, fake_uuid):
|
||||
|
||||
mocker.patch('app.notify_client.current_user', id='1')
|
||||
|
||||
mock_post = mocker.patch('app.notify_client.job_api_client.JobApiClient.post')
|
||||
|
||||
when = '2016-08-25T13:04:21.767198'
|
||||
|
||||
JobApiClient().create_job(
|
||||
fake_uuid, fake_uuid, fake_uuid, fake_uuid, 1, scheduled_for=when
|
||||
)
|
||||
|
||||
assert mock_post.call_args[1]['data']['scheduled_for'] == when
|
||||
|
||||
|
||||
def test_client_gets_job_by_service_and_job(mocker):
|
||||
mocker.patch('app.notify_client.current_user', id='1')
|
||||
|
||||
|
||||
@@ -837,7 +837,7 @@ def mock_check_verify_code_code_expired(mocker):
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_create_job(mocker, api_user_active):
|
||||
def _create(job_id, service_id, template_id, file_name, notification_count):
|
||||
def _create(job_id, service_id, template_id, file_name, notification_count, scheduled_for=None):
|
||||
return job_json(
|
||||
service_id,
|
||||
api_user_active,
|
||||
|
||||
Reference in New Issue
Block a user