mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-06-27 10:50:30 -04:00
Add tests for time_left
This commit extracts the code that works out the ‘Data available for…’ message so that it’s easy to unit test for.
This commit is contained in:
@@ -320,19 +320,23 @@ def get_job_partials(job):
|
||||
status=request.args.get('status', '')
|
||||
),
|
||||
help=get_help_argument(),
|
||||
time_left=ago.human(
|
||||
(
|
||||
datetime.now(timezone.utc).replace(hour=23, minute=59, second=59)
|
||||
) - (
|
||||
dateutil.parser.parse(job['created_at']) + timedelta(days=8)
|
||||
),
|
||||
future_tense='Data available for {}',
|
||||
past_tense='Was available {} ago', # No-one should ever see this
|
||||
precision=1
|
||||
)
|
||||
time_left=get_time_left(job['created_at'])
|
||||
),
|
||||
'status': render_template(
|
||||
'partials/jobs/status.html',
|
||||
job=job
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def get_time_left(job_created_at):
|
||||
return ago.human(
|
||||
(
|
||||
datetime.now(timezone.utc).replace(hour=23, minute=59, second=59)
|
||||
) - (
|
||||
dateutil.parser.parse(job_created_at) + timedelta(days=8)
|
||||
),
|
||||
future_tense='Data available for {}',
|
||||
past_tense='Data no longer available', # No-one should ever see this
|
||||
precision=1
|
||||
)
|
||||
|
||||
@@ -3,6 +3,7 @@ from flask import url_for
|
||||
from bs4 import BeautifulSoup
|
||||
import json
|
||||
from app.utils import generate_notifications_csv
|
||||
from app.main.views.jobs import get_time_left
|
||||
from tests import (notification_json, job_json)
|
||||
from tests.conftest import fake_uuid
|
||||
from tests.conftest import mock_get_job as mock_get_job1
|
||||
@@ -300,3 +301,16 @@ def test_should_download_notifications_for_a_job(app_,
|
||||
assert response.get_data(as_text=True) == csv_content
|
||||
assert 'text/csv' in response.headers['Content-Type']
|
||||
assert 'sample template - 1 January at 11:09.csv"' in response.headers['Content-Disposition']
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"job_created_at, expected_message", [
|
||||
("2016-01-10 11:09:00.000000+00:00", "Data available for 7 days"),
|
||||
("2016-01-04 11:09:00.000000+00:00", "Data available for 1 day"),
|
||||
("2016-01-03 11:09:00.000000+00:00", "Data available for 11 hours"),
|
||||
("2016-01-02 23:59:59.000000+00:00", "Data no longer available")
|
||||
]
|
||||
)
|
||||
@freeze_time("2016-01-10 12:00:00.000000")
|
||||
def test_time_left(job_created_at, expected_message):
|
||||
assert get_time_left(job_created_at) == expected_message
|
||||
|
||||
Reference in New Issue
Block a user