Fix assertions when we catch an error in the tests

Code that is within a `with Python.raises(...)` context manager but
comes after the line that raises the exception doesn't get evaluated.
We had some assertions that we never being tested because of this, so
this ensures that they will always get run and fixes them where
necessary.
This commit is contained in:
Katie Smith
2019-09-13 11:40:05 +01:00
parent f9f9092b5c
commit 09e8ac9644
8 changed files with 23 additions and 19 deletions

View File

@@ -97,8 +97,8 @@ def test_validate_date_range_is_within_a_financial_year(start_date, end_date):
def test_validate_date_range_is_within_a_financial_year_raises(start_date, end_date):
with pytest.raises(expected_exception=InvalidRequest) as e:
validate_date_range_is_within_a_financial_year(start_date, end_date)
assert e.message == 'Date must be in a single financial year.'
assert e.code == 400
assert e.value.message == 'Date must be in a single financial year.'
assert e.value.status_code == 400
def test_validate_date_is_within_a_financial_year_raises_validation_error():
@@ -107,8 +107,8 @@ def test_validate_date_is_within_a_financial_year_raises_validation_error():
with pytest.raises(expected_exception=InvalidRequest) as e:
validate_date_range_is_within_a_financial_year(start_date, end_date)
assert e.message == 'Start date must be before end date'
assert e.code == 400
assert e.value.message == 'Start date must be before end date'
assert e.value.status_code == 400
@pytest.mark.parametrize('start_date, end_date',
@@ -116,9 +116,9 @@ def test_validate_date_is_within_a_financial_year_raises_validation_error():
('2019-07-01', 'not-date')])
def test_validate_date_is_within_a_financial_year_when_input_is_not_a_date(start_date, end_date):
with pytest.raises(expected_exception=InvalidRequest) as e:
assert validate_date_range_is_within_a_financial_year(start_date, end_date)
assert e.message == 'Input must be a date in the format: YYYY-MM-DD'
assert e.code == 400
validate_date_range_is_within_a_financial_year(start_date, end_date)
assert e.value.message == 'Input must be a date in the format: YYYY-MM-DD'
assert e.value.status_code == 400
def test_get_usage_for_all_services(notify_db_session, admin_request):