Commits

Ronny Pfannschmidt  committed dd656ef

test entry prop functions

  • Participants
  • Parent commits 5a5eea0

Comments (0)

Files changed (2)

File gtkarchitect/model/entity.py

 
 
 def _get_entity_prop_element(entity, property):
-    prop_elements = entity.xpath("//property[@name='%s']" % property)
-    if prop_elements:
-        return prop_elements[0]
+    for element in entity.iter('property'):
+        if element.get('name') == property:
+            return element
 
 def get_entity_prop(entity, property):
     prop_element = _get_entity_prop_element(entity, property)

File tests/model/test_entity.py

 from lxml.etree import Element, SubElement
 
+
 from gtkarchitect.model.entity import *
 
 
     assert get_entity_type(entity) == 'test'
 
 
+def test_prop_make():
+    data = Element('test')
+    assert len(data) == 0
+
+    set_entity_prop(data, 'name', 'test')
+    assert len(data) == 1
+
+    set_entity_prop(data, 'name', 'test2')
+    assert len(data) == 1
+
+    set_entity_prop(data, 'name2', 'test')
+    assert len(data) == 2
+
+
+def test_prop_get():
+    data = Element('test')
+    for i in range(4):
+        set_entity_prop(data, 'name%s'%i, 'test%s'%i)
+        got = get_entity_prop(data, 'name%s'%i)
+        assert got == 'test%s'%i
+
+    assert get_entity_prop(data, 'unknown') is None