[tor-commits] [sbws/master] fix: tests: Add test for remove old consensus ts
juga at torproject.org
juga at torproject.org
Mon Mar 9 18:01:37 UTC 2020
commit 6aaa438e4c6e623afda7d0251b43cb48a8bc7a58
Author: juga0 <juga at riseup.net>
Date: Sun Mar 8 16:36:44 2020 +0000
fix: tests: Add test for remove old consensus ts
Tests don't pass in this commit, it's fixed in the next commits.
---
tests/unit/lib/test_relaylist.py | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/tests/unit/lib/test_relaylist.py b/tests/unit/lib/test_relaylist.py
new file mode 100644
index 0000000..3dec382
--- /dev/null
+++ b/tests/unit/lib/test_relaylist.py
@@ -0,0 +1,23 @@
+"""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
More information about the tor-commits
mailing list