Skip to content

Commit

Permalink
Fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
J535D165 committed Oct 23, 2023
1 parent 4942606 commit 125189c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
22 changes: 15 additions & 7 deletions pyalex/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,27 +284,35 @@ def count(self):

def _get_from_url(self, url, return_meta=False):
params = {"api_key": config.api_key} if config.api_key else {}

print("hellowww")
# print(res.status_code)
res = _get_requests_session().get(
self.url,
url,
headers={"User-Agent": "pyalex/" + __version__, "email": config.email},
params=params,
)
res_json = res.json()

# handle query errors
if res.status_code == 403:
if (
isinstance(res_json["error"], str)
and "query parameters" in res_json["error"]
isinstance(res.json()["error"], str)
and "query parameters" in res.json()["error"]
):
raise QueryError(res_json["message"])
raise QueryError(res.json()["message"])

res.raise_for_status()
res_json = res.json()

# group-by or results page
if "group-by" in self.params:
if self.params and "group-by" in self.params:
results = res_json["group_by"]
else:
elif "results" in res_json:
results = [self.resource_class(ent) for ent in res_json["results"]]
elif "id" in res_json:
results = self.resource_class(res_json)
else:
raise ValueError("Unknown response format")

# return result and metadata
if return_meta:
Expand Down
1 change: 1 addition & 0 deletions tests/test_pyalex.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def test_random_works():
def test_multi_works():
# the work to extract the referenced works of
w = Works()["W2741809807"]
print(w)

assert len(Works()[w["referenced_works"]]) == 25

Expand Down

0 comments on commit 125189c

Please sign in to comment.