mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
Add tests for get_complaint_count endpoint
* Added unit tests for the get_complaint_count endpoint * Updated the schema to use 'date' format instead of 'datetime' * Updated the complaint endpoint to convert start_date and end_date to be dates instead of strings
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
from datetime import date
|
||||
import json
|
||||
|
||||
from flask import url_for
|
||||
from freezegun import freeze_time
|
||||
|
||||
from tests import create_authorization_header
|
||||
from tests.app.db import create_complaint, create_service, create_template, create_notification
|
||||
|
||||
@@ -22,3 +26,39 @@ def test_get_all_complaints_returns_empty_list(client):
|
||||
|
||||
assert response.status_code == 200
|
||||
assert json.loads(response.get_data(as_text=True)) == []
|
||||
|
||||
|
||||
def test_get_complaint_with_start_and_end_date_passes_these_to_dao_function(mocker, client):
|
||||
start_date = date(2018, 6, 11)
|
||||
end_date = date(2018, 6, 11)
|
||||
dao_mock = mocker.patch('app.complaint.complaint_rest.fetch_count_of_complaints', return_value=3)
|
||||
response = client.get(
|
||||
url_for('complaint.get_complaint_count', start_date=start_date, end_date=end_date),
|
||||
headers=[create_authorization_header()]
|
||||
)
|
||||
|
||||
dao_mock.assert_called_once_with(start_date=start_date, end_date=end_date)
|
||||
assert response.status_code == 200
|
||||
assert json.loads(response.get_data(as_text=True)) == 3
|
||||
|
||||
|
||||
@freeze_time("2018-06-01 11:00:00")
|
||||
def test_get_complaint_sets_start_and_end_date_to_today_if_not_specified(mocker, client):
|
||||
dao_mock = mocker.patch('app.complaint.complaint_rest.fetch_count_of_complaints', return_value=5)
|
||||
response = client.get(url_for('complaint.get_complaint_count'), headers=[create_authorization_header()])
|
||||
|
||||
dao_mock.assert_called_once_with(start_date=date.today(), end_date=date.today())
|
||||
assert response.status_code == 200
|
||||
assert json.loads(response.get_data(as_text=True)) == 5
|
||||
|
||||
|
||||
def test_get_complaint_with_invalid_data_returns_400_status_code(client):
|
||||
start_date = '1234-56-78'
|
||||
response = client.get(
|
||||
url_for('complaint.get_complaint_count', start_date=start_date),
|
||||
headers=[create_authorization_header()]
|
||||
)
|
||||
|
||||
assert response.status_code == 400
|
||||
assert response.json['errors'][0]['message'] == 'start_date time data {} does not match format %Y-%m-%d'.format(
|
||||
start_date)
|
||||
|
||||
Reference in New Issue
Block a user