Skip to content

Commit

Permalink
Force UTC timezone for all datetime objects
Browse files Browse the repository at this point in the history
The specification defines datetime as UTC time zone.
python-tuf updated all their datetime objects, so it's time we do it now
as well.

I also used the opportunity to add MOCK_PATH constants to simplify
mocking and fake_datetime fixture, so we can reuse it.

Signed-off-by: Martin Vrachev <[email protected]>
  • Loading branch information
MVrachev committed Apr 9, 2024
1 parent f9fdfc2 commit fb0eac8
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 389 deletions.
8 changes: 4 additions & 4 deletions repository_service_tuf_api/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# SPDX-License-Identifier: MIT

import json
from datetime import datetime
from datetime import datetime, timezone
from typing import Any, Dict, List

from fastapi import HTTPException, status
Expand Down Expand Up @@ -201,7 +201,7 @@ def post(payload: AddPayload) -> ResponsePostAdd:
data = {
"artifacts": [artifact.path for artifact in payload.artifacts],
"task_id": task_id,
"last_update": datetime.now(),
"last_update": datetime.now(timezone.utc),
}
return ResponsePostAdd(data=data, message=message)

Expand Down Expand Up @@ -239,7 +239,7 @@ def delete(payload: DeletePayload) -> ResponsePostDelete:
data = {
"artifacts": payload.artifacts,
"task_id": task_id,
"last_update": datetime.now(),
"last_update": datetime.now(timezone.utc),
}

message = "Remove Artifact(s) successfully submitted."
Expand All @@ -263,7 +263,7 @@ def post_publish_artifacts() -> ResponsePostPublish:
data = {
"artifacts": [],
"task_id": task_id,
"last_update": datetime.now(),
"last_update": datetime.now(timezone.utc),
}

return ResponsePostPublish(
Expand Down
4 changes: 2 additions & 2 deletions repository_service_tuf_api/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import logging
import re
import time
from datetime import datetime
from datetime import datetime, timezone
from threading import Thread
from typing import Any, Dict, List, Optional

Expand Down Expand Up @@ -233,7 +233,7 @@ def post_bootstrap(payload: BootstrapPayload) -> BootstrapPostResponse:

data = {
"task_id": task_id,
"last_update": datetime.now(),
"last_update": datetime.now(timezone.utc),
}

return BootstrapPostResponse(
Expand Down
4 changes: 2 additions & 2 deletions repository_service_tuf_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# SPDX-License-Identifier: MIT

import json
from datetime import datetime
from datetime import datetime, timezone
from typing import Any, Dict

from fastapi import HTTPException, status
Expand Down Expand Up @@ -85,7 +85,7 @@ def put(payload: PutPayload):

data = {
"task_id": task_id,
"last_update": datetime.now(),
"last_update": datetime.now(timezone.utc),
}

return PutResponse(data=data, message="Settings successfully submitted.")
Expand Down
8 changes: 4 additions & 4 deletions repository_service_tuf_api/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# SPDX-License-Identifier: MIT

import json
from datetime import datetime
from datetime import datetime, timezone
from typing import Dict, Literal

from fastapi import HTTPException, status
Expand Down Expand Up @@ -83,7 +83,7 @@ def post_metadata(payload: MetadataPostPayload) -> MetadataPostResponse:
message = "Metadata update accepted."
data = {
"task_id": task_id,
"last_update": datetime.now(),
"last_update": datetime.now(timezone.utc),
}
return MetadataPostResponse(data=data, message=message)

Expand Down Expand Up @@ -224,7 +224,7 @@ def post_metadata_sign(
message = "Metadata sign accepted."
data = {
"task_id": task_id,
"last_update": datetime.now(),
"last_update": datetime.now(timezone.utc),
}

return MetadataPostResponse(data=data, message=message)
Expand Down Expand Up @@ -283,7 +283,7 @@ def delete_metadata_sign(payload: MetadataSignDeletePayload):
message = "Metadata sign delete accepted."
data = {
"task_id": task_id,
"last_update": datetime.now(),
"last_update": datetime.now(timezone.utc),
}

return MetadataSignDeleteResponse(data=data, message=message)
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# SPDX-FileCopyrightText: 2022-2023 VMware Inc
#
# SPDX-License-Identifier: MIT
from datetime import datetime, timezone

import pretend
import pytest
from fastapi.testclient import TestClient

Expand All @@ -13,3 +16,9 @@ def test_client(monkeypatch):
client = TestClient(rstuf_app)

return client


@pytest.fixture()
def fake_datetime(monkeypatch):
fake_time = datetime(2019, 6, 16, 9, 5, 1, tzinfo=timezone.utc)
return pretend.stub(now=pretend.call_recorder(lambda a: fake_time))
Loading

0 comments on commit fb0eac8

Please sign in to comment.