Skip to content

Commit

Permalink
test: Mock requests.codes.ok
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Sep 16, 2024
1 parent 6034bf7 commit b347c0b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,16 @@ def url_obj_w_files(url_obj, dataset, analyzed):

@pytest.fixture
def mocked_request(mocker, url_obj):
request = mocker.patch("core.tasks.requests")
mock = mocker.patch("core.tasks.requests")
path = os.path.dirname(__file__) + "/data/sample-dataset.json"
with open(path) as f:
data = f.read()
response = Response(body=data)
request.get.return_value = response
yield request
mock.get.return_value = response
codes = mocker.MagicMock()
type(codes).ok = mocker.PropertyMock(return_value=200)
type(mock).codes = mocker.PropertyMock(return_value=codes)
mocker.seal(mock)
yield mock

shutil.rmtree(os.path.join(settings.MEDIA_ROOT, str(url_obj.id)), ignore_errors=True)

0 comments on commit b347c0b

Please sign in to comment.