[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [sbws/maint-1.1] fix: tests: Add test timestamp.is_old



commit feae0a57e7ec14b1904d56d2f6081605a996f086
Author: juga0 <juga@xxxxxxxxxx>
Date:   Tue Mar 3 18:36:42 2020 +0000

    fix: tests: Add test timestamp.is_old
    
    The tests don't pass in this commit, it's fixed in the next ones.
---
 tests/unit/util/test_timestamp.py | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/tests/unit/util/test_timestamp.py b/tests/unit/util/test_timestamp.py
index 8ebc2f6..37cc9ea 100644
--- a/tests/unit/util/test_timestamp.py
+++ b/tests/unit/util/test_timestamp.py
@@ -1,9 +1,8 @@
 # -*- coding: utf-8 -*-
 """Test timestamp conversion util functions"""
-from datetime import datetime, timezone
-
+from datetime import datetime, timezone, timedelta
 from sbws.util.timestamp import (dt_obj_to_isodt_str, unixts_to_dt_obj,
-                                 unixts_to_isodt_str, unixts_to_str)
+                                 unixts_to_isodt_str, unixts_to_str, is_old)
 
 
 isodt_str = '2018-05-23T12:55:04'
@@ -25,3 +24,14 @@ def test_unixts_to_isodt_str():
 
 def test_unixts_to_str():
     assert str(unixts) == unixts_to_str(unixts)
+
+
+def test_is_old():
+    # Since this timestamp is generated a few microseconds before checking
+    # the oldest timestamp, it will be old.
+    old_timestamp = datetime.utcnow() - timedelta(days=5)
+    assert is_old(old_timestamp)
+    # A recent timestamp should be at least 1 second newer that the oldest
+    recent_timestamp = datetime.utcnow() - timedelta(days=5) \
+        + timedelta(seconds=1)
+    assert not is_old(recent_timestamp)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits