def test_append(self):
     el = XmlAttributeList(self.instance1,
                           tag='test-tag',
                           nesting=['test-tags'])
     el.append({'attrib1': 'value21'})
     elements_equal(
         el.instance.root.find('test-tags').findall('test-tag')[-1],
         ElementTree.fromstring('''<test-tag attrib1="value21" />'''))
 def test_append(self):
     rl = XmlReagentLabelList(self.instance1)
     rl.append('another label')
     assert rl == ['label name', 'another label']
     elements_equal(
         rl.instance.root.findall('reagent-label')[1],
         ElementTree.fromstring(
             '''<reagent-label name="another label"/>'''))
 def test_insert(self):
     el = XmlAttributeList(self.instance1,
                           tag='test-tag',
                           nesting=['test-tags'])
     el.insert(1, {'attrib1': 'value21'})
     elements_equal(
         el.instance.root.find('test-tags').findall('test-tag')[1],
         ElementTree.fromstring('''<test-tag attrib1="value21" />'''))
     elements_equal(
         el.instance.root.find('test-tags').findall('test-tag')[2],
         ElementTree.fromstring(
             '''<test-tag attrib1="value11" attrib2="value12" attrib3="value13" />'''
         ))
 def test_advance(self):
     with patch('requests.Session.get',
                return_value=Mock(content=self.step_xml, status_code=200)):
         with patch('pyclarity_lims.lims.requests.post',
                    return_value=Mock(content=self.step_xml,
                                      status_code=201)) as patch_post:
             s = Step(self.lims, id='s1')
             s.advance()
             assert elements_equal(
                 ElementTree.fromstring(
                     patch_post.call_args_list[0][1]['data']),
                 ElementTree.fromstring(self.step_xml))
    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_create(self):
     inputs = [
         Mock(spec=Artifact,
              lims=self.lims,
              uri='http://testgenologics.com:4040/api/v2/artifacts/a1'),
         Mock(spec=Artifact,
              lims=self.lims,
              uri='http://testgenologics.com:4040/api/v2/artifacts/a2')
     ]
     protocol_step = NamedMock(
         spec=ProtocolStep,
         real_name='My fancy step',
         uri=
         'http://testgenologics.com:4040/api/v2/configuration//protocols/p1/steps/p1s1',
         permitted_containers=['Tube'])
     with patch('pyclarity_lims.lims.requests.post',
                return_value=Mock(content=self.step_xml,
                                  status_code=201)) as patch_post:
         Step.create(self.lims,
                     protocol_step=protocol_step,
                     inputs=inputs,
                     replicates=[1, 2])
         data = '''<?xml version='1.0' encoding='utf-8'?>
         <stp:step-creation xmlns:stp="http://genologics.com/ri/step">
             <configuration uri="http://testgenologics.com:4040/api/v2/configuration//protocols/p1/steps/p1s1">
                 My fancy step
             </configuration>
             <container-type>Tube</container-type>
             <inputs>
                 <input uri="http://testgenologics.com:4040/api/v2/artifacts/a1" replicates="1"/>
                 <input uri="http://testgenologics.com:4040/api/v2/artifacts/a2" replicates="2"/>
             </inputs>
         </stp:step-creation>
         '''
         assert elements_equal(
             ElementTree.fromstring(
                 patch_post.call_args_list[0][1]['data']),
             ElementTree.fromstring(data))
 def test_create_entity(self):
     with patch('pyclarity_lims.lims.requests.post',
                return_value=Mock(content=self.sample_creation,
                                  status_code=201)) as patch_post:
         Sample.create(
             self.lims,
             project=Project(self.lims, uri='project'),
             container=Container(self.lims, uri='container'),
             position='1:1',
             name='s1',
         )
         data = '''<?xml version=\'1.0\' encoding=\'utf-8\'?>
         <smp:samplecreation xmlns:smp="http://genologics.com/ri/sample">
         <name>s1</name>
         <project uri="project" />
         <location>
           <container uri="container" />
           <value>1:1</value>
         </location>
         </smp:samplecreation>'''
         assert elements_equal(
             ElementTree.fromstring(
                 patch_post.call_args_list[0][1]['data']),
             ElementTree.fromstring(data))