From edefc3da72c1ce83c6ed9b75b252fbb2104cadab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com> Date: Thu, 23 Jan 2020 12:27:02 +0100 Subject: [PATCH] added test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Henrik tom Wörden <h.tomwoerden@indiscale.com> --- src/caosdb/common/models.py | 3 +- unittests/test_entity.py | 58 ++++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py index 495b4de5..2916f8af 100644 --- a/src/caosdb/common/models.py +++ b/src/caosdb/common/models.py @@ -38,8 +38,6 @@ from sys import hexversion from tempfile import NamedTemporaryFile from warnings import warn -from lxml import etree - from caosdb.common.utils import uuid, xml2str from caosdb.configuration import get_config from caosdb.connection.connection import get_connection @@ -50,6 +48,7 @@ from caosdb.exceptions import (AmbiguityException, AuthorizationException, EntityHasNoDatatypeError, TransactionError, UniqueNamesError, UnqualifiedParentsError, UnqualifiedPropertiesError, URITooLongException) +from lxml import etree _ENTITY_URI_SEGMENT = "Entity" diff --git a/unittests/test_entity.py b/unittests/test_entity.py index d0f4089c..a8f96785 100644 --- a/unittests/test_entity.py +++ b/unittests/test_entity.py @@ -23,35 +23,45 @@ # """Tests for the Entity class.""" # pylint: disable=missing-docstring -from nose.tools import (assert_is_not_none as there, assert_true as tru, - assert_equal as eq) -from caosdb import Entity, configure_connection -from caosdb.connection.mockup import MockUpServerConnection +import unittest +from caosdb import Entity, Property, Record, RecordType, configure_connection +from caosdb.connection.mockup import MockUpServerConnection -def setup_module(): - there(Entity) - configure_connection(url="unittests", username="testuser", - password="testpassword", timeout=200, - implementation=MockUpServerConnection) +class TestEntity(unittest.TestCase): + def setUp(self): + self.assertIsNotNone(Entity) + configure_connection(url="unittests", username="testuser", + password="testpassword", timeout=200, + implementation=MockUpServerConnection) -def hat(obj, attr): - tru(hasattr(obj, attr)) + def test_instance_variables(self): + entity = Entity() + self.assertTrue(hasattr(entity, "role")) + self.assertTrue(hasattr(entity, "id")) + self.assertTrue(hasattr(entity, "name")) + self.assertTrue(hasattr(entity, "description")) + self.assertTrue(hasattr(entity, "parents")) + self.assertTrue(hasattr(entity, "properties")) + def test_role(self): + entity = Entity(role="TestRole") + self.assertEqual(entity.role, "TestRole") + entity.role = "TestRole2" + self.assertEqual(entity.role, "TestRole2") -def test_instance_variables(): - entity = Entity() - hat(entity, "role") - hat(entity, "id") - hat(entity, "name") - hat(entity, "description") - hat(entity, "parents") - hat(entity, "properties") + def test_apply_to_ids(self): + parent = RecordType(id=3456) + rec = Record(id=23) + p = Property(id=23345) + rec.add_parent(parent) + rec.add_property(p) + def invert(id_): + return id_ * -1 + rec.apply_to_ids(invert) -def test_role(): - entity = Entity(role="TestRole") - eq(entity.role, "TestRole") - entity.role = "TestRole2" - eq(entity.role, "TestRole2") + self.assertEqual(parent.id, -3456) + self.assertEqual(p.id, -23345) + self.assertEqual(rec.id, -23) -- GitLab