Fixed timezone being returned incorrectly
Happened if you've set TZ to non-UTC. Apparently astimezone and replace doesn't do the same thing even if tzinfo is None.
This commit is contained in:
@@ -6,6 +6,7 @@ services:
|
||||
environment:
|
||||
- COCKROACH_USER=john
|
||||
- COCKROACH_DATABASE=spoolman
|
||||
- TZ=Asia/Seoul
|
||||
healthcheck:
|
||||
test:
|
||||
[
|
||||
@@ -26,6 +27,7 @@ services:
|
||||
- SPOOLMAN_DB_NAME=spoolman
|
||||
- SPOOLMAN_DB_USERNAME=john
|
||||
- SPOOLMAN_LOGGING_LEVEL=INFO
|
||||
- TZ=Europe/Stockholm
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
|
||||
@@ -8,6 +8,7 @@ services:
|
||||
- MARIADB_PASSWORD=abc
|
||||
- MARIADB_DATABASE=spoolman
|
||||
- MARIADB_MYSQL_LOCALHOST_USER=true
|
||||
- TZ=Asia/Seoul
|
||||
healthcheck:
|
||||
test:
|
||||
[
|
||||
@@ -30,6 +31,7 @@ services:
|
||||
- SPOOLMAN_DB_USERNAME=john
|
||||
- SPOOLMAN_DB_PASSWORD=abc
|
||||
- SPOOLMAN_LOGGING_LEVEL=INFO
|
||||
- TZ=Europe/Stockholm
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
|
||||
@@ -4,6 +4,8 @@ services:
|
||||
image: postgres:11-alpine
|
||||
environment:
|
||||
- POSTGRES_PASSWORD=abc
|
||||
- TZ='GMT+4'
|
||||
- PGTZ='GMT+4'
|
||||
spoolman:
|
||||
image: donkie/spoolman:test
|
||||
environment:
|
||||
@@ -14,6 +16,7 @@ services:
|
||||
- SPOOLMAN_DB_USERNAME=postgres
|
||||
- SPOOLMAN_DB_PASSWORD=abc
|
||||
- SPOOLMAN_LOGGING_LEVEL=INFO
|
||||
- TZ=Europe/Stockholm
|
||||
depends_on:
|
||||
- db
|
||||
tester:
|
||||
|
||||
@@ -4,6 +4,7 @@ services:
|
||||
image: donkie/spoolman:test
|
||||
environment:
|
||||
- SPOOLMAN_LOGGING_LEVEL=INFO
|
||||
- TZ=Europe/Stockholm
|
||||
tester:
|
||||
image: donkie/spoolman-tester:latest
|
||||
volumes:
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import asyncio
|
||||
import math
|
||||
from datetime import datetime, timezone
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
@@ -41,6 +42,14 @@ def test_use_spool_weight(random_filament: dict[str, Any], use_weight: float):
|
||||
assert spool["used_weight"] == pytest.approx(max(use_weight, 0))
|
||||
assert spool["remaining_weight"] == pytest.approx(min(max(start_weight - use_weight, 0), filament_net_weight))
|
||||
|
||||
# Verify that first_used has been updated
|
||||
diff = abs((datetime.now(tz=timezone.utc) - datetime.fromisoformat(spool["first_used"])).total_seconds())
|
||||
assert diff < 60
|
||||
|
||||
# Verify that last_used has been updated
|
||||
diff = abs((datetime.now(tz=timezone.utc) - datetime.fromisoformat(spool["last_used"])).total_seconds())
|
||||
assert diff < 60
|
||||
|
||||
# Clean up
|
||||
httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status()
|
||||
|
||||
@@ -56,6 +65,7 @@ def test_use_spool_length(random_filament: dict[str, Any], use_length: float):
|
||||
json={
|
||||
"filament_id": random_filament["id"],
|
||||
"remaining_weight": start_weight,
|
||||
"first_used": "2023-01-01T00:00:00Z",
|
||||
},
|
||||
)
|
||||
result.raise_for_status()
|
||||
@@ -79,6 +89,13 @@ def test_use_spool_length(random_filament: dict[str, Any], use_length: float):
|
||||
assert spool["used_weight"] == pytest.approx(max(use_weight, 0))
|
||||
assert spool["remaining_weight"] == pytest.approx(min(max(start_weight - use_weight, 0), filament_net_weight))
|
||||
|
||||
# Verify that first_used hasn't been updated since it was already set
|
||||
assert spool["first_used"] == "2023-01-01T00:00:00Z"
|
||||
|
||||
# Verify that last_used has been updated
|
||||
diff = abs((datetime.now(tz=timezone.utc) - datetime.fromisoformat(spool["last_used"])).total_seconds())
|
||||
assert diff < 60
|
||||
|
||||
# Clean up
|
||||
httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user