Skip to content

Commit

Permalink
add test for lims.get_batch to show the return type
Browse files Browse the repository at this point in the history
  • Loading branch information
tcezard committed Feb 11, 2019
1 parent 91c2547 commit a8abeda
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion tests/test_lims.py
Expand Up @@ -3,7 +3,7 @@

from requests.exceptions import HTTPError

from pyclarity_lims.entities import Sample, Project, Container
from pyclarity_lims.entities import Sample, Project, Container, Artifact
from pyclarity_lims.lims import Lims
from tests import elements_equal

Expand Down Expand Up @@ -212,6 +212,32 @@ def test_get_instances(self):
assert len(samples) == 6
assert mget.call_count == 3

def test_get_batch(self):
lims = Lims(self.url, username=self.username, password=self.password)
arts = [Artifact(lims, id='a1'), Artifact(lims, id='a2')]
artifact_list = '''<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<art:details xmlns:art="http://genologics.com/ri/artifact">
<art:artifact limsid="a1" uri="{url}/artifacts/a1">
<name>art1</name>
<type>type1</type>
</art:artifact>
<art:artifact limsid="a2" uri="{url}/artifacts/a2">
<name>art2</name>
<type>type2</type>
</art:artifact>
</art:details>
'''
with patch('requests.post', return_value=Mock(content=artifact_list, status_code=200)) as mocked_post:
arts = lims.get_batch(arts)
assert type(arts) == list
assert arts[0].name == 'art1'
assert arts[1].name == 'art2'
mocked_post.assert_called_once_with(
'http://testgenologics.com:4040/api/v2/artifacts/batch/retrieve',
auth=('test', 'password'),
data=b'<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<ri:links xmlns:ri="http://genologics.com/ri"><link rel="artifacts" uri="http://testgenologics.com:4040/api/v2/artifacts/a1" /><link rel="artifacts" uri="http://testgenologics.com:4040/api/v2/artifacts/a2" /></ri:links>',
headers={'content-type': 'application/xml', 'accept': 'application/xml'}, params={})

def test_create_batch(self):
lims = Lims(self.url, username=self.username, password=self.password)
p = Project(lims, uri='project')
Expand Down

0 comments on commit a8abeda

Please sign in to comment.