-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring crime incidents, moved former unit test into integration …
…tests Closes #194
- Loading branch information
Showing
3 changed files
with
54 additions
and
32 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
mycity/mycity/test/integration_tests/test_crime_incidents_api_utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import unittest | ||
import unittest.mock as mock | ||
import requests | ||
from mycity.utilities.crime_incidents_api_utils import get_crime_incident_response | ||
|
||
|
||
class CrimeIncidentsAPIUtilitiesTestCase(unittest.TestCase): | ||
|
||
def test_get_crime_incident_response_returns_success_if_query_is_successful(self): | ||
test_address = "46 Everdean St Boston, MA" | ||
result = get_crime_incident_response(test_address) | ||
self.assertEqual(True, result['success']) |
39 changes: 19 additions & 20 deletions
39
mycity/mycity/test/unit_tests/test_crime_incidents_api_utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,23 @@ | ||
import unittest | ||
import unittest.mock as mock | ||
import mycity.test.test_constants as test_constants | ||
import mycity.test.unit_tests.base as base | ||
from mycity.utilities.crime_incidents_api_utils import \ | ||
get_crime_incident_response | ||
import requests | ||
from mycity.utilities.crime_incidents_api_utils import get_crime_incident_response | ||
|
||
class CrimeIncidentsAPIUtilitiesTestCase(base.BaseTestCase): | ||
|
||
@mock.patch( | ||
'mycity.utilities.gis_utils.geocode_address', | ||
return_value=test_constants.GEOCODE_ADDRESS_MOCK | ||
) | ||
@mock.patch('requests.get') | ||
def test_get_crime_incident_response(self, mock_geocode_address, mock_get): | ||
mock_resp = self._mock_response(status=200, | ||
json_data=test_constants.GET_CRIME_INCIDENTS_API_MOCK) | ||
mock_get.return_value = mock_resp | ||
class CrimeIncidentsAPIUtilitiesTestCase(unittest.TestCase): | ||
|
||
test_address = "46 Everdean St Boston, MA" | ||
result = get_crime_incident_response(test_address) | ||
self.assertEqual( | ||
True, | ||
result['success'] | ||
) | ||
def test_get_crime_incident_response_returns_empty_dict_if_request_fails(self): | ||
test_session = mock.MagicMock() | ||
test_session.response = mock.MagicMock() | ||
test_session.response.status_code = requests.codes.bad | ||
to_test = get_crime_incident_response('46 Everdean St.', test_session) | ||
self.assertEquals({}, to_test) | ||
|
||
def test_get_crime_incident_response_returns_json_if_request_succeeds(self): | ||
expected = 1 | ||
test_session = mock.MagicMock() | ||
test_session.response = mock.MagicMock() | ||
test_session.response.status_code = requests.codes.ok | ||
test_session.response.json = lambda: expected | ||
to_test = get_crime_incident_response('46 Everdean St.', test_session) | ||
self.assertEquals(expected, to_test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters