housekeep: define filters in their own modules

This patch cleans up aurweb.templates and removes direct
module-level initialization of the environment.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2022-01-18 03:06:17 -08:00
parent fca175ed84
commit 211ca5e49c
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
16 changed files with 159 additions and 159 deletions

View file

@ -1,8 +1,6 @@
import json
from datetime import datetime
from http import HTTPStatus
from zoneinfo import ZoneInfo
import fastapi
import pytest
@ -13,38 +11,6 @@ from aurweb import filters, util
from aurweb.testing.requests import Request
def test_timestamp_to_datetime():
ts = datetime.utcnow().timestamp()
dt = datetime.utcfromtimestamp(int(ts))
assert util.timestamp_to_datetime(ts) == dt
def test_as_timezone():
ts = datetime.utcnow().timestamp()
dt = util.timestamp_to_datetime(ts)
assert util.as_timezone(dt, "UTC") == dt.astimezone(tz=ZoneInfo("UTC"))
def test_number_format():
assert util.number_format(0.222, 2) == "0.22"
assert util.number_format(0.226, 2) == "0.23"
def test_extend_query():
""" Test extension of a query via extend_query. """
query = {"a": "b"}
extended = util.extend_query(query, ("a", "c"), ("b", "d"))
assert extended.get("a") == "c"
assert extended.get("b") == "d"
def test_to_qs():
""" Test conversion from a query dictionary to a query string. """
query = {"a": "b", "c": [1, 2, 3]}
qs = util.to_qs(query)
assert qs == "a=b&c=1&c=2&c=3"
def test_round():
assert filters.do_round(1.3) == 1
assert filters.do_round(1.5) == 2