mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
add aurweb.time module
This module includes timezone-based utilities for a FastAPI request. This commit introduces use of the AURTZ cookie within get_request_timezone. This cookie should be set to the user or session's timezone. * `make_context` has been modified to parse the request's timezone and include the "timezone" and "timezones" variables, along with a timezone specified "now" date. + Added `Timezone` attribute to aurweb.testing.requests.Request.user. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
07d5907ecd
commit
9052688ed2
4 changed files with 104 additions and 4 deletions
33
test/test_time.py
Normal file
33
test/test_time.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
import aurweb.config
|
||||
|
||||
from aurweb.testing.requests import Request
|
||||
from aurweb.time import get_request_timezone, tz_offset
|
||||
|
||||
|
||||
def test_tz_offset_utc():
|
||||
offset = tz_offset("UTC")
|
||||
assert offset == "+00:00"
|
||||
|
||||
|
||||
def test_tz_offset_mst():
|
||||
offset = tz_offset("MST")
|
||||
assert offset == "-07:00"
|
||||
|
||||
|
||||
def test_request_timezone():
|
||||
request = Request()
|
||||
tz = get_request_timezone(request)
|
||||
assert tz == aurweb.config.get("options", "default_timezone")
|
||||
|
||||
|
||||
def test_authenticated_request_timezone():
|
||||
# Modify a fake request to be authenticated with the
|
||||
# America/Los_Angeles timezone.
|
||||
request = Request()
|
||||
request.user.authenticated = True
|
||||
request.user.Timezone = "America/Los_Angeles"
|
||||
|
||||
# Get the request's timezone, it should be America/Los_Angeles.
|
||||
tz = get_request_timezone(request)
|
||||
assert tz == request.user.Timezone
|
||||
assert tz == "America/Los_Angeles"
|
Loading…
Add table
Add a link
Reference in a new issue