-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d35d1a
commit d7b132d
Showing
5 changed files
with
42 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 26 additions & 23 deletions
49
tests/manager/api/controller/test_patron_activity_history.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,48 @@ | ||
from __future__ import annotations | ||
|
||
import flask | ||
import pytest | ||
|
||
from palace.manager.api.controller.patron_activity_history import ( | ||
PatronActivityHistoryController, | ||
) | ||
from palace.manager.sqlalchemy.model.patron import Patron | ||
from tests.fixtures.api_controller import ControllerFixture | ||
from tests.fixtures.database import DatabaseTransactionFixture | ||
from tests.fixtures.services import ServicesFixture | ||
from tests.fixtures.flask import FlaskAppFixture | ||
|
||
|
||
class PatronActivityHistoryFixture(ControllerFixture): | ||
class PatronActivityHistoryControllerFixture: | ||
def __init__( | ||
self, db: DatabaseTransactionFixture, services_fixture: ServicesFixture | ||
self, | ||
db: DatabaseTransactionFixture, | ||
): | ||
super().__init__(db, services_fixture) | ||
self.default_patron = db.patron() | ||
self.auth = dict(Authorization=self.valid_auth) | ||
self.controller = PatronActivityHistoryController() | ||
self.db = db | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def patron_activity_history_fixture( | ||
db: DatabaseTransactionFixture, services_fixture: ServicesFixture | ||
): | ||
return PatronActivityHistoryFixture(db, services_fixture) | ||
@pytest.fixture | ||
def controller_fixture( | ||
db: DatabaseTransactionFixture, | ||
) -> PatronActivityHistoryControllerFixture: | ||
return PatronActivityHistoryControllerFixture(db) | ||
|
||
|
||
class TestPatronActivityHistoryController: | ||
"""Test that a client can interact with the Patron Activity History.""" | ||
|
||
def test_erase(self, patron_activity_history_fixture: PatronActivityHistoryFixture): | ||
with patron_activity_history_fixture.request_context_with_library( | ||
"/", method="PUT", headers=patron_activity_history_fixture.auth | ||
): | ||
patron = ( | ||
patron_activity_history_fixture.controller.authenticated_patron_from_request() | ||
) | ||
def test_reset_statistics_uuid( | ||
self, | ||
controller_fixture: PatronActivityHistoryControllerFixture, | ||
flask_app_fixture: FlaskAppFixture, | ||
): | ||
|
||
with flask_app_fixture.test_request_context("/", method="PUT"): | ||
patron = controller_fixture.db.patron() | ||
flask.request.patron = patron # type: ignore[attr-defined] | ||
assert isinstance(patron, Patron) | ||
uuid1 = patron.uuid | ||
assert uuid1 | ||
response = ( | ||
patron_activity_history_fixture.manager.patron_activity_history.erase() | ||
) | ||
response = controller_fixture.controller.reset_statistics_uuid() | ||
uuid2 = patron.uuid | ||
assert uuid1 != uuid2 | ||
assert 200 == response.status_code | ||
assert response.status_code == 200 |