From 0a75fe1eb018f44c144f26f8c9735fde1783d3f5 Mon Sep 17 00:00:00 2001 From: Daniel Bernstein Date: Mon, 6 Nov 2023 10:11:16 -0800 Subject: [PATCH] * Adds test for FOLIO dialect modifications * Use "FOLIO" rather than "TZ SPACES" as dialect name * Revert dialect type check in sip client since new changes in the main obviate the need for them. --- api/sip/__init__.py | 2 +- api/sip/client.py | 7 +------ api/sip/dialect.py | 4 ++-- tests/api/sip/test_client.py | 15 +++++++++++---- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/api/sip/__init__.py b/api/sip/__init__.py index 7818a33174..e42bb96b21 100644 --- a/api/sip/__init__.py +++ b/api/sip/__init__.py @@ -120,7 +120,7 @@ class SIP2Settings(BasicAuthProviderSettings): options={ Sip2Dialect.GENERIC_ILS: "Generic ILS", Sip2Dialect.AG_VERSO: "Auto-Graphics VERSO", - Sip2Dialect.TZ_SPACES: "TZ Spaces", + Sip2Dialect.FOLIO: "Folio", }, required=True, ), diff --git a/api/sip/client.py b/api/sip/client.py index a0e71925e1..8a2317db77 100644 --- a/api/sip/client.py +++ b/api/sip/client.py @@ -345,11 +345,7 @@ def __init__( # We're implicitly logged in. self.must_log_in = False self.login_password = login_password - - if isinstance(dialect, str): - self.dialect_config = Dialect(dialect).config - else: - self.dialect_config = dialect.config + self.dialect_config = dialect.config def login(self): """Log in to the SIP server if required.""" @@ -558,7 +554,6 @@ def end_session_message( patron password: AD, variable length, optional """ code = "35" - timestamp = self.now() message = ( diff --git a/api/sip/dialect.py b/api/sip/dialect.py index f2e40c81fe..bb8b5829e7 100644 --- a/api/sip/dialect.py +++ b/api/sip/dialect.py @@ -13,7 +13,7 @@ class DialectConfig: class Dialect(Enum): GENERIC_ILS = "GenericILS" AG_VERSO = "AutoGraphicsVerso" - TZ_SPACES = "TZSpaces" + FOLIO = "TZSpaces" @property def config(self) -> DialectConfig: @@ -22,7 +22,7 @@ def config(self) -> DialectConfig: return DialectConfig(send_end_session=True, tz_spaces=False) elif self == Dialect.AG_VERSO: return DialectConfig(send_end_session=False, tz_spaces=False) - elif self == Dialect.TZ_SPACES: + elif self == Dialect.FOLIO: return DialectConfig(send_end_session=True, tz_spaces=True) else: raise NotImplementedError(f"Unknown dialect: {self}") diff --git a/tests/api/sip/test_client.py b/tests/api/sip/test_client.py index b1594e13c0..2153165249 100644 --- a/tests/api/sip/test_client.py +++ b/tests/api/sip/test_client.py @@ -708,13 +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.TZ_SPACES, 1, 1), + (Dialect.AG_VERSO, 0, 0, False), + (Dialect.FOLIO, 1, 1, True), ], ) def test_dialect( @@ -723,6 +723,7 @@ 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") @@ -730,3 +731,9 @@ def test_dialect( 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")