Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : master
---------------------------------------------------------------
commit 177ef3a473b3a7576b2620fed55e3e74dac35bc6
Author: Jakub Kadl����k <jkadlcik(a)redhat.com>
Date: Wed Nov 18 12:31:32 2015 +0100
[python] add Entity tests
---------------------------------------------------------------
python/copr/test/client_v2/test_entities.py | 40 +++++++++++++++++++++++++++
1 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/python/copr/test/client_v2/test_entities.py
b/python/copr/test/client_v2/test_entities.py
new file mode 100644
index 0000000..44b008d
--- /dev/null
+++ b/python/copr/test/client_v2/test_entities.py
@@ -0,0 +1,40 @@
+# coding: utf-8
+# pylint: disable=E1101, C0102
+import pytest
+from copr.client_v2.schemas import Schema, fields
+from copr.client_v2.entities import Entity
+
+
+class FooSchema(Schema):
+ foo = fields.Str()
+ bar = fields.Int()
+
+
+class FooEntity(Entity):
+ _schema = FooSchema()
+
+
+class TestEntities(object):
+
+ entity = None
+
+ # pylint: disable=W0613
+ def setup_method(self, method):
+ self.entity = FooEntity.from_dict({"foo": "baz",
"bar": 123, "non_existing_attribute": None})
+
+ def test_from_dict(self):
+ assert self.entity.foo == "baz"
+ assert self.entity.bar == 123
+ assert not hasattr(self.entity, "non_existing_attribute")
+
+ with pytest.raises(AttributeError):
+ assert self.entity.non_existing_attribute
+
+ def test_to_dict(self):
+ assert set(self.entity.to_dict().items()) == \
+ set([("foo", "baz"), ("bar", 123)])
+
+ def test_to_json(self):
+ assert self.entity.to_json() == \
+ '{"foo": "baz", "bar": 123}'
+