Skip to content

Commit

Permalink
Merge c334fd9 into 0aac6ad
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothee Cezard committed Jul 12, 2017
2 parents 0aac6ad + c334fd9 commit 6996a0e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
10 changes: 8 additions & 2 deletions pyclarity_lims/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ def set_placements(self, output_containers, output_placement_list):
self.placement.root = self.placement.post()

@classmethod
def create(cls, lims, protocol_step, inputs, container_type_name=None, reagent_category=None, **kwargs):
def create(cls, lims, protocol_step, inputs, container_type_name=None, reagent_category=None, replicates=1, **kwargs):
"""
Create a new instance of a Step. This method will start a step from queued artifacts.
Expand All @@ -885,6 +885,7 @@ def create(cls, lims, protocol_step, inputs, container_type_name=None, reagent_c
:param container_type_name: optional name of the type of container that this step use for its output.
if omitted it uses the required type from the ProtocolStep if there is only one.
:param reagent_category: optional reagent_category.
:param replicates: int or list of int specifying the number of replicates for each inputs.
"""
instance = super(Step, cls)._create(lims, **kwargs)
# Check configuratio of the step
Expand All @@ -910,12 +911,17 @@ def create(cls, lims, protocol_step, inputs, container_type_name=None, reagent_c
reagent_category_node = ElementTree.SubElement(instance.root, 'reagent_category')
reagent_category_node.text = reagent_category

if isinstance(replicates, int):
replicates = [replicates] * len(inputs)
assert len(replicates) == len(inputs)
inputs_node = ElementTree.SubElement(instance.root, 'inputs')
for artifact in inputs:
for i, artifact in enumerate(inputs):
if not isinstance(artifact, Artifact):
raise TypeError('Input must be of type Artifact not %s.' % type(artifact))
input_node = ElementTree.SubElement(inputs_node, 'input')
input_node.attrib['uri'] = artifact.uri
if replicates:
input_node.attrib['replicates'] = str(replicates[i])
data = lims.tostring(ElementTree.ElementTree(instance.root))
instance.root = lims.post(uri=lims.get_uri(cls._URI), data=data)
instance._uri = instance.root.attrib['uri']
Expand Down
36 changes: 32 additions & 4 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,35 @@ def test_create(self):
)
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_create2(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',
permittedcontainers=['Tube']
)
with patch('pyclarity_lims.lims.requests.post',
return_value=Mock(content=self.step_xml, status_code=201)) as patch_post:
# replicates default to 1
Step.create(self.lims, protocol_step=protocol_step, inputs=inputs)
data = '''<?xml version='1.0' encoding='utf-8'?>
<stp:step-creation xmlns:stp="http://genologics.com/ri/step">
Expand All @@ -282,13 +311,14 @@ def test_create(self):
</configuration>
<container-type>Tube</container-type>
<inputs>
<input uri="http://testgenologics.com:4040/api/v2/artifacts/a1" />
<input uri="http://testgenologics.com:4040/api/v2/artifacts/a2" />
<input uri="http://testgenologics.com:4040/api/v2/artifacts/a1" replicates="1"/>
<input uri="http://testgenologics.com:4040/api/v2/artifacts/a2" replicates="1"/>
</inputs>
</stp:step-creation>
'''
assert elements_equal(ElementTree.fromstring(patch_post.call_args_list[0][1]['data']), ElementTree.fromstring(data))


def test_parse_entity(self):
with patch('requests.Session.get', return_value=Mock(content=self.step_xml, status_code=200)):
s = Step(self.lims, id='s1')
Expand Down Expand Up @@ -404,5 +434,3 @@ def test_create_entity(self):
</location>
</smp:samplecreation>'''
assert elements_equal(ElementTree.fromstring(patch_post.call_args_list[0][1]['data']), ElementTree.fromstring(data))


0 comments on commit 6996a0e

Please sign in to comment.