Skip to content

Commit

Permalink
Merge pull request #54 from EdinburghGenomics/#53_action_rework
Browse files Browse the repository at this point in the history
Change rework-step value's type  to match the API requirement
  • Loading branch information
Timothee Cezard committed Mar 13, 2019
2 parents a03be6e + 0bdeaac commit 49850af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 9 additions & 5 deletions pyclarity_lims/descriptors.py
Expand Up @@ -278,21 +278,25 @@ class XmlAction(XmlElementAttributeDict):
action: The type of action to perform. (leave, repeat, remove, review, complete, store, nextstep, rework, completerepeat, unknown)
"""
def _parse_element(self, element, **kwargs):
from pyclarity_lims.entities import Artifact, ProtocolStep
from pyclarity_lims.entities import Artifact, ProtocolStep, Step
for k, v in element.attrib.items():

if k == 'artifact-uri':
k = 'artifact'
v = Artifact(self.instance.lims, uri=v)
elif k in ('step-uri', 'rework-step-uri'):
elif k == 'step-uri':
k = k[:-(len('-uri'))]
v = ProtocolStep(self.instance.lims, uri=v)
elif k == 'rework-step-uri':
k = k[:-(len('-uri'))]
v = Step(self.instance.lims, uri=v)
dict.__setitem__(self, k, v)

def _setitem(self, key, value):
from pyclarity_lims.entities import Artifact, ProtocolStep
if (key in ['artifact'] and isinstance(value, Artifact)) or \
(key in ['step', 'rework-step'] and isinstance(value, ProtocolStep)):
from pyclarity_lims.entities import Artifact, ProtocolStep, Step
if key == 'artifact' and isinstance(value, Artifact) or \
key == 'step' and isinstance(value, ProtocolStep) or \
key == 'rework-step' and isinstance(value, Step):
key += '-uri'
value = value.uri
elif key in ['action']:
Expand Down
7 changes: 5 additions & 2 deletions tests/test_descriptors.py
Expand Up @@ -11,7 +11,7 @@
StringDictionaryDescriptor, IntegerDescriptor, BooleanDescriptor, UdfDictionary, EntityDescriptor, \
InputOutputMapList, EntityListDescriptor, PlacementDictionary, EntityList, SubTagDictionary, ExternalidList,\
XmlElementAttributeDict, XmlAttributeList, XmlReagentLabelList, XmlPooledInputDict, XmlAction, QueuedArtifactList
from pyclarity_lims.entities import Artifact, ProtocolStep, Container, Process
from pyclarity_lims.entities import Artifact, ProtocolStep, Container, Process, Step
from pyclarity_lims.lims import Lims
from tests import elements_equal

Expand Down Expand Up @@ -780,7 +780,7 @@ class TestXmlAction(TestCase):
def setUp(self):
et = ElementTree.fromstring('''<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<test-entry>
<next-action step-uri="{url}/prt/1/stp/1" action="nextstep" artifact-uri="{url}/arts/a1"/>
<next-action step-uri="{url}/prt/1/stp/1" rework-step-uri="{url}/steps/1" action="nextstep" artifact-uri="{url}/arts/a1"/>
</test-entry>'''.format(url='http://testgenologics.com:4040'))

et1 = ElementTree.fromstring('''<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
Expand All @@ -797,13 +797,16 @@ def test_parse(self):
assert action['action'] == 'nextstep'
assert action['step'] == ProtocolStep(self.lims, uri='http://testgenologics.com:4040/prt/1/stp/1')
assert action['artifact'] == Artifact(self.lims, uri='http://testgenologics.com:4040/arts/a1')
assert action['rework-step'] == Step(self.lims, uri='http://testgenologics.com:4040/steps/1')

def test_set(self):
action = XmlAction(self.instance_empty, tag='next-action')
action['step'] = ProtocolStep(self.lims, uri='http://testgenologics.com:4040/prt/1/stp/1')
assert action.instance.root.find('next-action').attrib['step-uri'] == 'http://testgenologics.com:4040/prt/1/stp/1'
action['action'] = 'nextstep'
assert action.instance.root.find('next-action').attrib['action'] == 'nextstep'
action['rework-step'] = Step(self.lims, uri='http://testgenologics.com:4040/steps/1')
assert action.instance.root.find('next-action').attrib['rework-step-uri'] == 'http://testgenologics.com:4040/steps/1'

with pytest.raises(KeyError):
action['whatever'] = 'youwant'
Expand Down

0 comments on commit 49850af

Please sign in to comment.