Skip to content

Commit

Permalink
add mock_emanifest_auth_responses, test builds the search
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgraham4401 committed May 11, 2024
1 parent ba382cf commit 41407ae
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
9 changes: 9 additions & 0 deletions server/apps/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,15 @@ def mock_responses():
yield mock_responses


@pytest.fixture()
def mock_emanifest_auth_response(request, mock_responses):
api_id, api_key = request.param
mock_responses.get(
f"https://rcrainfopreprod.epa.gov/rcrainfo/rest/api/v1/auth/{api_id}/{api_key}",
body='{"token": "mocK_token", "expiration": "2021-01-01T00:00:00.000000Z"}',
)


@pytest.fixture
def mocker(mocker: pytest_mock.MockerFixture):
"""
Expand Down
26 changes: 21 additions & 5 deletions server/apps/manifest/tests/test_search_emanifest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from datetime import datetime, timezone
from unittest.mock import Mock, patch

Expand Down Expand Up @@ -54,18 +55,33 @@ def test_defaults_to_unauthenticated_rcra_client(self):
assert search.rcra_client is not None
assert search.rcra_client.is_authenticated is False

def test_execute_sends_a_request_to_rcrainfo(self, mock_responses):
@pytest.mark.parametrize("mock_emanifest_auth_response", [["foo", "foo"]], indirect=True)
def test_execute_sends_a_request_to_rcrainfo(
self, mock_responses, mock_emanifest_auth_response
):
stub_rcra_client = RcrainfoService(rcrainfo_env="preprod", api_key="foo", api_id="foo")
mock_responses.get(
"https://rcrainfopreprod.epa.gov/rcrainfo/rest/api/v1/auth/foo/foo",
body='{"token": "mocK_token", "expiration": "2021-01-01T00:00:00.000000Z"}',
)
mock_responses.post(
"https://rcrainfopreprod.epa.gov/rcrainfo/rest/api/v1/emanifest/search"
)
result = EmanifestSearch(stub_rcra_client).execute()
assert result.status_code == 200

@pytest.mark.parametrize("mock_emanifest_auth_response", [["foo", "foo"]], indirect=True)
def test_search_builds_json(self, mock_responses, mock_emanifest_auth_response):
stub_rcra_client = RcrainfoService(rcrainfo_env="preprod", api_key="foo", api_id="foo")
mock_responses.post(
"https://rcrainfopreprod.epa.gov/rcrainfo/rest/api/v1/emanifest/search"
)
EmanifestSearch(stub_rcra_client).add_state_code("CA").add_site_type(
"Generator"
).add_site_id("VATESTGEN001").execute()
for call in mock_responses.calls:
if "emanifest/search" in call.request.url:
request_body = json.loads(call.request.body)
assert request_body["stateCode"] == "CA"
assert request_body["siteType"] == "Generator"
assert request_body["siteId"] == "VATESTGEN001"

class TestBuildSearchWithStateCode:
def test_add_state_code(self):
search = EmanifestSearch().add_state_code("CA")
Expand Down

0 comments on commit 41407ae

Please sign in to comment.