From ac9d4c84a115c6c8d3aea04ed55635e8e743ea1d Mon Sep 17 00:00:00 2001
From: David Douard <david.douard@sdfa3.org>
Date: Thu, 12 Mar 2020 14:27:23 +0100
Subject: [PATCH] tests: add low level tests for the Timestamp model entity

---
 swh/model/tests/test_model.py | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/swh/model/tests/test_model.py b/swh/model/tests/test_model.py
index c5dbc59c..35d5695d 100644
--- a/swh/model/tests/test_model.py
+++ b/swh/model/tests/test_model.py
@@ -6,6 +6,8 @@
 import copy
 import datetime
 
+import attr
+from attrs_strict import AttributeTypeError
 from hypothesis import given
 from hypothesis.strategies import binary
 import pytest
@@ -70,6 +72,33 @@ def test_todict_origin_visit_updates(origin_visit_update):
     assert origin_visit_update == type(origin_visit_update).from_dict(obj)
 
 
+def test_timestamp_seconds():
+    attr.validate(Timestamp(seconds=0, microseconds=0))
+    with pytest.raises(AttributeTypeError):
+        Timestamp(seconds='0', microseconds=0)
+
+    attr.validate(Timestamp(seconds=2**63-1, microseconds=0))
+    with pytest.raises(ValueError):
+        Timestamp(seconds=2**63, microseconds=0)
+
+    attr.validate(Timestamp(seconds=-2**63, microseconds=0))
+    with pytest.raises(ValueError):
+        Timestamp(seconds=-2**63-1, microseconds=0)
+
+
+def test_timestamp_microseconds():
+    attr.validate(Timestamp(seconds=0, microseconds=0))
+    with pytest.raises(AttributeTypeError):
+        Timestamp(seconds=0, microseconds='0')
+
+    attr.validate(Timestamp(seconds=0, microseconds=10**6-1))
+    with pytest.raises(ValueError):
+        Timestamp(seconds=0, microseconds=10**6)
+
+    with pytest.raises(ValueError):
+        Timestamp(seconds=0, microseconds=-1)
+
+
 def test_timestampwithtimezone_from_datetime():
     tz = datetime.timezone(datetime.timedelta(minutes=+60))
     date = datetime.datetime(
-- 
GitLab