oship-dev team mailing list archive
-
oship-dev team
-
Mailing list archive
-
Message #01604
[Branch ~oship-dev/oship/devel] Rev 510: Implemented invariant in TermMapping class and added test for TermMapping.
------------------------------------------------------------
revno: 510
fixes bug(s): https://launchpad.net/bugs/609150
committer: Wagner Francisco Mezaroba <wagner@wagner-laptop>
branch nick: oship
timestamp: Wed 2010-11-17 11:14:09 -0200
message:
Implemented invariant in TermMapping class and added test for TermMapping.
added:
src/oship/openehr/rm/datatypes/text/tests/termmapping.py
modified:
src/oship/openehr/rm/datatypes/text/__init__.py
src/oship/openehr/rm/support/terminology/__init__.py
--
lp:oship
https://code.launchpad.net/~oship-dev/oship/devel
Your team OSHIP Development Team is subscribed to branch lp:oship.
To unsubscribe from this branch go to https://code.launchpad.net/~oship-dev/oship/devel/+edit-subscription
=== modified file 'src/oship/openehr/rm/datatypes/text/__init__.py'
--- src/oship/openehr/rm/datatypes/text/__init__.py 2010-08-06 21:39:30 +0000
+++ src/oship/openehr/rm/datatypes/text/__init__.py 2010-11-17 13:14:09 +0000
@@ -3,6 +3,7 @@
import grok
from interfaces import *
from oship.openehr.rm.datatypes.basic import DataValue
+from oship.openehr.rm.support.terminology import TerminologyService
class TermMapping(DataValue):
"""
@@ -20,15 +21,16 @@
grok.implements(ITermMapping)
- def __init__(self,target,match,purpose):
+ def __init__(self,target,match,purpose, terminologyService=None):
self.target = target
+ if purpose is not None:
+ terminologyService.terminology(TerminologyService.OPENEHR).hasCodeForGroupId('Group Id Term Mapping Purpose', purpose)
self.purpose = purpose
if match in ['<','>','=','?']:
self.match = match
else:
raise AttributeError(_('Invalid match parameter'))
-
def narrower():
return self.match == '<'
@@ -144,4 +146,4 @@
def __init__(self,definingCode,value,mappings,formatting,hyperlink,language,encoding):
self.definingCode=definingCode
DvText.__init__(self,value,mappings,formatting,hyperlink,language,encoding)
-
\ No newline at end of file
+
=== added file 'src/oship/openehr/rm/datatypes/text/tests/termmapping.py'
--- src/oship/openehr/rm/datatypes/text/tests/termmapping.py 1970-01-01 00:00:00 +0000
+++ src/oship/openehr/rm/datatypes/text/tests/termmapping.py 2010-11-17 13:14:09 +0000
@@ -0,0 +1,46 @@
+"""
+Do a Python test on the app.
+
+:Test-Layer: python
+"""
+import unittest
+import grok
+
+from oship.openehr.rm.datatypes.text import TermMapping, CodePhrase, DvCodedText
+from oship.openehr.rm.support.identification import TerminologyId
+
+class TermMappingTest(unittest.TestCase):
+
+ def testShouldInitializeWithNullPurpose(self):
+ tm = TermMapping(None, match(), None)
+
+ def testShouldInitializeWithValidPurpose(self):
+ tm = TermMapping(None, match(), purpose(), DummyTerminologyService(True))
+
+ def testShouldNotInitializeWithInvalidPurpose(self):
+ tm = TermMapping(None, match(), purpose(), DummyTerminologyService(False))
+
+
+def match():
+ return '<'
+
+def purpose():
+ tid = TerminologyId(u'SNOMED-CT')
+ cp = CodePhrase(tid, u'abc123')
+ return DvCodedText(cp, u'abc123', [], u'', None, None, None)
+
+class DummyTerminologyService(object):
+ def __init__(self, returnValue):
+ self.returnValue = returnValue
+
+ def terminology(self, terminologyId):
+ return DummyTerminologyAccess(self.returnValue)
+
+class DummyTerminologyAccess(object):
+
+ def __init__(self, returnValue):
+ self.returnValue = returnValue
+
+ def hasCodeForGroupId(self, groupId, code):
+ return self.returnValue
+
=== modified file 'src/oship/openehr/rm/support/terminology/__init__.py'
--- src/oship/openehr/rm/support/terminology/__init__.py 2010-07-12 21:32:11 +0000
+++ src/oship/openehr/rm/support/terminology/__init__.py 2010-11-17 13:14:09 +0000
@@ -132,6 +132,8 @@
Defines an object providing proxy access to a terminology service.
"""
+ OPENEHR='OpenEHR'
+
def terminology(self,name):
u""" Return an interface to the terminology named
name. Allowable names include "openehr","centc251",any name