Skip to content

Commit

Permalink
Adds new type of dialect for SIP2 servers that require spaces instead… (
Browse files Browse the repository at this point in the history
#1495)

of zeros in the time zone segment of the date time values sent via the SIP2 protocol.
Resolves: https://ebce-lyrasis.atlassian.net/browse/PP-546
  • Loading branch information
dbernstein authored Nov 6, 2023
1 parent 710219c commit 4763d83
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
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 patron_information(self, *args, **kwargs):

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 parse_patron_status(cls, status_string):

def now(self):
"""Return the current time, formatted as SIP expects it."""
tz_spaces = self.dialect_config.tz_spaces
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")

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)
elif self == Dialect.AG_VERSO:
return DialectConfig(sendEndSession=False)
return DialectConfig(send_end_session=False, tz_spaces=False)
elif self == Dialect.FOLIO:
return DialectConfig(send_end_session=True, tz_spaces=True)
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")

0 comments on commit 4763d83

Please sign in to comment.