diff --git a/kobo/apps/audit_log/models.py b/kobo/apps/audit_log/models.py index af7a5bb731..4fd3908849 100644 --- a/kobo/apps/audit_log/models.py +++ b/kobo/apps/audit_log/models.py @@ -147,14 +147,15 @@ def with_group_key(self): 'user_uid', ), ), - # for everything else, the group key is just the id since they won't be grouped + # for everything else, the group key is just the id + # since they won't be grouped default=Cast('id', output_field=models.CharField()), ) ) def with_submissions_grouped(self): """ - Returns minimal audit log representation with submissions grouped by user by hour + Returns minimal representation with submissions grouped by user by hour """ return ( self.with_group_key() diff --git a/kobo/apps/audit_log/tests/api/v2/test_api_audit_log.py b/kobo/apps/audit_log/tests/api/v2/test_api_audit_log.py index 62ea9ee9e0..8bf23dedec 100644 --- a/kobo/apps/audit_log/tests/api/v2/test_api_audit_log.py +++ b/kobo/apps/audit_log/tests/api/v2/test_api_audit_log.py @@ -315,7 +315,7 @@ def test_can_search_access_logs_by_username(self): admin = User.objects.get(username='admin') AccessLog.objects.create(user=user1) AccessLog.objects.create(user=user2) - self.force_login_user(User.objects.get(username='admin')) + self.force_login_user(admin) response = self.client.get(f'{self.url}?q=user__username:anotheruser') # only return logs from user1 diff --git a/kobo/apps/audit_log/tests/test_models.py b/kobo/apps/audit_log/tests/test_models.py index f1225b330d..a0af285c81 100644 --- a/kobo/apps/audit_log/tests/test_models.py +++ b/kobo/apps/audit_log/tests/test_models.py @@ -202,7 +202,8 @@ class AccessLogModelManagerTestCase(BaseTestCase): def test_access_log_manager_only_gets_access_logs(self): user = User.objects.get(username='someuser') - non_access_log = AuditLog.objects.create( + # non-access log + AuditLog.objects.create( user=user, log_type=AuditType.DATA_EDITING, action=AuditAction.CREATE, @@ -248,12 +249,12 @@ def test_with_submissions_grouped_preserves_non_submissions(self): '2024-01-01T01:45:25.123456+00:00' ) user = User.objects.get(username='someuser') - log_1 = AccessLog.objects.create( + AccessLog.objects.create( user=user, metadata={'auth_type': 'Token', 'identify_me': '1'}, date_created=jan_1_1_30_am, ) - log_2 = AccessLog.objects.create( + AccessLog.objects.create( user=user, metadata={'auth_type': 'Token', 'identify_me': '2'}, date_created=jan_1_1_45_am, @@ -288,22 +289,25 @@ def test_with_submissions_grouped_groups_submissions(self): user1 = User.objects.get(username='someuser') user2 = User.objects.get(username='anotheruser') - user_1_submission_1 = AccessLog.objects.create( + # two submissions for user1 between 1-2am + AccessLog.objects.create( user=user1, metadata={'auth_type': ACCESS_LOG_SUBMISSION_AUTH_TYPE}, date_created=jan_1_1_30_am, ) - user1_submission_2 = AccessLog.objects.create( + AccessLog.objects.create( user=user1, metadata={'auth_type': ACCESS_LOG_SUBMISSION_AUTH_TYPE}, date_created=jan_1_1_45_am, ) - user1_submission_3 = AccessLog.objects.create( + # one submission for user1 after 2am + AccessLog.objects.create( user=user1, metadata={'auth_type': ACCESS_LOG_SUBMISSION_AUTH_TYPE}, date_created=jan_1_2_15_am, ) - user2_submission_1 = AccessLog.objects.create( + # one submission for user2 between 1-2am + AccessLog.objects.create( user=user2, metadata={'auth_type': ACCESS_LOG_SUBMISSION_AUTH_TYPE}, date_created=jan_1_1_30_am, @@ -331,7 +335,7 @@ def test_with_submissions_grouped_groups_submissions(self): ACCESS_LOG_SUBMISSION_GROUP_AUTH_TYPE, ) - # should only + # one group for user2 user_2_groups = results.filter(user__username='anotheruser') self.assertEqual(user_2_groups.count(), 1) user_2_group_1 = user_2_groups.first() diff --git a/kobo/apps/audit_log/tests/test_one_time_auth.py b/kobo/apps/audit_log/tests/test_one_time_auth.py index 3068b90681..a4bb289dc2 100644 --- a/kobo/apps/audit_log/tests/test_one_time_auth.py +++ b/kobo/apps/audit_log/tests/test_one_time_auth.py @@ -107,7 +107,8 @@ def test_digest_auth_creates_logs(self): """ def side_effect(request): - # Digest authentication sets request.user, so include that as a side effect when necessary + # Digest authentication sets request.user, + # so include that as a side effect when necessary request.user = TestOneTimeAuthentication.user return mock.DEFAULT @@ -134,7 +135,7 @@ def side_effect(request): ) def test_any_auth_for_submissions(self, authetication_method): """ - Test any normal one-time authenticated submission results in a submission access log + Test most one-time authenticated submissions result in a submission access log """ with patch( @@ -143,7 +144,7 @@ def test_any_auth_for_submissions(self, authetication_method): ): # assume the submission works, we don't actually care with patch( - 'kobo.apps.openrosa.apps.api.viewsets.xform_submission_api.XFormSubmissionApi.create', + 'kobo.apps.openrosa.apps.api.viewsets.xform_submission_api.XFormSubmissionApi.create', # noqa return_value=HttpResponse(status=200), ): # try both v1 and v2 @@ -174,7 +175,7 @@ def side_effect(request): ): # assume the submission works, we don't actually care with patch( - 'kobo.apps.openrosa.apps.api.viewsets.xform_submission_api.XFormSubmissionApi.create', + 'kobo.apps.openrosa.apps.api.viewsets.xform_submission_api.XFormSubmissionApi.create', # noqa return_value=HttpResponse(status=200), ): # check v1 and v2 diff --git a/kpi/fields/username_hyperlinked.py b/kpi/fields/username_hyperlinked.py index 60b4cf47bb..3dd73b4097 100644 --- a/kpi/fields/username_hyperlinked.py +++ b/kpi/fields/username_hyperlinked.py @@ -4,7 +4,7 @@ class UsernameHyperlinkField(serializers.HyperlinkedRelatedField): """ - Special hyperlinked field to handle when a query returns a dict rather than a User object + Special hyperlinked field to handle a dict rather than a User object """ queryset = get_user_model().objects.all()