Skip to content

Commit 81ce628

Browse files
committed
ci: refactor load mocked http response function
1 parent dfd3376 commit 81ce628

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

binderhub/tests/conftest.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,9 @@ def pytest_terminal_summary(terminalreporter, exitstatus):
9595
json.dump(records, f, sort_keys=True, indent=1)
9696

9797

98-
def load_mock_responses(host):
99-
fname = os.path.join(here, f"http-record.{host}.json")
100-
if not os.path.exists(fname):
101-
return {}
102-
with open(fname) as f:
98+
def load_mock_responses(file_name):
99+
file_path = os.path.join(here, file_name)
100+
with open(file_path) as f:
103101
records = json.load(f)
104102
MockAsyncHTTPClient.mocks.update(records)
105103

@@ -120,12 +118,12 @@ def mock_asynchttpclient(request):
120118
# We should use as few mocked responses as possible because it means
121119
# we won't notice changes in the responses from the host that we are
122120
# mocking and our mock responses don't simulate every and all behavior
123-
load_mock_responses("www.hydroshare.org")
121+
load_mock_responses("http-record.www.hydroshare.org.json")
124122

125123
token = os.getenv("GITHUB_ACCESS_TOKEN")
126124
if not token:
127-
load_mock_responses("api.github.com")
128-
load_mock_responses("zenodo.org")
125+
load_mock_responses("http-record.api.github.com.json")
126+
load_mock_responses("http-record.zenodo.org.json")
129127
if token and token.startswith("ghs-"):
130128
# The GitHub Actions provided temporary token (secrets.github_token)
131129
# does not have access to api.github.com/gists. Due to this, we mock
@@ -136,7 +134,7 @@ def mock_asynchttpclient(request):
136134
# More about github token prefixes:
137135
# https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/#identifiable-prefixes
138136
#
139-
load_mock_responses("api.github.com.gists")
137+
load_mock_responses("http-record.api.github.com.gists.json")
140138

141139

142140
@pytest.fixture

0 commit comments

Comments
 (0)