Skip to content

Commit

Permalink
don't attempt to run tests on failed GET API specs
Browse files Browse the repository at this point in the history
  • Loading branch information
omarryhan committed May 22, 2024
1 parent d52a74d commit 6041271
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
1 change: 0 additions & 1 deletion tests/ALL_APIS.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
('people', 'v1'),
('playcustomapp', 'v1'),
('policytroubleshooter', 'v1'),
('poly', 'v1'),
('pubsub', 'v1'),
('recommender', 'v1'),
('redis', 'v1'),
Expand Down
27 changes: 9 additions & 18 deletions tests/refresh_all_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
from aiogoogle import HTTPError


def _pop_unstable_apis(all_apis: list):
return [api for api in all_apis if len(api[1]) <= 3]


async def refresh_disc_docs_json():
file_errors = []

Expand All @@ -29,7 +25,7 @@ async def refresh_disc_docs_json():

# Refresh all_apis in tests/tests_globals.py
all_apis = [(api["name"], api["version"]) for api in apis_pref["items"]]
all_apis = _pop_unstable_apis(all_apis)
all_apis = [api for api in all_apis if len(api[1]) <= 3]
final_all_apis = all_apis

async with Aiogoogle() as google:
Expand All @@ -41,22 +37,17 @@ async def refresh_disc_docs_json():
for google_api, (name, version) in zip(all_discovery_documents, all_apis):
if isinstance(google_api, HTTPError):
e = google_api
if e.res.status_code != 404:
print('Non 404 error')
print('\033[91m\n' + str(e) + '\n\033[0m')
else:
# only ignore if it's a 404 error. Should raise an error otherwise
final_all_apis = list(filter(lambda api: (api[0] != name), final_all_apis))

# filter out the errored api from the final_all_apis
final_all_apis = list(filter(lambda api: (api[0] != name), final_all_apis))
file_errors.append({f"{name}-{version}": str(e)})
print(f'\033[91mError: Failed to download {name} {version}\033[0m')
continue

# Save discovery docuemnt as .json file to the newly created data dir
json_file = data_dir / f"{name}_{version}_discovery_doc.json"
with open(str(json_file), "w") as discovery_file:
json.dump(google_api.discovery_document, discovery_file)
print(f"saved {name}-{version} to {json_file}")
else:
# Save discovery docuemnt as .json file to the newly created data dir
json_file = data_dir / f"{name}_{version}_discovery_doc.json"
with open(str(json_file), "w") as discovery_file:
json.dump(google_api.discovery_document, discovery_file)
print(f"saved {name}-{version} to {json_file}")

print("Done")
if file_errors:
Expand Down

0 comments on commit 6041271

Please sign in to comment.