1919from tests .helpers import user_login , user_logout
2020
2121
22- def _query_loan_extensions_stats (client ):
22+ def _query_loan_extensions_stats (client , trigger ):
2323 """Query stats via the HTTP API."""
2424 response = query_stats (
2525 client ,
26- "loan-extensions" ,
27- {},
26+ "loan-transitions" ,
27+ {
28+ "trigger" : trigger ,
29+ },
2830 )
2931 assert response .status_code == 200
3032 buckets = extract_buckets_from_stats_query (response )
@@ -33,7 +35,7 @@ def _query_loan_extensions_stats(client):
3335 return total_count
3436
3537
36- def test_loan_extensions_histogram (
38+ def test_loan_transition_histogram (
3739 client ,
3840 json_headers ,
3941 users ,
@@ -43,21 +45,28 @@ def test_loan_extensions_histogram(
4345 loan_params ,
4446 checkout_loan ,
4547):
46- """Test that loan extensions are tracked correctly."""
48+ """Test that certain transitions are tracked correctly.
49+
50+ The following transitions are tested checkout, extend and checkin
51+ """
4752
4853 process_and_aggregate_stats ()
4954 user_login (client , "admin" , users )
50- initial_count = _query_loan_extensions_stats (client )
55+ initial_checkout_count = _query_loan_extensions_stats (client , "checkout" )
56+ initial_extend_count = _query_loan_extensions_stats (client , "extend" )
57+ initial_checkin_count = _query_loan_extensions_stats (client , "checkin" )
5158
52- # checkout and extend loan
59+ # checkout loan
5360 loan_pid = "loanid-1"
5461 params = deepcopy (loan_params )
5562 params ["document_pid" ] = "docid-1"
5663 params ["item_pid" ]["value" ] = "itemid-2"
5764 del params ["transaction_date" ]
5865 loan = checkout_loan (loan_pid , params )
5966
60- extend_url = loan ["links" ]["actions" ]["extend" ]
67+ # extend loan
68+ urls = loan ["links" ]["actions" ]
69+ extend_url = urls ["extend" ]
6170 user_login (client , "admin" , users )
6271 res = client .post (
6372 extend_url ,
@@ -66,15 +75,30 @@ def test_loan_extensions_histogram(
6675 )
6776 assert res .status_code == 202
6877
78+ # checkin loan
79+ checkin_url = urls ["checkin" ]
80+ user_login (client , "librarian" , users )
81+ res = client .post (
82+ checkin_url ,
83+ headers = json_headers ,
84+ data = json .dumps (params ),
85+ )
86+ assert res .status_code == 202
87+
6988 process_and_aggregate_stats ()
70- final_count = _query_loan_extensions_stats (client )
71- assert final_count == initial_count + 1
89+ final_checkout_count = _query_loan_extensions_stats (client , "checkout" )
90+ final_extend_count = _query_loan_extensions_stats (client , "extend" )
91+ final_checkin_count = _query_loan_extensions_stats (client , "checkin" )
92+
93+ assert final_extend_count == initial_extend_count + 1
94+ assert final_checkout_count == initial_checkout_count + 1
95+ assert final_checkin_count == initial_checkin_count + 1
7296
7397
74- def test_loan_extensions_stats_permissions (client , users ):
98+ def test_loan_transition_stats_permissions (client , users ):
7599 """Test that only certain users can access the stats."""
76100
77- stat = "loan-extensions "
101+ stat = "loan-transitions "
78102 tests = [
79103 ("admin" , 200 ),
80104 ("patron1" , 403 ),
@@ -83,7 +107,9 @@ def test_loan_extensions_stats_permissions(client, users):
83107 ("anonymous" , 401 ),
84108 ]
85109
86- params = {}
110+ params = {
111+ "trigger" : "request" ,
112+ }
87113 for username , expected_resp_code in tests :
88114 user_login (client , username , users )
89115 response = query_stats (
0 commit comments