diff --git a/qiita_client/qiita_client.py b/qiita_client/qiita_client.py index ca7b189..2dca728 100644 --- a/qiita_client/qiita_client.py +++ b/qiita_client/qiita_client.py @@ -629,6 +629,28 @@ def artifact_and_preparation_files(self, artifact_id, return files, prep_info + def get_artifact_html_summary(self, artifact_id): + """Gets the artifact html_summary + + Parameters + ---------- + artifact_id : int + The artifact id + + Returns + ------- + None or str + filepath of the artifact html_summary + """ + html_summary_fp = None + artifact_info = self.get("/qiita_db/artifacts/%s/" % artifact_id) + + if 'html_summary' in artifact_info['files']: + html_summary_fp = artifact_info[ + 'files']['html_summary'][0]['filepath'] + + return html_summary_fp + def _process_files_per_sample_fastq(self, files, prep_info, ignore_small_files): "helper function to process per_sample_FASTQ artifacts and their preps" diff --git a/qiita_client/tests/test_qiita_client.py b/qiita_client/tests/test_qiita_client.py index 87178b0..12689e8 100644 --- a/qiita_client/tests/test_qiita_client.py +++ b/qiita_client/tests/test_qiita_client.py @@ -171,16 +171,26 @@ def test_post_error(self): self.tester.post("/qiita_db/artifacts/1/type/") def test_patch(self): + artifact_id = '2' + + # before we patch the artifact by adding the html_summary, the + # html_summary should be None + self.assertIsNone(self.tester.get_artifact_html_summary(artifact_id)) + + # now, let's patch fd, fp = mkstemp() close(fd) with open(fp, 'w') as f: f.write('\n') self.clean_up_files.append(fp) - - obs = self.tester.patch('/qiita_db/artifacts/2/', 'add', + obs = self.tester.patch(f'/qiita_db/artifacts/{artifact_id}/', 'add', '/html_summary/', value=fp) self.assertIsNone(obs) + # now, the html_summary should contain the filename fp + self.assertTrue( + basename(fp) in self.tester.get_artifact_html_summary(artifact_id)) + def test_patch_error(self): with self.assertRaises(BadRequestError): self.tester.patch(