def test_should_show_cancel_link_for_letter_job( client_request, mocker, mock_get_service_letter_template, mock_get_service_data_retention, active_user_with_permissions, job_status, ): job_id = uuid.uuid4() job = job_json(SERVICE_ONE_ID, active_user_with_permissions, job_id=job_id, created_at="2019-06-20T15:30:00.000001+00:00", job_status=job_status) notifications_json = notification_json(SERVICE_ONE_ID, job=job, status="created", template_type="letter") mocker.patch('app.job_api_client.get_job', side_effect=[{"data": job}]) mocker.patch('app.notification_api_client.get_notifications_for_service', side_effect=[notifications_json]) page = client_request.get('main.view_job', service_id=SERVICE_ONE_ID, job_id=str(job_id)) assert page.find( 'a', text='Cancel sending these letters').attrs["href"] == url_for( "main.cancel_letter_job", service_id=SERVICE_ONE_ID, job_id=job_id) assert page.find('p', { 'id': 'printing-info' }).text.strip() == "Printing starts today at 5:30pm"
def test_should_not_show_cancel_link_for_letter_job_if_too_late( client_request, mocker, mock_get_service_letter_template, mock_get_service_data_retention, active_user_with_permissions, job_created_at, expected_fragment, ): job_id = uuid.uuid4() job = job_json(SERVICE_ONE_ID, active_user_with_permissions, job_id=job_id, created_at=job_created_at) notifications_json = notification_json(SERVICE_ONE_ID, job=job, status="created", template_type="letter") mocker.patch('app.job_api_client.get_job', side_effect=[{"data": job}]) mocker.patch('app.notification_api_client.get_notifications_for_service', side_effect=[notifications_json]) page = client_request.get('main.view_job', service_id=SERVICE_ONE_ID, job_id=str(job_id)) assert "Cancel sending these letters" not in page assert page.find('p', { 'id': 'printing-info' }).text.strip() == "Printed {} at 5:30pm".format(expected_fragment)
def test_should_cancel_letter_job(client_request, mocker, active_user_with_permissions): job_id = uuid.uuid4() job = job_json(SERVICE_ONE_ID, active_user_with_permissions, job_id=job_id, created_at="2019-06-20T15:30:00.000001+00:00", job_status="finished") mocker.patch('app.job_api_client.get_job', side_effect=[{"data": job}]) notifications_json = notification_json(SERVICE_ONE_ID, job=job, status="created", template_type="letter") mocker.patch('app.job_api_client.get_job', side_effect=[{"data": job}]) mocker.patch('app.notification_api_client.get_notifications_for_service', side_effect=[notifications_json]) mock_cancel = mocker.patch( 'app.main.jobs.job_api_client.cancel_letter_job', return_value=5) client_request.post('main.cancel_letter_job', service_id=SERVICE_ONE_ID, job_id=job_id, _expected_status=302, _expected_redirect=url_for( 'main.service_dashboard', service_id=SERVICE_ONE_ID, _external=True, )) mock_cancel.assert_called_once_with(SERVICE_ONE_ID, job_id)
def test_should_show_old_job( client_request, service_one, active_user_with_permissions, mock_get_service_template, mocker, mock_get_notifications_with_no_notifications, mock_get_service_data_retention, fake_uuid, created_at, processing_started, expected_message, ): mocker.patch( 'app.job_api_client.get_job', return_value={ "data": job_json( SERVICE_ONE_ID, active_user_with_permissions, created_at=created_at.replace(tzinfo=timezone.utc).isoformat(), processing_started=(processing_started.replace( tzinfo=timezone.utc).isoformat() if processing_started else None), ), }) page = client_request.get( 'main.view_job', service_id=SERVICE_ONE_ID, job_id=fake_uuid, ) assert not page.select('.pill a') assert not page.select('p.hint') assert not page.select('a[download]') assert page.select_one('tbody').text.strip() == expected_message
def test_should_show_updates_for_scheduled_job_as_json( logged_in_client, service_one, active_user_with_permissions, mock_get_notifications, mock_get_service_template, mock_get_service_data_retention, mocker, fake_uuid, ): mocker.patch('app.job_api_client.get_job', return_value={'data': job_json( service_one['id'], created_by=user_json(), job_id=fake_uuid, scheduled_for='2016-06-01T13:00:00+00:00', processing_started='2016-06-01T15:00:00+00:00', )}) response = logged_in_client.get(url_for('main.view_job_updates', service_id=service_one['id'], job_id=fake_uuid)) assert response.status_code == 200 content = response.json assert 'sending' in content['counts'] assert 'delivered' in content['counts'] assert 'failed' in content['counts'] assert 'Recipient' in content['notifications'] assert '07123456789' in content['notifications'] assert 'Status' in content['notifications'] assert 'Delivered' in content['notifications'] assert '12:01am' in content['notifications'] assert 'Sent by Test User on 1 June at 4:00pm' in content['status']
def test_dont_cancel_letter_job_when_to_early_to_cancel( client_request, mocker, mock_get_service_letter_template, mock_get_service_data_retention, active_user_with_permissions, job_status, number_of_processed_notifications, ): job_id = uuid.uuid4() job = job_json(SERVICE_ONE_ID, active_user_with_permissions, job_id=job_id, created_at="2019-06-20T15:30:00.000001+00:00", job_status=job_status, notification_count=2) mocker.patch('app.job_api_client.get_job', side_effect=[{ "data": job }, { "data": job }]) notifications_json = notification_json( SERVICE_ONE_ID, job=job, status="created", template_type="letter", rows=number_of_processed_notifications) mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications_json) mocker.patch( 'app.notification_api_client.get_notification_count_for_job_id', return_value=number_of_processed_notifications) mock_cancel = mocker.patch('app.job_api_client.cancel_letter_job') page = client_request.post( 'main.cancel_letter_job', service_id=SERVICE_ONE_ID, job_id=str(job_id), _expected_status=200, ) mock_cancel.assert_not_called() flash_message = normalize_spaces( page.find('div', class_='banner-dangerous').text) assert 'We are still processing these letters, please try again in a minute.' in flash_message