Skip to content

Commit 6d50889

Browse files
bltravisbtravisebsco
authored andcommitted
Add tests for coverage
1 parent 2216e76 commit 6d50889

1 file changed

Lines changed: 100 additions & 12 deletions

File tree

tests/test_requests_migrator_inactive_user.py

Lines changed: 100 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -170,21 +170,109 @@ def test_create_request_with_inactive_user_retry_catches_inactive_user_error(sel
170170

171171
assert result is True
172172

173-
def test_create_request_with_inactive_user_retry_reraises_other_errors(self):
173+
def test_create_request_with_inactive_user_retry_returns_false_on_non_inactive_error(self):
174174
m = self._make_migrator()
175175
legacy_request = DummyLegacyRequest(patron_barcode="P001")
176176

177-
# Mock a different error
178-
error_response = Mock()
179-
error_response.json.return_value = {
180-
"errors": [{"message": "Some other error"}]
177+
# circulation_helper.create_request catches FolioValidationError and returns False
178+
# so _create_request_with_inactive_user_retry just returns that False
179+
m.circulation_helper.create_request.return_value = False
180+
181+
result = m._create_request_with_inactive_user_retry(legacy_request)
182+
183+
assert result is False
184+
185+
def test_get_user_by_barcode_exception_handling(self):
186+
m = self._make_migrator()
187+
m.folio_client.folio_get.side_effect = Exception("API Error")
188+
189+
result = m.get_user_by_barcode("P001")
190+
191+
assert result is None
192+
193+
def test_update_user_calls_folio_put_correctly(self):
194+
m = self._make_migrator()
195+
user_data = {
196+
"id": "user-123",
197+
"barcode": "P001",
198+
"active": True,
199+
"name": "John Doe",
181200
}
182-
error_request = Mock()
183-
m.folio_client.handle_json_response.return_value = {
184-
"errors": [{"message": "Some other error"}]
201+
202+
m.update_user(user_data)
203+
204+
m.folio_client.folio_put.assert_called_once_with("/users/user-123", user_data)
205+
206+
def test_full_inactive_user_flow_integration(self):
207+
m = self._make_migrator()
208+
legacy_request = DummyLegacyRequest(patron_barcode="P001")
209+
210+
# Mock user data
211+
user_data = {
212+
"id": "user-123",
213+
"barcode": "P001",
214+
"active": False,
215+
"expirationDate": "2024-12-31",
185216
}
186-
fve = FolioValidationError(request=error_request, response=error_response)
187-
m.circulation_helper.create_request.side_effect = fve
217+
m.folio_client.folio_get.return_value = [user_data]
218+
m.circulation_helper.create_request.return_value = True
219+
220+
# Call the retry method
221+
result = m._retry_request_for_inactive_user(legacy_request)
222+
223+
# Verify the flow
224+
assert result is True
225+
m.folio_client.folio_get.assert_called_once_with("/users", "users", query='barcode=="P001"')
226+
# Should call folio_put twice: once for activate, once for deactivate
227+
assert m.folio_client.folio_put.call_count == 2
228+
# Verify the URLs called
229+
assert m.folio_client.folio_put.call_args_list[0][0][0] == "/users/user-123"
230+
assert m.folio_client.folio_put.call_args_list[1][0][0] == "/users/user-123"
188231

189-
with pytest.raises(FolioValidationError):
190-
m._create_request_with_inactive_user_retry(legacy_request)
232+
def test_deactivate_user_restores_original_expiration(self):
233+
m = self._make_migrator()
234+
user_data = {
235+
"id": "user-123",
236+
"barcode": "P001",
237+
"active": True,
238+
"expirationDate": "2025-06-30",
239+
}
240+
original_expiration = "2024-12-31"
241+
242+
m.deactivate_user(user_data, original_expiration)
243+
244+
assert user_data["active"] is False
245+
assert user_data["expirationDate"] == "2024-12-31"
246+
m.folio_client.folio_put.assert_called_once()
247+
248+
def test_activate_user_extends_expiration_correctly(self):
249+
m = self._make_migrator()
250+
user_data = {
251+
"id": "user-123",
252+
"barcode": "P001",
253+
"active": False,
254+
}
255+
256+
m.activate_user(user_data)
257+
258+
assert user_data["active"] is True
259+
m.folio_client.folio_put.assert_called_once()
260+
261+
def test_request_creation_fails_after_reactivation(self):
262+
m = self._make_migrator()
263+
legacy_request = DummyLegacyRequest(patron_barcode="P001")
264+
265+
user_data = {
266+
"id": "user-123",
267+
"barcode": "P001",
268+
"active": False,
269+
"expirationDate": "2024-12-31",
270+
}
271+
m.folio_client.folio_get.return_value = [user_data]
272+
m.circulation_helper.create_request.return_value = False
273+
274+
result = m._retry_request_for_inactive_user(legacy_request)
275+
276+
assert result is False
277+
# User should still be deactivated even though request failed
278+
assert m.folio_client.folio_put.call_count == 2

0 commit comments

Comments
 (0)