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

Adds new type of dialect for SIP2 servers that require spaces instead… #1495

Merged
merged 2 commits into from
Nov 6, 2023
Merged
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
1 change: 1 addition & 0 deletions api/sip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class SIP2Settings(BasicAuthProviderSettings):
options={
Sip2Dialect.GENERIC_ILS: "Generic ILS",
Sip2Dialect.AG_VERSO: "Auto-Graphics VERSO",
Sip2Dialect.FOLIO: "Folio",
},
required=True,
),
Expand Down
6 changes: 4 additions & 2 deletions api/sip/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@

def end_session(self, *args, **kwargs):
"""Send end session message."""
if self.dialect_config.sendEndSession:
if self.dialect_config.send_end_session:
return self.make_request(
self.end_session_message,
self.end_session_response_parser,
Expand Down Expand Up @@ -842,8 +842,10 @@

def now(self):
"""Return the current time, formatted as SIP expects it."""
tz_spaces = self.dialect_config.tz_spaces

Check warning on line 845 in api/sip/client.py

View check run for this annotation

Codecov / codecov/patch

api/sip/client.py#L845

Added line #L845 was not covered by tests
now = utc_now()
return datetime.datetime.strftime(now, "%Y%m%d0000%H%M%S")
zzzz = " " * 4 if tz_spaces else "0" * 4
return datetime.datetime.strftime(now, f"%Y%m%d{zzzz}%H%M%S")

Check warning on line 848 in api/sip/client.py

View check run for this annotation

Codecov / codecov/patch

api/sip/client.py#L847-L848

Added lines #L847 - L848 were not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a small test for this that makes sure now() formats the date as we would expect based on the dialect selected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


def summary(
self,
Expand Down
10 changes: 7 additions & 3 deletions api/sip/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@
class DialectConfig:
"""Describe a SIP2 dialect_config."""

sendEndSession: bool
send_end_session: bool
tz_spaces: bool


class Dialect(Enum):
GENERIC_ILS = "GenericILS"
AG_VERSO = "AutoGraphicsVerso"
FOLIO = "TZSpaces"

@property
def config(self) -> DialectConfig:
"""Return the configuration for this dialect."""
if self == Dialect.GENERIC_ILS:
return DialectConfig(sendEndSession=True)
return DialectConfig(send_end_session=True, tz_spaces=False)

Check warning on line 22 in api/sip/dialect.py

View check run for this annotation

Codecov / codecov/patch

api/sip/dialect.py#L22

Added line #L22 was not covered by tests
elif self == Dialect.AG_VERSO:
return DialectConfig(sendEndSession=False)
return DialectConfig(send_end_session=False, tz_spaces=False)

Check warning on line 24 in api/sip/dialect.py

View check run for this annotation

Codecov / codecov/patch

api/sip/dialect.py#L24

Added line #L24 was not covered by tests
elif self == Dialect.FOLIO:
return DialectConfig(send_end_session=True, tz_spaces=True)

Check warning on line 26 in api/sip/dialect.py

View check run for this annotation

Codecov / codecov/patch

api/sip/dialect.py#L26

Added line #L26 was not covered by tests
else:
raise NotImplementedError(f"Unknown dialect: {self}")
14 changes: 11 additions & 3 deletions tests/api/sip/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,12 +708,13 @@ def test_parse_patron_status(self):

class TestClientDialects:
@pytest.mark.parametrize(
"dialect,expected_read_count,expected_write_count",
"dialect,expected_read_count,expected_write_count,expected_tz_spaces",
[
# Generic ILS should send end_session message
(Dialect.GENERIC_ILS, 1, 1),
(Dialect.GENERIC_ILS, 1, 1, False),
# AG VERSO ILS shouldn't end_session message
(Dialect.AG_VERSO, 0, 0),
(Dialect.AG_VERSO, 0, 0, False),
(Dialect.FOLIO, 1, 1, True),
],
)
def test_dialect(
Expand All @@ -722,10 +723,17 @@ def test_dialect(
dialect,
expected_read_count,
expected_write_count,
expected_tz_spaces,
):
sip = sip_client_factory(dialect=dialect)
sip.queue_response("36Y201610210000142637AO3|AA25891000331441|AF|AG")
sip.end_session("username", "password")
assert sip.dialect_config == dialect.config
assert sip.read_count == expected_read_count
assert sip.write_count == expected_write_count
assert sip.dialect_config.tz_spaces == expected_tz_spaces

# verify timestamp format aligns with the expected tz spaces dialect
ts = sip.now()
tz_element = ts[8:12]
assert tz_element == (" " if expected_tz_spaces else "0000")