From 6909704a0da2f882ed0f57493d120a8d97f4eb10 Mon Sep 17 00:00:00 2001
From: Valentin Lorentz <vlorentz@softwareheritage.org>
Date: Mon, 8 Apr 2019 15:14:13 +0200
Subject: [PATCH] Check recursively that .to_dict() returns a nested dict.

---
 swh/model/tests/test_hypothesis_strategies.py | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/swh/model/tests/test_hypothesis_strategies.py b/swh/model/tests/test_hypothesis_strategies.py
index 52e1211a..7e63d847 100644
--- a/swh/model/tests/test_hypothesis_strategies.py
+++ b/swh/model/tests/test_hypothesis_strategies.py
@@ -20,10 +20,26 @@ def test_generation(obj_type_and_obj):
     attr.validate(object_)
 
 
+def assert_nested_dict(obj):
+    """Tests the object is a nested dict and contains no more class
+    from swh.model.model."""
+    if isinstance(obj, dict):
+        for (key, value) in obj.items():
+            assert isinstance(key, (str, bytes)), key
+            assert_nested_dict(value)
+    elif isinstance(obj, list):
+        for value in obj:
+            assert_nested_dict(value)
+    elif isinstance(obj, (int, float, str, bytes, bool, type(None))):
+        pass
+    else:
+        assert False, obj
+
+
 @given(object_dicts())
 def test_dicts_generation(obj_type_and_obj):
     (obj_type, object_) = obj_type_and_obj
-    assert isinstance(object_, dict)
+    assert_nested_dict(object_)
     if obj_type == 'content':
         if object_['status'] == 'visible':
             assert set(object_) == \
-- 
GitLab