Skip to content

Commit

Permalink
[#56] flake8 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jo committed Sep 24, 2019
1 parent e638cec commit cfb40b1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
1 change: 0 additions & 1 deletion invisible_flow/storage/local_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def store_string(self, filename, file_content: str, path: str):

pathlib.Path(dir_path).mkdir(exist_ok=True, parents=True)
with open(os.path.join(dir_path, filename), 'wb') as file:
print("&&&&&&&&&&&&&", type(file_content), file_content.encode('utf-8'))
file.write(file_content.encode('utf-8'))
file.close()

Expand Down
31 changes: 21 additions & 10 deletions tests/api/test_copa_scrape.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import unittest

from unittest import mock

import pytest

from invisible_flow.api import CopaScrape
from invisible_flow.constants import SCRAPE_URL

response_code = 200


def mocked_requests_get(**kwargs):
class MockResponse:
Expand All @@ -16,28 +18,37 @@ def __init__(self, json_data, status_code, content):
def json(self):
return self.json_data
if kwargs == {"url": SCRAPE_URL + ".csv"}:
return MockResponse({"key1": "value1"}, 200, "bubbles")
return MockResponse({"key1": "value1"}, response_code, "bubbles")
elif kwargs == {"url": SCRAPE_URL + ".json"}:
return MockResponse({"key1": "value1"}, 200, "bubbles")
return MockResponse({"key1": "value1"}, response_code, "bubbles")
elif kwargs == {"url": SCRAPE_URL + ".csv?$where=assignment=\"COPA\""}:
return MockResponse({"key1": "value1"}, 200, "bubbles")
return MockResponse({"key1": "value1"}, response_code, "bubbles")
elif kwargs == {"url": SCRAPE_URL + ".csv?$where=assignment!=\"COPA\""}:
return MockResponse({"key1": "value1"}, 200, "bubbles")
return MockResponse({"key1": "value1"}, response_code, "bubbles")
elif kwargs == {"url": SCRAPE_URL + ".csv?$select=log_no,complaint_date,beat&$where=assignment=\"COPA\""}:
return MockResponse({"key1": "value1"}, 200, "bubbles")
return MockResponse({"key1": "value1"}, response_code, "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({"key1": "value1"}, response_code, "bubbles")

return MockResponse(None, 404, None)


@mock.patch('requests.get', side_effect=mocked_requests_get)
class TestCopaScrape(unittest.TestCase):
@pytest.fixture(
scope="class",
autouse=True,
params=[200, 404]
)
def default_fixture(request):
global response_code
response_code = request.param


@mock.patch('requests.get', side_effect=mocked_requests_get)
class TestCopaScrape():
def test_scrape_data_csv(self, get_mock):
should_be_bubbles = CopaScrape().scrape_data_csv()
assert should_be_bubbles == "bubbles"
Expand Down

0 comments on commit cfb40b1

Please sign in to comment.