Skip to content

Commit

Permalink
Merge pull request #17 from EdinburghGenomics/fixactions
Browse files Browse the repository at this point in the history
Fixactions
  • Loading branch information
Timothee Cezard committed Jan 3, 2018
2 parents b358a92 + 1fc4e81 commit 82c1b93
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 19 deletions.
23 changes: 14 additions & 9 deletions pyclarity_lims/descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,25 +270,30 @@ class XmlAction(XmlElementAttributeDict):
artifact: The Artifact associated with this Action
step: The next step associated with this action
rework-step: The step associated with this action when the Artifact need to be requeued
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, Step
from pyclarity_lims.entities import Artifact, ProtocolStep
for k, v in element.attrib.items():

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

def _setitem(self, key, value):
if key in ['artifact', 'step', 'rework-step']:
key = key + '-uri'
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)):
key += '-uri'
value = value.uri
elif key in ['action']:
pass
else:
raise KeyError('%s Is not a supported key for next action' % key)
self._elems[0].attrib[key] = value

def _delitem(self, key):
Expand Down
17 changes: 15 additions & 2 deletions pyclarity_lims/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,19 +655,32 @@ def get_selected_containers(self):


class StepActions(Entity):
"""Actions associated with a step"""
"""Actions associated with the end of the step"""
_escalation = None
next_actions = MutableDescriptor(XmlActionList)
"""
List of dict that representing an action for an artifact. They keys of the dict are:
- artifact: The :py:class:`artifact <pyclarity_lims.entities.Artifact>` associated with this Action
- step: The next :py:class:`step <pyclarity_lims.entities.Step>` associated with this action
- rework-step: The :py:class:`step <pyclarity_lims.entities.Step>` associated with this action when the Artifact need to be requeued"""
- rework-step: The :py:class:`step <pyclarity_lims.entities.Step>` associated with this action when the Artifact need to be requeued
- action: The type of action to perform.
- leave: Leave the sample in the QC protocol.
- repeat: Repeat this step.
- remove: Remove from workflow.
- review: Request manager review.
- complete: Mark protocol as complete.
- store: Store for later.
- nextstep: Continue to the next step.
- rework: Rework from an earlier step.
- completerepeat: Complete and Repeat
- unknown: The action is unknown.
"""
step = None # See bottom of the file
""":py:class:`Step <pyclarity_lims.entities.Step>` associated with the actions."""

@property
def escalation(self):
# TODO: Convert to using descriptor and document
if not self._escalation:
self.get()
self._escalation = {}
Expand Down
50 changes: 42 additions & 8 deletions tests/test_descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
from pyclarity_lims.descriptors import StringDescriptor, StringAttributeDescriptor, StringListDescriptor, \
StringDictionaryDescriptor, IntegerDescriptor, BooleanDescriptor, UdfDictionary, EntityDescriptor, \
InputOutputMapList, EntityListDescriptor, PlacementDictionary, EntityList, SubTagDictionary, ExternalidList,\
XmlElementAttributeDict, XmlAttributeList, XmlReagentLabelList, XmlPooledInputDict
from pyclarity_lims.entities import Artifact
XmlElementAttributeDict, XmlAttributeList, XmlReagentLabelList, XmlPooledInputDict, XmlAction
from pyclarity_lims.entities import Artifact, ProtocolStep
from pyclarity_lims.lims import Lims
from tests import elements_equal
from tests import elements_equal

if version_info[0] == 2:
from mock import Mock
Expand Down Expand Up @@ -94,7 +94,7 @@ def setUp(self):

def test__get__(self):
bd = self._make_desc(BooleanDescriptor, 'istest')
assert bd.__get__(self.instance, None) == True
assert bd.__get__(self.instance, None)

def test__set__(self):
bd = self._make_desc(BooleanDescriptor, 'istest')
Expand Down Expand Up @@ -246,6 +246,7 @@ def test__set__(self):
assert isinstance(res, dict)
assert res['mykey1'] == 'myvalue1'


class TestUdfDictionary(TestCase):
def setUp(self):
et = ElementTree.fromstring("""<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
Expand Down Expand Up @@ -345,8 +346,7 @@ def test___delitem__(self):
del self.dict1['test']
with pytest.raises(KeyError):
self.dict1['test']
assert self._get_udf_value(self.dict1, 'test') == None

assert self._get_udf_value(self.dict1, 'test') is None

def test_items(self):
pass
Expand Down Expand Up @@ -500,6 +500,7 @@ def test___setitem__(self):
assert len(self.dict1) == 3
assert len(self.dict1.rootnode(self.dict1.instance)) == 3


class TestEntityList(TestCase):

def setUp(self):
Expand Down Expand Up @@ -600,7 +601,6 @@ def test___get__(self):
assert sorted(res[0][1].keys()) == sorted(expected_keys_ouput)



class TestExternalidList(TestCase):

def setUp(self):
Expand Down Expand Up @@ -648,7 +648,7 @@ def setUp(self):
def test_get(self):
al = XmlAttributeList(self.instance1, tag='test-tag', nesting=['test-tags'])
assert al[0] == {'attrib1': 'value1', 'attrib2':'value2'}
assert al[1] == {'attrib1': 'value11', 'attrib2':'value12', 'attrib3':'value13'}
assert al[1] == {'attrib1': 'value11', 'attrib2': 'value12', 'attrib3':'value13'}

def test_append(self):
el = XmlAttributeList(self.instance1, tag='test-tag', nesting=['test-tags'])
Expand Down Expand Up @@ -694,3 +694,37 @@ def test_append(self):
rl.instance.root.findall('reagent-label')[1],
ElementTree.fromstring('''<reagent-label name="another label"/>''')
)


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"/>
</test-entry>'''.format(url='http://testgenologics.com:4040'))

et1 = ElementTree.fromstring('''<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<test-entry>
<next-action artifact-uri="{url}/arts/a1"/>
</test-entry>'''.format(url='http://testgenologics.com:4040'))

self.lims = Lims('http://testgenologics.com:4040', username='test', password='password')
self.instance1 = Mock(root=et, lims=self.lims)
self.instance_empty = Mock(root=et1, lims=self.lims)

def test_parse(self):
action = XmlAction(self.instance1, tag='next-action')
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')

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'

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

0 comments on commit 82c1b93

Please sign in to comment.