Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New endpoints #76

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[flake8]
per-file-ignores =
tests/*:E501
tests/*:E501, W503
2 changes: 1 addition & 1 deletion bookops_worldcat/_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(
"""
Args:
authorization: WorldcatAccessToken instance
agent: "User-agent" parameter to attached to each
agent: "User-agent" parameter to attach to each
request in the session
timeout: how long to wait for server to send data
before giving up
Expand Down
1,360 changes: 804 additions & 556 deletions bookops_worldcat/metadata_api.py

Large diffs are not rendered by default.

17 changes: 2 additions & 15 deletions bookops_worldcat/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,9 @@ def __init__(
if session.authorization.is_expired():
session._get_new_access_token()

self.response = None

try:
self.response = session.send(prepared_request, timeout=timeout)

if "/ih/data" in prepared_request.url: # type: ignore
if self.response.status_code == 409:
# HTTP 409 code returns when trying to set/unset
# holdings on already set/unset record
# It is reasonable not to raise any exceptions
# in this case
pass # pragma: no cover
else:
self.response.raise_for_status()
else:
self.response.raise_for_status()
self.response.raise_for_status()

except HTTPError as exc:
raise WorldcatRequestError(
Expand All @@ -77,5 +64,5 @@ def __init__(
)
except (Timeout, ConnectionError):
raise WorldcatRequestError(f"Connection Error: {sys.exc_info()[0]}")
except:
except Exception:
raise WorldcatRequestError(f"Unexpected request error: {sys.exc_info()[0]}")
14 changes: 14 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ def live_keys():
os.environ["WCPrincipalIDNS"] = data["principal_idns"]


@pytest.fixture
def stub_marc_xml():
with open("tests/test.xml", "r") as stub:
stub_marc_xml = stub.read()
return stub_marc_xml


@pytest.fixture
def stub_marc21():
with open("tests/test.mrc", "rb") as stub:
stub_marc21 = stub.read()
return stub_marc21


class FakeUtcNow(datetime.datetime):
@classmethod
def now(cls, tzinfo=datetime.timezone.utc):
Expand Down
1 change: 1 addition & 0 deletions tests/test.mrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
00266nam a2200097 a 4500008004100000010001700041040002200058100002700080245001600107500004500123120827s2012 nyua 000 0 eng d a 63011276  aOCWMSbengcOCWMS0 aOCLC Developer Network10aTest Record aFOR OCLC DEVELOPER NETWORK DOCUMENTATION
24 changes: 24 additions & 0 deletions tests/test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<record>
<leader>00000nam a2200000 a 4500</leader>
<controlfield tag="008">120827s2012 nyua 000 0 eng d</controlfield>
<datafield tag="010" ind1=" " ind2=" ">
<subfield code="a"> 63011276 </subfield>
</datafield>
<datafield tag="035" ind1=" " ind2=" ">
<subfield code="a">ocn850940548</subfield>
</datafield>
<datafield tag="040" ind1=" " ind2=" ">
<subfield code="a">OCWMS</subfield>
<subfield code="b">eng</subfield>
<subfield code="c">OCWMS</subfield>
</datafield>
<datafield tag="100" ind1="0" ind2=" ">
<subfield code="a">OCLC Developer Network</subfield>
</datafield>
<datafield tag="245" ind1="1" ind2="0">
<subfield code="a">Test Record</subfield>
</datafield>
<datafield tag="500" ind1=" " ind2=" ">
<subfield code="a">FOR OCLC DEVELOPER NETWORK DOCUMENTATION</subfield>
</datafield>
</record>
Loading