diff --git a/pyclarity_lims/entities.py b/pyclarity_lims/entities.py
index 66adeea5..24fd60b0 100644
--- a/pyclarity_lims/entities.py
+++ b/pyclarity_lims/entities.py
@@ -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.
@@ -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
@@ -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']
diff --git a/tests/test_entities.py b/tests/test_entities.py
index de6ee9cf..8ccf803b 100644
--- a/tests/test_entities.py
+++ b/tests/test_entities.py
@@ -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 = '''
+
+
+ My fancy step
+
+ Tube
+
+
+
+
+
+ '''
+ 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 = '''
@@ -282,13 +311,14 @@ def test_create(self):
Tube
-
-
+
+
'''
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')
@@ -404,5 +434,3 @@ def test_create_entity(self):
'''
assert elements_equal(ElementTree.fromstring(patch_post.call_args_list[0][1]['data']), ElementTree.fromstring(data))
-
-