-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#56] WIP: Added test file for copa_scrape, called test_copa_scrape
- Loading branch information
1 parent
3f36a26
commit f0a7f85
Showing
4 changed files
with
64 additions
and
57 deletions.
There are no files selected for viewing
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
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
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,63 @@ | ||
import unittest | ||
|
||
from unittest import mock | ||
|
||
from invisible_flow.api import CopaScrape | ||
from invisible_flow.constants import SCRAPE_URL | ||
|
||
|
||
def mocked_requests_get(**kwargs): | ||
class MockResponse: | ||
def __init__(self, json_data, status_code, content): | ||
self.json_data = json_data | ||
self.status_code = status_code | ||
self.content = content | ||
|
||
def json(self): | ||
return self.json_data | ||
if kwargs == {"url": SCRAPE_URL + ".csv"}: | ||
return MockResponse({"key1": "value1"}, 200, "bubbles") | ||
elif kwargs == {"url": SCRAPE_URL + ".json"}: | ||
return MockResponse({"key1": "value1"}, 200, "bubbles") | ||
elif kwargs == {"url": SCRAPE_URL + ".csv?$where=assignment=\"COPA\""}: | ||
return MockResponse({"key1": "value1"}, 200, "bubbles") | ||
elif kwargs == {"url": SCRAPE_URL + ".csv?$where=assignment!=\"COPA\""}: | ||
return MockResponse({"key1": "value1"}, 200, "bubbles") | ||
elif kwargs == {"url": SCRAPE_URL + ".csv?$select=log_no,complaint_date,beat&$where=assignment!=\"COPA\""}: | ||
return MockResponse({"key1": "value1"}, 200, "bubbles") | ||
elif kwargs == {"url": SCRAPE_URL + ".csv?$select=log_no,assignment,case_type,current_status,current_category," | ||
"finding_code,police_shooting,race_of_complainants,sex_of_complainants,age_of_complainants," | ||
"race_of_involved_officers,sex_of_involved_officers,age_of_involved_officers," | ||
"years_on_force_of_officers,complaint_hour,complaint_day,complaint_month&" | ||
"$where=assignment!=\"COPA\""}: | ||
return MockResponse({"key1": "value1"}, 200, "bubbles") | ||
|
||
return MockResponse(None, 404, None) | ||
|
||
|
||
@mock.patch('requests.get', side_effect=mocked_requests_get) | ||
class TestCopaScrape(unittest.TestCase): | ||
|
||
def test_scrape_data_csv(self, get_mock): | ||
should_be_bubbles = CopaScrape().scrape_data_csv() | ||
assert should_be_bubbles == "bubbles" | ||
|
||
def test_scrape_data_json(self, get_mock): | ||
should_be_json_data = CopaScrape().scrape_data_json() | ||
assert should_be_json_data == {"key1": "value1"} | ||
|
||
def test_scrape_copa_csv(self, get_mock): | ||
should_be_bubbles = CopaScrape().scrape_copa_csv() | ||
assert should_be_bubbles == "bubbles" | ||
|
||
def test_scrape_not_copa_csv(self, get_mock): | ||
should_be_bubbles = CopaScrape().scrape_not_copa_csv() | ||
assert should_be_bubbles == "bubbles" | ||
|
||
def test_scrape_copa_ready_for_entity(self, get_mock): | ||
should_be_bubbles = CopaScrape().scrape_copa_ready_for_entity() | ||
assert should_be_bubbles == "bubbles" | ||
|
||
def test_scrape_copa_not_in_entity(self, get_mock): | ||
should_be_bubbles = CopaScrape().scrape_copa_not_in_entity() | ||
assert should_be_bubbles == "bubbles" |
This file was deleted.
Oops, something went wrong.