Skip to content

Commit

Permalink
fixup!: more formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rgraber committed Sep 19, 2024
1 parent 42eadd0 commit d7b3bfa
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
5 changes: 3 additions & 2 deletions kobo/apps/audit_log/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion kobo/apps/audit_log/tests/api/v2/test_api_audit_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions kobo/apps/audit_log/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 5 additions & 4 deletions kobo/apps/audit_log/tests/test_one_time_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion kpi/fields/username_hyperlinked.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit d7b3bfa

Please sign in to comment.