def setUp(self): et = ElementTree.fromstring( '''<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <test-entry> <pooled-inputs> <pool output-uri="{uri}/out1" name="pool1"> <input uri="{uri}/in1"/> <input uri="{uri}/in2"/> </pool> <pool output-uri="{uri}/out2" name="pool2"> <input uri="{uri}/in3"/> <input uri="{uri}/in4"/> </pool> </pooled-inputs> </test-entry>'''.format(uri='http://testgenologics.com:4040')) self.lims = Lims('http://testgenologics.com:4040', username='******', password='******') self.instance1 = Mock(root=et, lims=self.lims) self.dict1 = XmlPooledInputDict(self.instance1) self.out1 = Artifact(self.lims, uri='http://testgenologics.com:4040/out1') self.in1 = Artifact(self.lims, uri='http://testgenologics.com:4040/in1') self.in2 = Artifact(self.lims, uri='http://testgenologics.com:4040/in2')
def setUp(self): et = ElementTree.fromstring( """<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <test-entry> <artifact uri="http://testgenologics.com:4040/api/v2/artifacts/a1"></artifact> <artifact uri="http://testgenologics.com:4040/api/v2/artifacts/a2"></artifact> <other>thing</other> </test-entry> """) self.lims = Lims('http://testgenologics.com:4040', username='******', password='******') self.a1 = Artifact(self.lims, id='a1') self.a2 = Artifact(self.lims, id='a2') self.instance1 = Mock(root=et, lims=self.lims) et = ElementTree.fromstring( """<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <test-entry> <nesting> <artifact uri="http://testgenologics.com:4040/api/v2/artifacts/a1"></artifact> <artifact uri="http://testgenologics.com:4040/api/v2/artifacts/a2"></artifact> </nesting> </test-entry> """) self.instance2 = Mock(root=et, lims=self.lims)
def test_set_list(self): el = EntityList(self.instance1, 'artifact', Artifact) assert len(el) == 2 assert len(el.instance.root.findall('artifact')) == 2 a3 = Artifact(self.lims, id='a3') a4 = Artifact(self.lims, id='a4') el[0:2] = [a3, a4] assert len(el) == 2 assert el[0] == a3 assert el[1] == a4
def test___add__(self): el1 = EntityList(self.instance1, 'artifact', Artifact) assert len(el1) == 2 assert len(el1.instance.root.findall('artifact')) == 2 el2 = [Artifact(self.lims, id='a3'), Artifact(self.lims, id='a4')] el3 = el1 + el2 assert len(el3) == 4 assert el3[:2] == el1 assert el3[2:] == el2
def _parse_element(self, element, **kwargs): from pyclarity_lims.entities import Artifact dict.__setitem__( self, element.attrib.get('name'), ( Artifact(self.instance.lims, uri=element.attrib.get('output-uri')), tuple(Artifact(self.instance.lims, uri=sub.attrib.get('uri')) for sub in element.findall('input')) ) )
def test__iadd__(self): el1 = EntityList(self.instance1, 'artifact', Artifact) id1 = id(el1) assert len(el1) == 2 assert len(el1.instance.root.findall('artifact')) == 2 el2 = [Artifact(self.lims, id='a3'), Artifact(self.lims, id='a4')] el1 += el2 id2 = id(el1) assert id1 == id2 # still the same object assert len(el1) == 4 assert el1[2:] == el2
def test_get_placements_list(self): s = StepPlacements(uri=self.lims.get_uri('steps', 's1', 'placements'), lims=self.lims) with patch('requests.Session.get', return_value=Mock(content=self.original_step_placements_xml, status_code=200)): a1 = Artifact(uri='http://testgenologics.com:4040/artifacts/a1', lims=self.lims) a2 = Artifact(uri='http://testgenologics.com:4040/artifacts/a2', lims=self.lims) c1 = Container(uri='http://testgenologics.com:4040/containers/c1', lims=self.lims) expected_placements = [(a1, (c1, '1:1')), (a2, (c1, '2:1'))] assert s.get_placement_list() == expected_placements
def _parse_element(self, element, lims, **kwargs): from pyclarity_lims.entities import Artifact, Container input_art = Artifact(lims, uri=element.attrib['uri']) loc = element.find('location') location = (None, None) if loc: location = ( Container(lims, uri=loc.find('container').attrib['uri']), loc.find('value').text ) qt = element.find('queue-time') queue_date = None if qt is not None: h, s, t = qt.text.rpartition(':') qt = h + t microsec = '' if '.' in qt: microsec = '.%f' date_format = '%Y-%m-%dT%H:%M:%S' + microsec try: queue_date = datetime.datetime.strptime(qt, date_format + '%z') except ValueError: # support for python 2.7 ignore time zone # use python 3 for timezone support if '+' in qt: qt = qt.split('+')[0] else: qt_array = qt.split('-') qt = qt_array[0] + "-" + qt_array[1] + "-" + qt_array[2] queue_date = datetime.datetime.strptime(qt, date_format) list.append(self, (input_art, queue_date, location))
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 get_queue_art(self, art_id, pos, microsec, time_delta): if version_info[0] == 2: return (Artifact(self.lims, id=art_id), datetime.datetime(2011, 12, 25, 1, 10, 10, microsec), (Container(self.lims, id='c1'), pos)) else: return (Artifact(self.lims, id=art_id), datetime.datetime(2011, 12, 25, 1, 10, 10, microsec, tzinfo=datetime.timezone(time_delta)), (Container(self.lims, id='c1'), pos))
def test_set_placements_list_fail(self): a1 = Artifact(uri='http://testgenologics.com:4040/artifacts/a1', lims=self.lims) a2 = Artifact(uri='http://testgenologics.com:4040/artifacts/a2', lims=self.lims) c2 = Container(uri='http://testgenologics.com:4040/containers/c2', lims=self.lims) s = StepPlacements(uri=self.lims.get_uri('steps', 's1', 'placements'), lims=self.lims) with patch('requests.Session.get', return_value=Mock(content=self.original_step_placements_xml, status_code=200)): new_placements = [(a1, (c2, '1:1')), (a2, (c2, '1:1'))] s.placement_list = new_placements assert elements_equal( s.root, ElementTree.fromstring(self.modcont_step_placements_xml))
def test_append(self): el = EntityList(self.instance1, 'artifact', Artifact) assert len(el) == 2 assert len(el.instance.root.findall('artifact')) == 2 a3 = Artifact(self.lims, id='a3') el.append(a3) assert len(el) == 3 assert el[2] == a3 assert len(el._elems) == 3 assert len(el.instance.root.findall('artifact')) == 3
def _parse_element(self, element, lims, **kwargs): from pyclarity_lims.entities import Artifact, Container input = Artifact(lims, uri=element.attrib['uri']) loc = element.find('location') location = (None, None) if loc: location = ( Container(lims, uri=loc.find('container').attrib['uri']), loc.find('value').text ) list.append(self, (input, location))
def _parse_element(self, element, **kwargs): 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 in ('step-uri', 'rework-step-uri'): k = k[:-(len('-uri'))] v = ProtocolStep(self.instance.lims, uri=v) dict.__setitem__(self, k, v)
def test_set(self): el = EntityList(self.instance1, 'artifact', Artifact) assert len(el) == 2 assert len(el.instance.root.findall('artifact')) == 2 a3 = Artifact(self.lims, id='a3') el[1] = a3 assert len(el) == 2 assert el[1] == a3 assert len(el._elems) == 2 assert el.instance.root.findall('artifact')[1].attrib[ 'uri'] == 'http://testgenologics.com:4040/api/v2/artifacts/a3'
def test___setitem__(self): assert len( self.dict1.rootnode(self.dict1.instance).findall('placement')) == 1 art2 = Artifact(lims=self.lims, id='a2') self.dict1['A:1'] = art2 assert len( self.dict1.rootnode(self.dict1.instance).findall('placement')) == 1 self.dict1['A:2'] = art2 assert len( self.dict1.rootnode(self.dict1.instance).findall('placement')) == 2 assert self.dict1['A:2'] == art2
def test_workflow_stages_and_statuses(self): a = Artifact(uri=self.lims.get_uri('artifacts', 'a1'), lims=self.lims) expected_wf_stage = [ (Stage(self.lims, uri=url + '/api/v2/configuration/workflows/1/stages/2'), 'QUEUED', 'Test workflow s2'), (Stage(self.lims, uri=url + '/api/v2/configuration/workflows/1/stages/1'), 'COMPLETE', 'Test workflow s1') ] with patch('requests.Session.get', return_value=Mock(content=self.root_artifact_xml, status_code=200)): assert a.workflow_stages_and_statuses == expected_wf_stage
def setUp(self): et = ElementTree.fromstring( """<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <test-entry xmlns:udf="http://genologics.com/ri/userdefined"> <placement uri="http://testgenologics.com:4040/api/v2/artifacts/a1" limsid="a1"> <value>A:1</value> </placement> <other>thing</other> </test-entry>""") self.lims = Lims('http://testgenologics.com:4040', username='******', password='******') self.instance1 = Mock(root=et, lims=self.lims) self.dict1 = PlacementDictionary(self.instance1) self.art1 = Artifact(lims=self.lims, id='a1')
def _get_dict(self, lims, node): from pyclarity_lims.entities import Artifact, Process if node is None: return None result = dict() for key in ['limsid', 'output-type', 'output-generation-type']: try: result[key] = node.attrib[key] except KeyError: pass for uri in ['uri', 'post-process-uri']: try: result[uri] = Artifact(lims, uri=node.attrib[uri]) except KeyError: pass node = node.find('parent-process') if node is not None: result['parent-process'] = Process(lims, node.attrib['uri']) return result
def test_next_actions(self): s = StepActions(uri=self.lims.get_uri('steps', 'step_id', 'actions'), lims=self.lims) with patch('requests.Session.get', return_value=Mock( content=self.step_actions_no_escalation_xml, status_code=200)): step1 = Step(self.lims, uri='http://testgenologics.com:4040/steps/s1') step2 = Step(self.lims, uri='http://testgenologics.com:4040/steps/s2') artifact = Artifact( self.lims, uri='http://testgenologics.com:4040/artifacts/a1') expected_next_actions = [{ 'artifact': artifact, 'action': 'requeue', 'step': step1, 'rework-step': step2 }] assert s.next_actions == expected_next_actions
def test_escalation(self): s = StepActions(uri=self.lims.get_uri('steps', 'step_id', 'actions'), lims=self.lims) with patch('requests.Session.get', return_value=Mock(content=self.step_actions_xml, status_code=200)): with patch('requests.post', return_value=Mock(content=self.dummy_xml, status_code=200)): r = Researcher( uri='http://testgenologics.com:4040/researchers/r1', lims=self.lims) a = Artifact(uri='http://testgenologics.com:4040/artifacts/r1', lims=self.lims) expected_escalation = { 'status': 'Reviewed', 'author': r, 'artifacts': [a], 'request': 'no comments', 'answer': 'no comments', 'reviewer': r } assert s.escalation == expected_escalation
def test_input_artifact_list(self): a = Artifact(uri=self.lims.get_uri('artifacts', 'a1'), lims=self.lims) with patch('requests.Session.get', return_value=Mock(content=self.root_artifact_xml, status_code=200)): assert a.input_artifact_list() == []
def _parse_element(self, element, **kwargs): from pyclarity_lims.entities import Artifact key = element.find('value').text dict.__setitem__(self, key, Artifact(self.instance.lims, uri=element.attrib['uri']))