Skip to content

Commit ec177d3

Browse files
committed
Test that last_usage field is set and updated
1 parent 32be468 commit ec177d3

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

packages/hidp/tests/smoke_tests/test_federated/test_views.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,16 @@ def test_redirect_to_register(self, mock_handle_authentication_callback):
271271
)
272272
def test_redirect_to_login(self, mock_handle_authentication_callback):
273273
user = user_factories.VerifiedUserFactory()
274-
models.OpenIdConnection.objects.create(
274+
connection = models.OpenIdConnection.objects.create(
275275
user=user,
276276
provider_key="example",
277277
issuer_claim="example",
278278
subject_claim="test_subject",
279279
)
280+
281+
# Save original timestamp for comparison
282+
original_last_usage = connection.last_usage
283+
280284
response = self.client.get(
281285
reverse("hidp_oidc_client:callback", kwargs={"provider_key": "example"}),
282286
secure=True,
@@ -289,6 +293,14 @@ def test_redirect_to_login(self, mock_handle_authentication_callback):
289293
token = query["token"][0]
290294
self.assertIn(token, self.client.session)
291295

296+
# Refresh from DB and assert last_usage was updated
297+
connection.refresh_from_db()
298+
self.assertIsNotNone(connection.last_usage)
299+
self.assertGreater(
300+
connection.last_usage,
301+
original_last_usage,
302+
)
303+
292304
@mock.patch(
293305
"hidp.federated.views.authorization_code_flow.handle_authentication_callback",
294306
return_value=(*_VALID_AUTH_CALLBACK, None),

0 commit comments

Comments
 (0)