Skip to content

Commit

Permalink
further setup of mocked unit test for UAT access
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfromearth committed Mar 19, 2024
1 parent 6b27039 commit 301568c
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions tests/unit/test_uat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from unittest import mock

import responses
from earthaccess import Auth
from earthaccess.auth import CLIENT_ID
from earthaccess import Auth, search_data
from earthaccess.auth import CLIENT_ID, Env


class TestUatEnvironmentArgument:
@responses.activate
@responses.activate # This will cause the test to check that all mocked URLs are hit.
@mock.patch("getpass.getpass", new=mock.Mock(return_value="password"))
@mock.patch(
"builtins.input",
Expand Down Expand Up @@ -43,14 +43,24 @@ def test_uat_is_requested_when_uat_selected(self) -> bool:
# TODO: Can we use the top-level API? Why do other tests manually create
# an Auth instance instead of:
# earthaccess.login(strategy=..., earthdata_environment=Env.UAT)

auth = Auth()
auth.login(strategy="interactive")

# Check that mock communication was with UAT EDL
...
# Check that we're not already authenticated.
session = auth.get_session()
headers = session.headers
assert not auth.authenticated

# Login
auth.login(strategy="interactive", earthdata_environment=Env.UAT)
assert auth.authenticated
assert auth.token in json_response

# Query CMR
...
# test that we are creating a session with the proper headers
assert "User-Agent" in headers
assert "earthaccess" in headers["User-Agent"]

# Check that mock communication was with UAT CMR
...
# Query CMR, and check that mock communication was with UAT CMR
results = search_data(session=session)
# Then possibly this:
assert len(results) == 0

0 comments on commit 301568c

Please sign in to comment.