update tests to reflect new code

also change jobs.py to filter out test jobs (since we dont need to see em)
and to use the new statuses filter rather than filtering on front end
This commit is contained in:
Leo Hemsted
2016-10-05 17:45:04 +01:00
parent 441a2717f2
commit aa458a15da
6 changed files with 53 additions and 32 deletions

View File

@@ -31,8 +31,10 @@ from app.utils import (
get_page_from_request,
generate_previous_next_dict,
user_has_permissions,
generate_notifications_csv)
from app.utils import get_help_argument
generate_notifications_csv,
get_help_argument
)
from app.statistics_utils import add_rate_to_job
def _parse_filter_args(filter_dict):
@@ -64,11 +66,18 @@ def _set_status_filters(filter_args):
@login_required
@user_has_permissions('view_activity', admin_override=True)
def view_jobs(service_id):
# all but scheduled and cancelled
statuses_to_display = [
'pending',
'in progress',
'finished',
'sending limits exceeded',
]
return render_template(
'views/jobs/jobs.html',
jobs=[
add_rate_to_job(job) for job in job_api_client.get_jobs(service_id)['data']
if job['job_status'] not in ['scheduled', 'cancelled']
add_rate_to_job(job) for job in job_api_client.get_jobs(service_id, statuses=statuses_to_display)['data']
if job['original_file_name'] != current_app.config['TEST_MESSAGE_FILENAME']
]
)

View File

@@ -159,7 +159,7 @@ def job_json(
notification_count=1,
notifications_sent=1,
notifications_requested=1,
job_status='Delivered',
job_status='finished',
scheduled_for=''
):
if job_id is None:

View File

@@ -182,7 +182,10 @@ def test_should_show_upcoming_jobs_on_dashboard(
client.login(api_user_active)
response = client.get(url_for('main.service_dashboard', service_id=SERVICE_ONE_ID))
mock_get_jobs.assert_called_once_with(SERVICE_ONE_ID, limit_days=7)
first_call = mock_get_jobs.call_args_list[0]
assert first_call[0] == (SERVICE_ONE_ID,)
assert first_call[1]['statuses'] == ['scheduled']
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
@@ -218,7 +221,10 @@ def test_should_show_recent_jobs_on_dashboard(
client.login(api_user_active)
response = client.get(url_for('main.service_dashboard', service_id=SERVICE_ONE_ID))
mock_get_jobs.assert_called_once_with(SERVICE_ONE_ID, limit_days=7)
second_call = mock_get_jobs.call_args_list[1]
assert second_call[0] == (SERVICE_ONE_ID,)
assert 'scheduled' not in second_call[1]['statuses']
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')

View File

@@ -12,11 +12,13 @@ from tests import notification_json
from freezegun import freeze_time
def test_should_return_list_of_all_jobs(app_,
service_one,
active_user_with_permissions,
mock_get_jobs,
mocker):
def test_should_return_list_of_all_real_jobs(
app_,
service_one,
active_user_with_permissions,
mock_get_jobs,
mocker
):
with app_.test_request_context():
with app_.test_client() as client:
client.login(active_user_with_permissions, mocker, service_one)
@@ -25,8 +27,9 @@ def test_should_return_list_of_all_jobs(app_,
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert page.h1.string == 'Uploaded files'
jobs = page.tbody.find_all('tr')
assert len(jobs) == 5
jobs = [x.text for x in page.tbody.find_all('a', {'class':'file-list-filename'})]
assert len(jobs) == 4
assert 'Test message' not in jobs
@pytest.mark.parametrize(

View File

@@ -1,3 +1,6 @@
import uuid
from unittest.mock import ANY
from app.notify_client.job_api_client import JobApiClient
@@ -51,8 +54,6 @@ def test_client_schedules_job(mocker, fake_uuid):
def test_client_gets_job_by_service_and_job(mocker):
mocker.patch('app.notify_client.current_user', id='1')
service_id = 'service_id'
job_id = 'job_id'
@@ -66,9 +67,15 @@ def test_client_gets_job_by_service_and_job(mocker):
mock_get.assert_called_once_with(url=expected_url, params={})
def test_client_parses_job_stats(mocker):
mocker.patch('app.notify_client.current_user', id='1')
def test_client_gets_jobs_with_status_filter(mocker):
mock_get = mocker.patch('app.notify_client.job_api_client.JobApiClient.get')
JobApiClient().get_jobs(uuid.uuid4(), statuses=['foo', 'bar'])
mock_get.assert_called_once_with(url=ANY, params={'statuses': 'foo,bar'})
def test_client_parses_job_stats(mocker):
service_id = 'service_id'
job_id = 'job_id'
expected_data = {'data': {
@@ -114,8 +121,6 @@ def test_client_parses_job_stats(mocker):
def test_client_parses_empty_job_stats(mocker):
mocker.patch('app.notify_client.current_user', id='1')
service_id = 'service_id'
job_id = 'job_id'
expected_data = {'data': {
@@ -152,8 +157,6 @@ def test_client_parses_empty_job_stats(mocker):
def test_client_parses_job_stats_for_service(mocker):
mocker.patch('app.notify_client.current_user', id='1')
service_id = 'service_id'
job_1_id = 'job_id_1'
job_2_id = 'job_id_2'
@@ -232,8 +235,6 @@ def test_client_parses_job_stats_for_service(mocker):
def test_client_parses_empty_job_stats_for_service(mocker):
mocker.patch('app.notify_client.current_user', id='1')
service_id = 'service_id'
job_1_id = 'job_id_1'
job_2_id = 'job_id_2'
@@ -294,7 +295,6 @@ def test_client_parses_empty_job_stats_for_service(mocker):
def test_cancel_job(mocker):
mock_post = mocker.patch('app.notify_client.job_api_client.JobApiClient.post')
JobApiClient().cancel_job('service_id', 'job_id')

View File

@@ -902,7 +902,10 @@ def mock_get_job_in_progress(mocker, api_user_active):
@pytest.fixture(scope='function')
def mock_get_jobs(mocker, api_user_active):
def _get_jobs(service_id, limit_days=None, statuses=None):
return {"data": [
if statuses is None:
statuses = ['', 'scheduled', 'pending', 'cancelled']
jobs = [
job_json(
service_id,
api_user_active,
@@ -911,17 +914,17 @@ def mock_get_jobs(mocker, api_user_active):
job_status=job_status
)
for filename, scheduled_for, job_status in (
("Test message", '', ''),
("Test message", '2016-01-01 11:09:00.061258', 'scheduled'),
("export 1/1/2016.xls", '', ''),
("Test message", '', 'finished'),
("export 1/1/2016.xls", '', 'finished'),
("all email addresses.xlsx", '', 'pending'),
("applicants.ods", '', ''),
("thisisatest.csv", '', ''),
("applicants.ods", '', 'finished'),
("thisisatest.csv", '', 'finished'),
("send_me_later.csv", '2016-01-01 11:09:00.061258', 'scheduled'),
("even_later.csv", '2016-01-01 23:09:00.061258', 'scheduled'),
("full_of_regret.csv", '2016-01-01 23:09:00.061258', 'cancelled')
)
]}
]
return {"data": [job for job in jobs if job['job_status'] in statuses]}
return mocker.patch('app.job_api_client.get_jobs', side_effect=_get_jobs)