Skip to content

Commit

Permalink
Add test for submission endpoint with specified UTC offset
Browse files Browse the repository at this point in the history
  • Loading branch information
TimJentzsch committed Jan 4, 2022
1 parent 0033c0d commit b48e253
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions api/tests/submissions/test_submission_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,38 @@ def test_rate_filtering(self, client: Client,) -> None:
assert response["results"] == [
{"count": 3, "date": "2021-06-20T00:00:00Z"},
]

def test_rate_timezones(self, client: Client,) -> None:
"""Verify that the timezone is applied correctly, if specified."""
client, headers, user = setup_user_client(client, id=123456)

dates = [
# 2020-07-16 23:00 UTC
datetime(2020, 7, 16, 23),
# 2020-07-16 22:00 UTC
datetime(2020, 7, 16, 22),
]

for date in dates:
create_transcription(
create_submission(completed_by=user, complete_time=date),
user,
create_time=make_aware(date),
)

# +01:30 offset
utc_offset = 90 * 60

result = client.get(
reverse("submission-rate")
+ "?time_frame=day&completed_by=123456"
+ f"&utc_offset={utc_offset}",
content_type="application/json",
**headers,
)
assert result.status_code == status.HTTP_200_OK
response = result.json()
assert response["results"] == [
{"count": 1, "date": "2020-07-16T00:00:00+01:30"},
{"count": 1, "date": "2020-07-17T00:00:00+01:30"},
]
2 changes: 1 addition & 1 deletion api/views/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def rate(self, request: Request) -> Response:
include days on which the user did not make any transcriptions!
"""
time_frame = request.GET.get("time_frame", "day")
utc_offset = request.GET.get("utc_offset", 0)
utc_offset = int(request.GET.get("utc_offset", "0"))
# Construct a timezone from the offset
tzinfo = datetime.timezone(datetime.timedelta(seconds=utc_offset))

Expand Down

0 comments on commit b48e253

Please sign in to comment.