aurweb/test/test_time.py
Kevin Morris 9052688ed2 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>
2021-06-05 20:11:17 -07:00

33 lines
894 B
Python

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"