Skip to content

Commit

Permalink
CONCD-749 don't hardcode user ID (#2328)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasarkar authored Mar 28, 2024
1 parent 867e0ea commit fe186fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
20 changes: 9 additions & 11 deletions concordia/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,8 @@ def _asset_reservation_test_payload(self, user_id, anonymous=False):
expected_update_queries = 2
if not anonymous and settings.SESSION_ENGINE.endswith("db"):
expected_update_queries += 1
expected_acquire_queries = expected_update_queries
if not anonymous:
# + 1 get user ID from request
expected_acquire_queries += 1
# + 1 get user ID from request
expected_acquire_queries = expected_update_queries + 1

with self.assertNumQueries(expected_acquire_queries):
resp = self.client.post(reverse("reserve-asset", args=(asset.pk,)))
Expand Down Expand Up @@ -549,9 +547,9 @@ def test_asset_reservation_competition(self):
# We'll reserve the test asset as the anonymous user and then attempt
# to edit it after logging in

# 3 queries =
# 1 expiry + 1 acquire
with self.assertNumQueries(2):
# 4 queries =
# 1 expiry + 1 acquire + 2 get user ID from request
with self.assertNumQueries(4):
resp = self.client.post(reverse("reserve-asset", args=(asset.pk,)))
self.assertEqual(200, resp.status_code)
self.assertEqual(1, AssetTranscriptionReservation.objects.count())
Expand Down Expand Up @@ -655,11 +653,11 @@ def test_asset_reservation_tombstone(self):

self.client.logout()

# 1 session check + 1 reservation check + 1 acquire
# 1 reservation check + 1 acquire + 2 get user ID from request
expected_queries = 4
if settings.SESSION_ENGINE.endswith("db"):
expected_queries = 3
else:
expected_queries = 2
# + 1 session check
expected_queries += 1

with self.assertNumQueries(expected_queries):
resp = self.client.post(reverse("reserve-asset", args=(asset.pk,)))
Expand Down
2 changes: 1 addition & 1 deletion concordia/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_or_create_reservation_token(request):
# We should probably call get_anonymous_user,
# but I'm going to avoid doing so since it would
# incur yet *another* database query
uid = 8
uid = get_anonymous_user().id
request.session["reservation_token"] += str(uid).zfill(6)
return request.session["reservation_token"]

Expand Down

0 comments on commit fe186fe

Please sign in to comment.