GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit 6aaa438e authored by juga  's avatar juga
Browse files

fix: tests: Add test for remove old consensus ts

Tests don't pass in this commit, it's fixed in the next commits.
parent 3ec1a8e6
"""relaylist.py unit tests."""
from datetime import datetime, timedelta
# When datetime is imported as a class (`from datetime import datetime`) it can
# not be mocked because it is a built-in type. It can only be mocked when
# imported as module.
# freezegun is able to mock any datetime object, it also allows comparations.
from freezegun import freeze_time
from sbws.lib.relaylist import remove_old_consensus_timestamps
def test_remove_old_consensus_timestamps():
days_ago = datetime(2020, 3, 1)
timestamps = [days_ago] + [
days_ago + timedelta(days=x) for x in range(1, 5)
]
with freeze_time(days_ago + timedelta(days=5, seconds=1)):
new_timestamps = remove_old_consensus_timestamps(
timestamps, 5 * 24 * 60 * 60
)
assert len(new_timestamps) == len(timestamps) - 1
assert days_ago not in new_timestamps
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment