mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
housekeep: replace deprecated datetime functions
tests show warnings for deprecated utc functions with python 3.12 Signed-off-by: moson <moson@archlinux.org>
This commit is contained in:
parent
ffddf63975
commit
afb7af3e27
9 changed files with 21 additions and 21 deletions
|
@ -1,4 +1,4 @@
|
|||
from datetime import datetime
|
||||
from datetime import UTC, datetime
|
||||
|
||||
|
||||
class Benchmark:
|
||||
|
@ -7,7 +7,7 @@ class Benchmark:
|
|||
|
||||
def _timestamp(self) -> float:
|
||||
"""Generate a timestamp."""
|
||||
return float(datetime.utcnow().timestamp())
|
||||
return float(datetime.now(UTC).timestamp())
|
||||
|
||||
def start(self) -> int:
|
||||
"""Start a benchmark."""
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import copy
|
||||
import math
|
||||
from datetime import datetime
|
||||
from datetime import UTC, datetime
|
||||
from typing import Any, Union
|
||||
from urllib.parse import quote_plus, urlencode
|
||||
from zoneinfo import ZoneInfo
|
||||
|
@ -94,7 +94,7 @@ def tn(context: dict[str, Any], count: int, singular: str, plural: str) -> str:
|
|||
|
||||
@register_filter("dt")
|
||||
def timestamp_to_datetime(timestamp: int):
|
||||
return datetime.utcfromtimestamp(int(timestamp))
|
||||
return datetime.fromtimestamp(timestamp, UTC)
|
||||
|
||||
|
||||
@register_filter("as_timezone")
|
||||
|
|
|
@ -3,7 +3,7 @@ import importlib
|
|||
import os
|
||||
import sys
|
||||
import traceback
|
||||
from datetime import datetime
|
||||
from datetime import UTC, datetime
|
||||
|
||||
import orjson
|
||||
import pygit2
|
||||
|
@ -60,7 +60,7 @@ def update_repository(repo: pygit2.Repository):
|
|||
except pygit2.GitError:
|
||||
base = []
|
||||
|
||||
utcnow = datetime.utcnow()
|
||||
utcnow = datetime.now(UTC)
|
||||
author = pygit2.Signature(
|
||||
config.get("git-archive", "author"),
|
||||
config.get("git-archive", "author-email"),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import zoneinfo
|
||||
from collections import OrderedDict
|
||||
from datetime import datetime
|
||||
from datetime import UTC, datetime
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from fastapi import Request
|
||||
|
@ -89,4 +89,4 @@ def utcnow() -> int:
|
|||
|
||||
:return: Current UTC timestamp
|
||||
"""
|
||||
return int(datetime.utcnow().timestamp())
|
||||
return int(datetime.now(UTC).timestamp())
|
||||
|
|
|
@ -15,7 +15,7 @@ import os
|
|||
import random
|
||||
import sys
|
||||
import time
|
||||
from datetime import datetime
|
||||
from datetime import UTC, datetime
|
||||
|
||||
import bcrypt
|
||||
|
||||
|
@ -263,7 +263,7 @@ for p in list(seen_pkgs.keys()):
|
|||
out.write(s)
|
||||
|
||||
# Cast votes
|
||||
utcnow = int(datetime.utcnow().timestamp())
|
||||
utcnow = int(datetime.now(UTC).timestamp())
|
||||
|
||||
track_votes = {}
|
||||
log.debug("Casting votes for packages.")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import re
|
||||
import tempfile
|
||||
from datetime import datetime
|
||||
from datetime import UTC, datetime
|
||||
from http import HTTPStatus
|
||||
from logging import DEBUG
|
||||
from subprocess import Popen
|
||||
|
@ -394,7 +394,7 @@ def test_post_register_error_ip_banned(client: TestClient):
|
|||
# 'testclient' is our fallback value in case request.client is None
|
||||
# which is the case for TestClient
|
||||
with db.begin():
|
||||
create(Ban, IPAddress="testclient", BanTS=datetime.utcnow())
|
||||
create(Ban, IPAddress="testclient", BanTS=datetime.now(UTC))
|
||||
|
||||
with client as request:
|
||||
response = post_register(request)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import warnings
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import UTC, datetime, timedelta
|
||||
|
||||
import pytest
|
||||
from sqlalchemy import exc as sa_exc
|
||||
|
@ -17,7 +17,7 @@ def setup(db_test):
|
|||
|
||||
@pytest.fixture
|
||||
def ban() -> Ban:
|
||||
ts = datetime.utcnow() + timedelta(seconds=30)
|
||||
ts = datetime.now(UTC) + timedelta(seconds=30)
|
||||
with db.begin():
|
||||
ban = create(Ban, IPAddress="127.0.0.1", BanTS=ts)
|
||||
yield ban
|
||||
|
@ -30,7 +30,7 @@ def test_ban(ban: Ban):
|
|||
|
||||
def test_invalid_ban():
|
||||
with pytest.raises(sa_exc.IntegrityError):
|
||||
bad_ban = Ban(BanTS=datetime.utcnow())
|
||||
bad_ban = Ban(BanTS=datetime.now(UTC))
|
||||
|
||||
# We're adding a ban with no primary key; this causes an
|
||||
# SQLAlchemy warnings when committing to the DB.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from datetime import datetime
|
||||
from datetime import UTC, datetime
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
import pytest
|
||||
|
@ -8,7 +8,7 @@ from aurweb import filters, time
|
|||
|
||||
def test_timestamp_to_datetime():
|
||||
ts = time.utcnow()
|
||||
dt = datetime.utcfromtimestamp(int(ts))
|
||||
dt = datetime.fromtimestamp(ts, UTC)
|
||||
assert filters.timestamp_to_datetime(ts) == dt
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import hashlib
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import UTC, datetime, timedelta
|
||||
|
||||
import bcrypt
|
||||
import pytest
|
||||
|
@ -135,7 +135,7 @@ def test_user_login_twice(user: User):
|
|||
|
||||
def test_user_login_banned(user: User):
|
||||
# Add ban for the next 30 seconds.
|
||||
banned_timestamp = datetime.utcnow() + timedelta(seconds=30)
|
||||
banned_timestamp = datetime.now(UTC) + timedelta(seconds=30)
|
||||
with db.begin():
|
||||
db.create(Ban, IPAddress="127.0.0.1", BanTS=banned_timestamp)
|
||||
|
||||
|
@ -170,7 +170,7 @@ def test_user_login_with_outdated_sid(user: User):
|
|||
Session,
|
||||
UsersID=user.ID,
|
||||
SessionID="stub",
|
||||
LastUpdateTS=datetime.utcnow().timestamp() - 5,
|
||||
LastUpdateTS=datetime.now(UTC).timestamp() - 5,
|
||||
)
|
||||
sid = user.login(Request(), "testPassword")
|
||||
assert sid and user.is_authenticated()
|
||||
|
@ -279,7 +279,7 @@ def test_user_is_developer(user: User):
|
|||
|
||||
def test_user_voted_for(user: User, package: Package):
|
||||
pkgbase = package.PackageBase
|
||||
now = int(datetime.utcnow().timestamp())
|
||||
now = int(datetime.now(UTC).timestamp())
|
||||
with db.begin():
|
||||
db.create(PackageVote, PackageBase=pkgbase, User=user, VoteTS=now)
|
||||
assert user.voted_for(package)
|
||||
|
|
Loading…
Add table
Reference in a new issue