Skip to content

Commit dcf6234

Browse files
committed
tests: Fake datetime.now() when using mock staging
The current staging TUF assets expire in 3 days: mock datetime.now() so they seem valid in the tests. This is absolutely quite sketchy but seems to work. Signed-off-by: Jussi Kukkonen <[email protected]>
1 parent f94c3f0 commit dcf6234

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

test/unit/conftest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from __future__ import annotations
1616

1717
import base64
18+
import datetime
1819
import os
1920
import re
2021
from collections import defaultdict
@@ -158,6 +159,16 @@ def _fetch(self, url: str) -> Iterator[bytes]:
158159

159160
monkeypatch.setattr(updater, "Urllib3Fetcher", lambda app_user_agent: MockFetcher())
160161

162+
# Using the staging TUF assets is a nice way to test but staging tuf assets expire in
163+
# 3 days so faking now() becomes necessary. This correctly affects checks in
164+
# _internal/trust.py as well
165+
class mydatetime(datetime.datetime):
166+
@classmethod
167+
def now(cls, tz=None):
168+
return datetime.datetime(2025, 5, 6, 0, 0, 0, 0, datetime.UTC)
169+
170+
monkeypatch.setattr(datetime, 'datetime', mydatetime)
171+
161172
return success, failure
162173

163174

0 commit comments

Comments
 (0)