Skip to content

Commit

Permalink
* Adds test for FOLIO dialect modifications
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
dbernstein committed Nov 6, 2023
1 parent e97f01d commit 0a75fe1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion api/sip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down
7 changes: 1 addition & 6 deletions api/sip/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -558,7 +554,6 @@ def end_session_message(
patron password: AD, variable length, optional
"""
code = "35"

timestamp = self.now()

message = (
Expand Down
4 changes: 2 additions & 2 deletions api/sip/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -22,7 +22,7 @@ def config(self) -> DialectConfig:
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(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.TZ_SPACES:
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}")
15 changes: 11 additions & 4 deletions tests/api/sip/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -723,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 0a75fe1

Please sign in to comment.