Skip to content

Commit 21afbc4

Browse files
Merge pull request #54 from antgonza/get_artifact_html_summary
add get_artifact_html_summary
2 parents d7ae29a + 6b4e139 commit 21afbc4

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

qiita_client/qiita_client.py

+22
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,28 @@ def artifact_and_preparation_files(self, artifact_id,
629629

630630
return files, prep_info
631631

632+
def get_artifact_html_summary(self, artifact_id):
633+
"""Gets the artifact html_summary
634+
635+
Parameters
636+
----------
637+
artifact_id : int
638+
The artifact id
639+
640+
Returns
641+
-------
642+
None or str
643+
filepath of the artifact html_summary
644+
"""
645+
html_summary_fp = None
646+
artifact_info = self.get("/qiita_db/artifacts/%s/" % artifact_id)
647+
648+
if 'html_summary' in artifact_info['files']:
649+
html_summary_fp = artifact_info[
650+
'files']['html_summary'][0]['filepath']
651+
652+
return html_summary_fp
653+
632654
def _process_files_per_sample_fastq(self, files, prep_info,
633655
ignore_small_files):
634656
"helper function to process per_sample_FASTQ artifacts and their preps"

qiita_client/tests/test_qiita_client.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,26 @@ def test_post_error(self):
171171
self.tester.post("/qiita_db/artifacts/1/type/")
172172

173173
def test_patch(self):
174+
artifact_id = '2'
175+
176+
# before we patch the artifact by adding the html_summary, the
177+
# html_summary should be None
178+
self.assertIsNone(self.tester.get_artifact_html_summary(artifact_id))
179+
180+
# now, let's patch
174181
fd, fp = mkstemp()
175182
close(fd)
176183
with open(fp, 'w') as f:
177184
f.write('\n')
178185
self.clean_up_files.append(fp)
179-
180-
obs = self.tester.patch('/qiita_db/artifacts/2/', 'add',
186+
obs = self.tester.patch(f'/qiita_db/artifacts/{artifact_id}/', 'add',
181187
'/html_summary/', value=fp)
182188
self.assertIsNone(obs)
183189

190+
# now, the html_summary should contain the filename fp
191+
self.assertTrue(
192+
basename(fp) in self.tester.get_artifact_html_summary(artifact_id))
193+
184194
def test_patch_error(self):
185195
with self.assertRaises(BadRequestError):
186196
self.tester.patch(

0 commit comments

Comments
 (0)