Skip to content

Commit

Permalink
Rename Circulation libraries to associated_libraries.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdilauro committed Nov 26, 2024
1 parent 6f25265 commit 365cc46
Show file tree
Hide file tree
Showing 36 changed files with 89 additions and 85 deletions.
2 changes: 1 addition & 1 deletion src/palace/manager/api/admin/controller/custom_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def _create_or_update_list(
if not collection:
self._db.rollback()
return MISSING_COLLECTION
if list.library not in collection.libraries:
if list.library not in collection.associated_libraries:
self._db.rollback()
return COLLECTION_NOT_ASSOCIATED_WITH_LIBRARY
new_collections.append(collection)
Expand Down
4 changes: 2 additions & 2 deletions src/palace/manager/api/selftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def default_patrons(
- a failure SelfTestResult when it cannot.
"""
_db = Session.object_session(collection)
if not collection.libraries:
if not collection.associated_libraries:
yield cls.test_failure(
"Acquiring test patron credentials.",
"Collection is not associated with any libraries.",
Expand All @@ -60,7 +60,7 @@ def default_patrons(
# Not strictly necessary, but makes it obvious that we won't do anything else.
return

for library in collection.libraries:
for library in collection.associated_libraries:
task = "Acquiring test patron credentials for library %s" % library.name
try:
patron, password = cls._determine_self_test_patron(library, _db=_db)
Expand Down
2 changes: 1 addition & 1 deletion src/palace/manager/scripts/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def do_run(self, _db=None, cmd_args=None, output=sys.stdout):
message += " I only know about: %s" % library_names
raise ValueError(message)
if collection not in library.collections:
collection.libraries.append(library)
collection.associated_libraries.append(library)
site_configuration_has_changed(_db)
_db.commit()
output.write("Configuration settings stored.\n")
Expand Down
4 changes: 3 additions & 1 deletion src/palace/manager/scripts/informational.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ def explain_license_pool(self, pool):
self.write("Licensepool info:")
if pool.collection:
self.write(" Collection: %r" % pool.collection)
libraries = [library.name for library in pool.collection.libraries]
libraries = [
library.name for library in pool.collection.associated_libraries
]
if libraries:
self.write(" Available to libraries: %s" % ", ".join(libraries))
else:
Expand Down
2 changes: 1 addition & 1 deletion src/palace/manager/sqlalchemy/model/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def lookup_hook():
def can_see_collection(self, collection):
if self.is_system_admin():
return True
for library in collection.libraries:
for library in collection.associated_libraries:
if self.is_librarian(library):
return True
return False
Expand Down
4 changes: 2 additions & 2 deletions src/palace/manager/sqlalchemy/model/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Collection(Base, HasSessionCache, RedisKeyMixin):

# A Collection can provide books to many Libraries.
# https://docs.sqlalchemy.org/en/14/orm/extensions/associationproxy.html#composite-association-proxies
libraries: Mapped[list[Library]] = association_proxy(
associated_libraries: Mapped[list[Library]] = association_proxy(
"integration_configuration", "libraries"
)

Expand Down Expand Up @@ -563,7 +563,7 @@ def delete(
_db = Session.object_session(self)

# Disassociate all libraries from this collection.
self.libraries.clear()
self.associated_libraries.clear()

# Delete all the license pools. This should be the only part
# of the application where LicensePools are permanently
Expand Down
6 changes: 3 additions & 3 deletions tests/fixtures/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def _make_default_library(self) -> Library:
protocol=OPDSAPI,
settings=self.opds_settings(data_source="OPDS"),
)
collection.libraries.append(library)
collection.associated_libraries.append(library)
return library

@classmethod
Expand Down Expand Up @@ -606,8 +606,8 @@ def collection(
collection.integration_configuration.settings_dict = settings
flag_modified(collection.integration_configuration, "settings_dict")

if library and library not in collection.libraries:
collection.libraries.append(library)
if library and library not in collection.associated_libraries:
collection.associated_libraries.append(library)
return collection

def work(
Expand Down
6 changes: 3 additions & 3 deletions tests/fixtures/marc.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def __init__(
self.collection2 = db.collection()
self.collection3 = db.collection()

self.collection1.libraries = [self.library1, self.library2]
self.collection2.libraries = [self.library1]
self.collection3.libraries = [self.library2]
self.collection1.associated_libraries = [self.library1, self.library2]
self.collection2.associated_libraries = [self.library1]
self.collection3.associated_libraries = [self.library2]

def integration(self) -> IntegrationConfiguration:
return self._db.integration_configuration(
Expand Down
8 changes: 4 additions & 4 deletions tests/manager/api/admin/controller/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_collections_get_collections_with_multiple_collections(
c3.parent = c2

l1 = db.library(short_name="L1")
c3.libraries += [l1, db.default_library()]
c3.associated_libraries += [l1, db.default_library()]
db.integration_library_configuration(
c3.integration_configuration,
l1,
Expand Down Expand Up @@ -534,7 +534,7 @@ def test_collections_post_edit(
)

# A library now has access to the collection.
assert collection.libraries == [l1]
assert collection.associated_libraries == [l1]

# Additional settings were set on the collection.
assert "1234" == collection.integration_configuration.settings_dict.get(
Expand Down Expand Up @@ -571,7 +571,7 @@ def test_collections_post_edit(
assert OverdriveAPI.label() == collection.protocol

# But the library has been removed.
assert collection.libraries == []
assert collection.associated_libraries == []

# All settings for that library and collection have been deleted.
assert collection.integration_configuration.library_configurations == []
Expand Down Expand Up @@ -704,7 +704,7 @@ def test_collections_post_edit_library_specific_configuration(
# when the connection between collection and library was deleted.
assert isinstance(l1.id, int)
assert collection.integration_configuration.for_library(l1.id) is None
assert [] == collection.libraries
assert [] == collection.associated_libraries

def test_collection_delete(
self,
Expand Down
22 changes: 12 additions & 10 deletions tests/manager/api/admin/controller/test_custom_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ def test_custom_lists_post_collection_with_wrong_library(
def test_custom_lists_create(self, admin_librarian_fixture: AdminLibrarianFixture):
work = admin_librarian_fixture.ctrl.db.work(with_open_access_download=True)
collection = admin_librarian_fixture.ctrl.db.collection()
collection.libraries = [admin_librarian_fixture.ctrl.db.default_library()]
collection.associated_libraries = [
admin_librarian_fixture.ctrl.db.default_library()
]

with admin_librarian_fixture.request_context_with_library_and_admin(
"/", method="POST"
Expand Down Expand Up @@ -595,9 +597,9 @@ def test_custom_list_edit(self, admin_librarian_fixture: AdminLibrarianFixture):
]

c1 = admin_librarian_fixture.ctrl.db.collection()
c1.libraries = [admin_librarian_fixture.ctrl.db.default_library()]
c1.associated_libraries = [admin_librarian_fixture.ctrl.db.default_library()]
c2 = admin_librarian_fixture.ctrl.db.collection()
c2.libraries = [admin_librarian_fixture.ctrl.db.default_library()]
c2.associated_libraries = [admin_librarian_fixture.ctrl.db.default_library()]
list.collections = [c1]
new_collections = [c2]

Expand Down Expand Up @@ -875,7 +877,7 @@ def _setup_share_locally(self, admin_librarian_fixture: AdminLibrarianFixture):
shared_with = admin_librarian_fixture.ctrl.db.library("shared_with")
primary_library = admin_librarian_fixture.ctrl.db.library("primary")
collection1 = admin_librarian_fixture.ctrl.db.collection("c1")
collection1.libraries.append(primary_library)
collection1.associated_libraries.append(primary_library)

data_source = DataSource.lookup(
admin_librarian_fixture.ctrl.db.session, DataSource.LIBRARY_STAFF
Expand Down Expand Up @@ -921,7 +923,7 @@ def test_share_locally_success(
self, admin_librarian_fixture: AdminLibrarianFixture
):
s = self._setup_share_locally(admin_librarian_fixture)
s.collection1.libraries.append(s.shared_with)
s.collection1.associated_libraries.append(s.shared_with)
response = self._share_locally(
s.list, s.primary_library, admin_librarian_fixture
)
Expand All @@ -945,11 +947,11 @@ def test_share_locally_with_invalid_entries(
logging.INFO, "palace.manager.core.query.customlist.CustomListQueries"
)
s = self._setup_share_locally(admin_librarian_fixture)
s.collection1.libraries.append(s.shared_with)
s.collection1.associated_libraries.append(s.shared_with)

# Second collection with work in list
collection2 = admin_librarian_fixture.ctrl.db.collection()
collection2.libraries.append(s.primary_library)
collection2.associated_libraries.append(s.primary_library)
w = admin_librarian_fixture.ctrl.db.work(collection=collection2)
s.list.add_entry(w)

Expand All @@ -973,7 +975,7 @@ def test_share_locally_with_entry_with_missing_work(
logging.INFO, "palace.manager.core.query.customlist.CustomListQueries"
)
s = self._setup_share_locally(admin_librarian_fixture)
s.collection1.libraries.append(s.shared_with)
s.collection1.associated_libraries.append(s.shared_with)

w = admin_librarian_fixture.ctrl.db.work(collection=s.collection1)
entry, ignore = s.list.add_entry(w)
Expand Down Expand Up @@ -1010,7 +1012,7 @@ def message_found_n_times(self, caplog, message: str, occurrences: int = 1):
def test_share_locally_get(self, admin_librarian_fixture: AdminLibrarianFixture):
"""Does the GET method fetch shared lists"""
s = self._setup_share_locally(admin_librarian_fixture)
s.collection1.libraries.append(s.shared_with)
s.collection1.associated_libraries.append(s.shared_with)

resp = self._share_locally(s.list, s.primary_library, admin_librarian_fixture)
assert resp["successes"] == 1
Expand Down Expand Up @@ -1045,7 +1047,7 @@ def test_share_locally_get(self, admin_librarian_fixture: AdminLibrarianFixture)
def test_share_locally_delete(self, admin_librarian_fixture: AdminLibrarianFixture):
"""Test the deleting of a lists shared status"""
s = self._setup_share_locally(admin_librarian_fixture)
s.collection1.libraries.append(s.shared_with)
s.collection1.associated_libraries.append(s.shared_with)

resp = self._share_locally(s.list, s.primary_library, admin_librarian_fixture)
assert resp["successes"] == 1
Expand Down
2 changes: 1 addition & 1 deletion tests/manager/api/admin/controller/test_lanes.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TestLanesController:
def test_lanes_get(self, alm_fixture: AdminLibraryManagerFixture):
library = alm_fixture.ctrl.db.library()
collection = alm_fixture.ctrl.db.collection()
collection.libraries.append(library)
collection.associated_libraries.append(library)

english = alm_fixture.ctrl.db.lane(
"English", library=library, languages=["eng"]
Expand Down
6 changes: 3 additions & 3 deletions tests/manager/api/admin/controller/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_generate_report_authorization(
collection = db.collection(
protocol=OPDSAPI,
)
collection.libraries = [library1, library2]
collection.associated_libraries = [library1, library2]

def assert_and_clear_caplog(
response: Response | ProblemDetail, email: str
Expand Down Expand Up @@ -179,7 +179,7 @@ def test_inventory_report_info(
collection = db.collection(
protocol=OPDSAPI,
)
collection.libraries = [library1, library2]
collection.associated_libraries = [library1, library2]

success_payload_dict = InventoryReportInfo(
collections=[
Expand Down Expand Up @@ -291,7 +291,7 @@ def test_inventory_report_info_reportable_collections(

library = db.library()
collection = db.collection(protocol=protocol, settings=settings)
collection.libraries = [library]
collection.associated_libraries = [library]

if parent_settings:
parent = db.collection(
Expand Down
6 changes: 3 additions & 3 deletions tests/manager/api/admin/test_dashboard_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def test_stats_collections(admin_statistics_session: AdminStatisticsSessionFixtu

default_library = db.library("Default Library", "default")
default_collection = db.collection(name="Default Collection")
default_collection.libraries += [default_library]
default_collection.associated_libraries += [default_library]

# default collection adds an OA title.
_, _ = db.edition(
Expand Down Expand Up @@ -360,7 +360,7 @@ def test_stats_collections(admin_statistics_session: AdminStatisticsSessionFixtu

c2 = db.collection()
c3 = db.collection()
c3.libraries += [default_library]
c3.associated_libraries += [default_library]

# c2 adds a 5/10 metered license title.
edition, pool = db.edition(
Expand Down Expand Up @@ -627,7 +627,7 @@ def test_stats_parent_collection_permissions(
child: Collection = db.collection()
child.parent = parent
library = db.library()
child.libraries.append(library)
child.associated_libraries.append(library)
admin.add_role(AdminRole.LIBRARIAN, library)

response = session.get_statistics()
Expand Down
2 changes: 1 addition & 1 deletion tests/manager/api/controller/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def test_load_licensepools(self, circulation_fixture: CirculationControllerFixtu
library = circulation_fixture.library
[c1] = library.collections
c2 = circulation_fixture.db.collection()
c2.libraries.append(library)
c2.associated_libraries.append(library)

# Here's a Collection not affiliated with any Library.
c3 = circulation_fixture.db.collection()
Expand Down
2 changes: 1 addition & 1 deletion tests/manager/api/controller/test_loan.py
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,7 @@ def test_loan_duration_settings_impact_on_loans_and_borrow_response(
protocol=collection_protocol,
)

collection.libraries.append(loan_fixture.db.default_library())
collection.associated_libraries.append(loan_fixture.db.default_library())
if collection_default_loan_period:
loan_fixture.db.integration_library_configuration(
collection.integration_configuration,
Expand Down
8 changes: 4 additions & 4 deletions tests/manager/api/controller/test_marc.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test_get_files_collection_removed_from_library(
assert len(files) == 1

# The collection is removed from the library, so it's not returned.
marc_record_controller_fixture.collection.libraries = []
marc_record_controller_fixture.collection.associated_libraries = []

files = marc_record_controller_fixture.controller.get_files(
marc_record_controller_fixture.db.session,
Expand All @@ -191,7 +191,7 @@ def test_get_files_multiple_collections(
# Create a second collection, with a full file and a delta.
collection_2 = db.collection(name="Second Collection")
collection_2.export_marc_records = True
collection_2.libraries = [marc_record_controller_fixture.library]
collection_2.associated_libraries = [marc_record_controller_fixture.library]
marc_record_controller_fixture.file(collection=collection_2, created=now)
marc_record_controller_fixture.file(
collection=collection_2, created=now, since=last_week
Expand All @@ -200,13 +200,13 @@ def test_get_files_multiple_collections(
# Create a third collection that doesn't export MARC records.
collection_3 = db.collection()
collection_3.export_marc_records = False
collection_3.libraries = [marc_record_controller_fixture.library]
collection_3.associated_libraries = [marc_record_controller_fixture.library]
marc_record_controller_fixture.file(collection=collection_3, created=now)

# Create a fourth collection that doesn't belong to the library.
collection_4 = db.collection()
collection_4.export_marc_records = True
collection_4.libraries = []
collection_4.associated_libraries = []
marc_record_controller_fixture.file(collection=collection_4, created=now)

files = marc_record_controller_fixture.controller.get_files(
Expand Down
2 changes: 1 addition & 1 deletion tests/manager/api/controller/test_playtime_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def test_api_validation(
assert response.detail == "Collection was not found in the Library."

# Identifier not part of collection
collection.libraries.append(library)
collection.associated_libraries.append(library)
response = playtime_entries_controller_fixture.controller.track_playtimes(
collection.id, identifier.type, identifier.identifier
)
Expand Down
2 changes: 1 addition & 1 deletion tests/manager/api/test_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def patron_activity(self, patron, pin):
# Collection -- one library with a default patron and one
# without.
no_default_patron = axis360.db.library()
axis360.collection.libraries.append(no_default_patron)
axis360.collection.associated_libraries.append(no_default_patron)

with_default_patron = axis360.db.default_library()
axis360.db.simple_auth_integration(with_default_patron)
Expand Down
2 changes: 1 addition & 1 deletion tests/manager/api/test_bibliotheca.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def patron_activity(self, patron, pin):
# Collection -- one library with a default patron and one
# without.
no_default_patron = db.library()
bibliotheca_fixture.collection.libraries.append(no_default_patron)
bibliotheca_fixture.collection.associated_libraries.append(no_default_patron)

with_default_patron = db.default_library()
db.simple_auth_integration(with_default_patron)
Expand Down
2 changes: 1 addition & 1 deletion tests/manager/api/test_enki.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def patron_activity(self, patron, pin):
# patron and one without.
no_default_patron = db.library()
assert api.collection is not None
api.collection.libraries.append(no_default_patron)
api.collection.associated_libraries.append(no_default_patron)

with_default_patron = db.default_library()
db.simple_auth_integration(with_default_patron)
Expand Down
4 changes: 2 additions & 2 deletions tests/manager/api/test_lanes.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ def test_init(self, db: DatabaseTransactionFixture):
library = db.default_library()
default_collection = db.default_collection()
other_library_collection = db.collection()
other_library_collection.libraries.append(library)
other_library_collection.associated_libraries.append(library)

# This collection is not associated with any library.
unused_collection = db.collection()
Expand Down Expand Up @@ -1174,7 +1174,7 @@ def test_constructor(self, db: DatabaseTransactionFixture):
"Test Overdrive Collection",
protocol=OverdriveAPI,
)
overdrive_collection.libraries.append(library)
overdrive_collection.associated_libraries.append(library)

# Create another collection that is _not_ associated with this
# library. It will not be used at all.
Expand Down
Loading

0 comments on commit 365cc46

Please sign in to comment.