[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [sbws/maint-1.1] fix: tests: Add test for remove old consensus ts
commit 6aaa438e4c6e623afda7d0251b43cb48a8bc7a58
Author: juga0 <juga@xxxxxxxxxx>
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
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits