From 6a00483621baf75eec315d560b459df90e127714 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com>
Date: Wed, 5 Feb 2020 20:41:11 +0000
Subject: [PATCH] FIX: make Entity.get_property case-insensitive

---
 src/caosdb/common/models.py |  4 +++-
 unittests/test_entity.py    | 42 +++++++++++++++++++++----------------
 unittests/test_record.py    | 19 +++++++++++++++--
 3 files changed, 44 insertions(+), 21 deletions(-)

diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py
index 28dc6997..045c5002 100644
--- a/src/caosdb/common/models.py
+++ b/src/caosdb/common/models.py
@@ -542,7 +542,9 @@ class Entity(object):
                     return p
         else:
             for p in self.properties:
-                if p.name is not None and str(p.name) == str(key):
+                if (p.name is not None
+                        and str(p.name).lower() == str(key).lower()):
+
                     return p
 
         return None
diff --git a/unittests/test_entity.py b/unittests/test_entity.py
index d0f4089c..c3862ae2 100644
--- a/unittests/test_entity.py
+++ b/unittests/test_entity.py
@@ -22,11 +22,14 @@
 # ** end header
 #
 """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)
+import unittest
+
 from caosdb import Entity, configure_connection
 from caosdb.connection.mockup import MockUpServerConnection
+# pylint: disable=missing-docstring
+from nose.tools import assert_equal as eq
+from nose.tools import assert_is_not_none as there
+from nose.tools import assert_true as tru
 
 
 def setup_module():
@@ -40,18 +43,21 @@ def hat(obj, attr):
     tru(hasattr(obj, attr))
 
 
-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_role():
-    entity = Entity(role="TestRole")
-    eq(entity.role, "TestRole")
-    entity.role = "TestRole2"
-    eq(entity.role, "TestRole2")
+class TestEntity(unittest.TestCase):
+    def test_instance_variables(self):
+        entity = Entity()
+        hat(entity, "role")
+        hat(entity, "id")
+        hat(entity, "name")
+        hat(entity, "description")
+        hat(entity, "parents")
+        hat(entity, "properties")
+
+    def test_role(self):
+        entity = Entity(role="TestRole")
+        eq(entity.role, "TestRole")
+        entity.role = "TestRole2"
+        eq(entity.role, "TestRole2")
+
+    def test_instanciation(self):
+        self.assertRaises(Exception, Entity())
diff --git a/unittests/test_record.py b/unittests/test_record.py
index cd65ede6..001f91a7 100644
--- a/unittests/test_record.py
+++ b/unittests/test_record.py
@@ -5,6 +5,7 @@
 #
 # Copyright (C) 2018 Research Group Biomedical Physics,
 # Max-Planck-Institute for Dynamics and Self-Organization Göttingen
+# Copyright (C) 2019 Henrik tom Wörden
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as
@@ -23,8 +24,12 @@
 #
 """Tests for the Record class."""
 # pylint: disable=missing-docstring
-from nose.tools import (assert_is_not_none as there, assert_true as tru,
-                        assert_equal as eq)
+import unittest
+
+from nose.tools import assert_equal as eq
+from nose.tools import assert_is_not_none as there
+from nose.tools import assert_true as tru
+
 from caosdb import Entity, Record, configure_connection
 from caosdb.connection.mockup import MockUpServerConnection
 
@@ -48,3 +53,13 @@ def test_is_entity():
 def test_role():
     record = Record()
     eq(record.role, "Record")
+
+
+class TestRecord(unittest.TestCase):
+    def test_property_access(self):
+        rec = Record()
+        rec.add_property("Prop")
+        self.assertIsNone(rec.get_property("Pop"))
+        self.assertIsNotNone(rec.get_property("Prop"))
+        self.assertIsNotNone(rec.get_property("prop"))
+        self.assertIsNotNone(rec.get_property("prOp"))
-- 
GitLab