mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-11 10:28:41 -04:00
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:
+13
-4
@@ -31,8 +31,10 @@ from app.utils import (
|
|||||||
get_page_from_request,
|
get_page_from_request,
|
||||||
generate_previous_next_dict,
|
generate_previous_next_dict,
|
||||||
user_has_permissions,
|
user_has_permissions,
|
||||||
generate_notifications_csv)
|
generate_notifications_csv,
|
||||||
from app.utils import get_help_argument
|
get_help_argument
|
||||||
|
)
|
||||||
|
from app.statistics_utils import add_rate_to_job
|
||||||
|
|
||||||
|
|
||||||
def _parse_filter_args(filter_dict):
|
def _parse_filter_args(filter_dict):
|
||||||
@@ -64,11 +66,18 @@ def _set_status_filters(filter_args):
|
|||||||
@login_required
|
@login_required
|
||||||
@user_has_permissions('view_activity', admin_override=True)
|
@user_has_permissions('view_activity', admin_override=True)
|
||||||
def view_jobs(service_id):
|
def view_jobs(service_id):
|
||||||
|
# all but scheduled and cancelled
|
||||||
|
statuses_to_display = [
|
||||||
|
'pending',
|
||||||
|
'in progress',
|
||||||
|
'finished',
|
||||||
|
'sending limits exceeded',
|
||||||
|
]
|
||||||
return render_template(
|
return render_template(
|
||||||
'views/jobs/jobs.html',
|
'views/jobs/jobs.html',
|
||||||
jobs=[
|
jobs=[
|
||||||
add_rate_to_job(job) for job in job_api_client.get_jobs(service_id)['data']
|
add_rate_to_job(job) for job in job_api_client.get_jobs(service_id, statuses=statuses_to_display)['data']
|
||||||
if job['job_status'] not in ['scheduled', 'cancelled']
|
if job['original_file_name'] != current_app.config['TEST_MESSAGE_FILENAME']
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -159,7 +159,7 @@ def job_json(
|
|||||||
notification_count=1,
|
notification_count=1,
|
||||||
notifications_sent=1,
|
notifications_sent=1,
|
||||||
notifications_requested=1,
|
notifications_requested=1,
|
||||||
job_status='Delivered',
|
job_status='finished',
|
||||||
scheduled_for=''
|
scheduled_for=''
|
||||||
):
|
):
|
||||||
if job_id is None:
|
if job_id is None:
|
||||||
|
|||||||
@@ -182,7 +182,10 @@ def test_should_show_upcoming_jobs_on_dashboard(
|
|||||||
client.login(api_user_active)
|
client.login(api_user_active)
|
||||||
response = client.get(url_for('main.service_dashboard', service_id=SERVICE_ONE_ID))
|
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
|
assert response.status_code == 200
|
||||||
|
|
||||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
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)
|
client.login(api_user_active)
|
||||||
response = client.get(url_for('main.service_dashboard', service_id=SERVICE_ONE_ID))
|
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
|
assert response.status_code == 200
|
||||||
|
|
||||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||||
|
|||||||
@@ -12,11 +12,13 @@ from tests import notification_json
|
|||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
|
|
||||||
|
|
||||||
def test_should_return_list_of_all_jobs(app_,
|
def test_should_return_list_of_all_real_jobs(
|
||||||
|
app_,
|
||||||
service_one,
|
service_one,
|
||||||
active_user_with_permissions,
|
active_user_with_permissions,
|
||||||
mock_get_jobs,
|
mock_get_jobs,
|
||||||
mocker):
|
mocker
|
||||||
|
):
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(active_user_with_permissions, mocker, service_one)
|
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
|
assert response.status_code == 200
|
||||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||||
assert page.h1.string == 'Uploaded files'
|
assert page.h1.string == 'Uploaded files'
|
||||||
jobs = page.tbody.find_all('tr')
|
jobs = [x.text for x in page.tbody.find_all('a', {'class':'file-list-filename'})]
|
||||||
assert len(jobs) == 5
|
assert len(jobs) == 4
|
||||||
|
assert 'Test message' not in jobs
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import uuid
|
||||||
|
from unittest.mock import ANY
|
||||||
|
|
||||||
from app.notify_client.job_api_client import JobApiClient
|
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):
|
def test_client_gets_job_by_service_and_job(mocker):
|
||||||
mocker.patch('app.notify_client.current_user', id='1')
|
|
||||||
|
|
||||||
service_id = 'service_id'
|
service_id = 'service_id'
|
||||||
job_id = 'job_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={})
|
mock_get.assert_called_once_with(url=expected_url, params={})
|
||||||
|
|
||||||
|
|
||||||
def test_client_parses_job_stats(mocker):
|
def test_client_gets_jobs_with_status_filter(mocker):
|
||||||
mocker.patch('app.notify_client.current_user', id='1')
|
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'
|
service_id = 'service_id'
|
||||||
job_id = 'job_id'
|
job_id = 'job_id'
|
||||||
expected_data = {'data': {
|
expected_data = {'data': {
|
||||||
@@ -114,8 +121,6 @@ def test_client_parses_job_stats(mocker):
|
|||||||
|
|
||||||
|
|
||||||
def test_client_parses_empty_job_stats(mocker):
|
def test_client_parses_empty_job_stats(mocker):
|
||||||
mocker.patch('app.notify_client.current_user', id='1')
|
|
||||||
|
|
||||||
service_id = 'service_id'
|
service_id = 'service_id'
|
||||||
job_id = 'job_id'
|
job_id = 'job_id'
|
||||||
expected_data = {'data': {
|
expected_data = {'data': {
|
||||||
@@ -152,8 +157,6 @@ def test_client_parses_empty_job_stats(mocker):
|
|||||||
|
|
||||||
|
|
||||||
def test_client_parses_job_stats_for_service(mocker):
|
def test_client_parses_job_stats_for_service(mocker):
|
||||||
mocker.patch('app.notify_client.current_user', id='1')
|
|
||||||
|
|
||||||
service_id = 'service_id'
|
service_id = 'service_id'
|
||||||
job_1_id = 'job_id_1'
|
job_1_id = 'job_id_1'
|
||||||
job_2_id = 'job_id_2'
|
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):
|
def test_client_parses_empty_job_stats_for_service(mocker):
|
||||||
mocker.patch('app.notify_client.current_user', id='1')
|
|
||||||
|
|
||||||
service_id = 'service_id'
|
service_id = 'service_id'
|
||||||
job_1_id = 'job_id_1'
|
job_1_id = 'job_id_1'
|
||||||
job_2_id = 'job_id_2'
|
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):
|
def test_cancel_job(mocker):
|
||||||
|
|
||||||
mock_post = mocker.patch('app.notify_client.job_api_client.JobApiClient.post')
|
mock_post = mocker.patch('app.notify_client.job_api_client.JobApiClient.post')
|
||||||
|
|
||||||
JobApiClient().cancel_job('service_id', 'job_id')
|
JobApiClient().cancel_job('service_id', 'job_id')
|
||||||
|
|||||||
+10
-7
@@ -902,7 +902,10 @@ def mock_get_job_in_progress(mocker, api_user_active):
|
|||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def mock_get_jobs(mocker, api_user_active):
|
def mock_get_jobs(mocker, api_user_active):
|
||||||
def _get_jobs(service_id, limit_days=None, statuses=None):
|
def _get_jobs(service_id, limit_days=None, statuses=None):
|
||||||
return {"data": [
|
if statuses is None:
|
||||||
|
statuses = ['', 'scheduled', 'pending', 'cancelled']
|
||||||
|
|
||||||
|
jobs = [
|
||||||
job_json(
|
job_json(
|
||||||
service_id,
|
service_id,
|
||||||
api_user_active,
|
api_user_active,
|
||||||
@@ -911,17 +914,17 @@ def mock_get_jobs(mocker, api_user_active):
|
|||||||
job_status=job_status
|
job_status=job_status
|
||||||
)
|
)
|
||||||
for filename, scheduled_for, job_status in (
|
for filename, scheduled_for, job_status in (
|
||||||
("Test message", '', ''),
|
("Test message", '', 'finished'),
|
||||||
("Test message", '2016-01-01 11:09:00.061258', 'scheduled'),
|
("export 1/1/2016.xls", '', 'finished'),
|
||||||
("export 1/1/2016.xls", '', ''),
|
|
||||||
("all email addresses.xlsx", '', 'pending'),
|
("all email addresses.xlsx", '', 'pending'),
|
||||||
("applicants.ods", '', ''),
|
("applicants.ods", '', 'finished'),
|
||||||
("thisisatest.csv", '', ''),
|
("thisisatest.csv", '', 'finished'),
|
||||||
("send_me_later.csv", '2016-01-01 11:09:00.061258', 'scheduled'),
|
("send_me_later.csv", '2016-01-01 11:09:00.061258', 'scheduled'),
|
||||||
("even_later.csv", '2016-01-01 23: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')
|
("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)
|
return mocker.patch('app.job_api_client.get_jobs', side_effect=_get_jobs)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user