Skip to content
Snippets Groups Projects
Commit 6a004836 authored by Henrik tom Wörden's avatar Henrik tom Wörden Committed by Timm Fitschen
Browse files

FIX: make Entity.get_property case-insensitive

parent e7a391bd
Branches
Tags
No related merge requests found
...@@ -542,7 +542,9 @@ class Entity(object): ...@@ -542,7 +542,9 @@ class Entity(object):
return p return p
else: else:
for p in self.properties: 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 p
return None return None
......
...@@ -22,11 +22,14 @@ ...@@ -22,11 +22,14 @@
# ** end header # ** end header
# #
"""Tests for the Entity class.""" """Tests for the Entity class."""
# pylint: disable=missing-docstring import unittest
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 import Entity, configure_connection
from caosdb.connection.mockup import MockUpServerConnection 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(): def setup_module():
...@@ -40,7 +43,8 @@ def hat(obj, attr): ...@@ -40,7 +43,8 @@ def hat(obj, attr):
tru(hasattr(obj, attr)) tru(hasattr(obj, attr))
def test_instance_variables(): class TestEntity(unittest.TestCase):
def test_instance_variables(self):
entity = Entity() entity = Entity()
hat(entity, "role") hat(entity, "role")
hat(entity, "id") hat(entity, "id")
...@@ -49,9 +53,11 @@ def test_instance_variables(): ...@@ -49,9 +53,11 @@ def test_instance_variables():
hat(entity, "parents") hat(entity, "parents")
hat(entity, "properties") hat(entity, "properties")
def test_role(self):
def test_role():
entity = Entity(role="TestRole") entity = Entity(role="TestRole")
eq(entity.role, "TestRole") eq(entity.role, "TestRole")
entity.role = "TestRole2" entity.role = "TestRole2"
eq(entity.role, "TestRole2") eq(entity.role, "TestRole2")
def test_instanciation(self):
self.assertRaises(Exception, Entity())
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
# #
# Copyright (C) 2018 Research Group Biomedical Physics, # Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen # 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 # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
...@@ -23,8 +24,12 @@ ...@@ -23,8 +24,12 @@
# #
"""Tests for the Record class.""" """Tests for the Record class."""
# pylint: disable=missing-docstring # pylint: disable=missing-docstring
from nose.tools import (assert_is_not_none as there, assert_true as tru, import unittest
assert_equal as eq)
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 import Entity, Record, configure_connection
from caosdb.connection.mockup import MockUpServerConnection from caosdb.connection.mockup import MockUpServerConnection
...@@ -48,3 +53,13 @@ def test_is_entity(): ...@@ -48,3 +53,13 @@ def test_is_entity():
def test_role(): def test_role():
record = Record() record = Record()
eq(record.role, "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"))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment