From 7e637665b4961fb958715f1cb02b48d93c004513 Mon Sep 17 00:00:00 2001 From: ayobi Date: Fri, 12 Apr 2024 14:39:58 -0400 Subject: [PATCH 01/18] added lock to qiita repo --- microsetta_private_api/repo/qiita_repo.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/microsetta_private_api/repo/qiita_repo.py b/microsetta_private_api/repo/qiita_repo.py index 66dfdea48..b965c26a1 100644 --- a/microsetta_private_api/repo/qiita_repo.py +++ b/microsetta_private_api/repo/qiita_repo.py @@ -1,7 +1,10 @@ +from microsetta_private_api.repo.admin_repo import AdminRepo from microsetta_private_api.repo.base_repo import BaseRepo from microsetta_private_api.qiita import qclient from microsetta_private_api.repo.metadata_repo import retrieve_metadata from microsetta_private_api.repo.metadata_repo._constants import MISSING_VALUE +from microsetta_private_api.repo.survey_answers_repo import SurveyAnswersRepo +from microsetta_private_api.repo.transaction import Transaction class QiitaRepo(BaseRepo): @@ -35,6 +38,26 @@ def push_metadata_to_qiita(self, barcodes=None): list Any error detail when constructing metadata """ + # lock survey-sample association + with Transaction() as t: + admin_repo = AdminRepo(t) + sar_repo = SurveyAnswersRepo(t) + + for sample_barcode in barcodes: + ids = admin_repo._get_ids_relevant_to_barcode(sample_barcode) + + if ids is not None: + account_id = ids.get('account_id') + source_id = ids.get('source_id') + sample_id = ids.get('sample_id') + + survey_ids = sar_repo.list_answered_surveys_by_sample( + account_id, source_id, sample_id) + + for survey_id in survey_ids: + sar_repo.associate_answered_survey_with_sample( + account_id, source_id, sample_id, survey_id) + if barcodes is None: with self._transaction.cursor() as cur: # obtain all barcodes, which are part of the AG table, From 8cacf8278cc33e92cbfb269622991a5e59dff0b9 Mon Sep 17 00:00:00 2001 From: ayobi Date: Mon, 15 Apr 2024 11:26:16 -0400 Subject: [PATCH 02/18] changed where to get survey ids --- microsetta_private_api/repo/qiita_repo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsetta_private_api/repo/qiita_repo.py b/microsetta_private_api/repo/qiita_repo.py index b965c26a1..604109c5c 100644 --- a/microsetta_private_api/repo/qiita_repo.py +++ b/microsetta_private_api/repo/qiita_repo.py @@ -51,7 +51,7 @@ def push_metadata_to_qiita(self, barcodes=None): source_id = ids.get('source_id') sample_id = ids.get('sample_id') - survey_ids = sar_repo.list_answered_surveys_by_sample( + survey_ids = sar_repo.list_answered_surveys( account_id, source_id, sample_id) for survey_id in survey_ids: From b99405ae4a8ddb6161a698a38e3423a6226e30f8 Mon Sep 17 00:00:00 2001 From: ayobi Date: Mon, 15 Apr 2024 23:53:17 -0400 Subject: [PATCH 03/18] moved lock sample to func in qiita repo and added test --- microsetta_private_api/repo/qiita_repo.py | 42 +++++++++++-------- .../repo/tests/test_qiita.py | 25 +++++++++++ 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/microsetta_private_api/repo/qiita_repo.py b/microsetta_private_api/repo/qiita_repo.py index 604109c5c..e51548ee6 100644 --- a/microsetta_private_api/repo/qiita_repo.py +++ b/microsetta_private_api/repo/qiita_repo.py @@ -8,6 +8,29 @@ class QiitaRepo(BaseRepo): + def lock_sample_to_survey(self, barcodes): + # lock survey-sample association + with Transaction() as t: + admin_repo = AdminRepo(t) + sar_repo = SurveyAnswersRepo(t) + + for sample_barcode in barcodes: + ids = admin_repo._get_ids_relevant_to_barcode(sample_barcode) + + if ids is not None: + account_id = ids.get('account_id') + source_id = ids.get('source_id') + sample_id = ids.get('sample_id') + + survey_ids = sar_repo.list_answered_surveys( + account_id, source_id) + + for survey_id in survey_ids: + sar_repo.associate_answered_survey_with_sample( + account_id, source_id, sample_id, survey_id) + + t.commit() + def push_metadata_to_qiita(self, barcodes=None): """Attempt to format and push metadata for the set of barcodes @@ -39,24 +62,7 @@ def push_metadata_to_qiita(self, barcodes=None): Any error detail when constructing metadata """ # lock survey-sample association - with Transaction() as t: - admin_repo = AdminRepo(t) - sar_repo = SurveyAnswersRepo(t) - - for sample_barcode in barcodes: - ids = admin_repo._get_ids_relevant_to_barcode(sample_barcode) - - if ids is not None: - account_id = ids.get('account_id') - source_id = ids.get('source_id') - sample_id = ids.get('sample_id') - - survey_ids = sar_repo.list_answered_surveys( - account_id, source_id, sample_id) - - for survey_id in survey_ids: - sar_repo.associate_answered_survey_with_sample( - account_id, source_id, sample_id, survey_id) + self.lock_sample_to_survey(barcodes) if barcodes is None: with self._transaction.cursor() as cur: diff --git a/microsetta_private_api/repo/tests/test_qiita.py b/microsetta_private_api/repo/tests/test_qiita.py index 5d9cb9069..23fe39ad9 100644 --- a/microsetta_private_api/repo/tests/test_qiita.py +++ b/microsetta_private_api/repo/tests/test_qiita.py @@ -69,6 +69,31 @@ def test_push_metadata_to_qiita(self, test_retrieve_metadata, "associated with any surveys " "matching this template id")}]) + def test_lock_sample_to_survey(self): + test_barcode = '000012914' + test_barcodes = [test_barcode] + test_survey_id = '000a1da7d9d7e35b' + + with Transaction() as t: + with t.cursor() as cur: + for sample_barcode in test_barcodes: + cur.execute("SELECT * FROM ag.source_barcodes_surveys " + "WHERE barcode = %s AND survey_id = %s", + (sample_barcode, test_survey_id)) + barcode_does_not_exist_before = cur.fetchone() is None + + qiita_repo = QiitaRepo(t) + qiita_repo.lock_sample_to_survey(test_barcodes) + + cur.execute("SELECT * FROM source_barcodes_surveys " + "WHERE barcode=%s AND survey_id=%s", + (sample_barcode, test_survey_id)) + inserted_found = cur.fetchone() + barcode_exists_after = inserted_found is not None + + self.assertTrue(barcode_does_not_exist_before) + self.assertTrue(barcode_exists_after) + if __name__ == '__main__': main() From e8bf94744e0eea752f7048d7444559cd30637f40 Mon Sep 17 00:00:00 2001 From: ayobi Date: Tue, 16 Apr 2024 15:09:18 -0400 Subject: [PATCH 04/18] changed location of lock --- microsetta_private_api/repo/qiita_repo.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/microsetta_private_api/repo/qiita_repo.py b/microsetta_private_api/repo/qiita_repo.py index e51548ee6..bdcda4458 100644 --- a/microsetta_private_api/repo/qiita_repo.py +++ b/microsetta_private_api/repo/qiita_repo.py @@ -61,8 +61,6 @@ def push_metadata_to_qiita(self, barcodes=None): list Any error detail when constructing metadata """ - # lock survey-sample association - self.lock_sample_to_survey(barcodes) if barcodes is None: with self._transaction.cursor() as cur: @@ -94,6 +92,9 @@ def push_metadata_to_qiita(self, barcodes=None): else: barcodes = set(barcodes) + # lock survey-sample association + self.lock_sample_to_survey(barcodes) + # determine what samples are already known in qiita samples_in_qiita = set(qclient.get('/api/v1/study/10317/samples')) From c763aaab4f9388106d02b159745b1f1079a108ee Mon Sep 17 00:00:00 2001 From: ayobi Date: Wed, 17 Apr 2024 12:16:54 -0400 Subject: [PATCH 05/18] added dissociate in test --- microsetta_private_api/repo/qiita_repo.py | 10 +++++++--- microsetta_private_api/repo/tests/test_qiita.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/microsetta_private_api/repo/qiita_repo.py b/microsetta_private_api/repo/qiita_repo.py index bdcda4458..97b65be05 100644 --- a/microsetta_private_api/repo/qiita_repo.py +++ b/microsetta_private_api/repo/qiita_repo.py @@ -1,3 +1,4 @@ +from microsetta_private_api.exceptions import RepoException from microsetta_private_api.repo.admin_repo import AdminRepo from microsetta_private_api.repo.base_repo import BaseRepo from microsetta_private_api.qiita import qclient @@ -25,9 +26,12 @@ def lock_sample_to_survey(self, barcodes): survey_ids = sar_repo.list_answered_surveys( account_id, source_id) - for survey_id in survey_ids: - sar_repo.associate_answered_survey_with_sample( - account_id, source_id, sample_id, survey_id) + if survey_ids is not None: + for survey_id in survey_ids: + sar_repo.associate_answered_survey_with_sample( + account_id, source_id, sample_id, survey_id) + else: + raise RepoException("Survey IDs not found for barcode") t.commit() diff --git a/microsetta_private_api/repo/tests/test_qiita.py b/microsetta_private_api/repo/tests/test_qiita.py index 23fe39ad9..7bcf5d3d5 100644 --- a/microsetta_private_api/repo/tests/test_qiita.py +++ b/microsetta_private_api/repo/tests/test_qiita.py @@ -1,5 +1,6 @@ from unittest import TestCase, main from unittest.mock import patch +from microsetta_private_api.repo.survey_answers_repo import SurveyAnswersRepo from microsetta_private_api.repo.transaction import Transaction from microsetta_private_api.repo.qiita_repo import QiitaRepo @@ -70,10 +71,25 @@ def test_push_metadata_to_qiita(self, test_retrieve_metadata, "matching this template id")}]) def test_lock_sample_to_survey(self): + test_account_id = 'ed5ab96f-fc55-ead5-e040-8a80115d1c4b' + test_source_id = '1d7138e7-f1a7-421b-8c58-9245b2bc343e' + test_sample_id = 'ed5ab96f-fc57-ead5-e040-8a80115d1c4b' test_barcode = '000012914' test_barcodes = [test_barcode] test_survey_id = '000a1da7d9d7e35b' + with Transaction() as t: + answers_repo = SurveyAnswersRepo(t) + answered_survey_ids = answers_repo.list_answered_surveys_by_sample( + test_account_id, test_source_id, test_sample_id) + + for curr_answered_survey_id in answered_survey_ids: + answers_repo.dissociate_answered_survey_from_sample( + test_account_id, test_source_id, + test_sample_id, curr_answered_survey_id) + + t.commit() + with Transaction() as t: with t.cursor() as cur: for sample_barcode in test_barcodes: From 6f5a56aad35c32672733f2ff7013a462838f08ed Mon Sep 17 00:00:00 2001 From: ayobi Date: Wed, 17 Apr 2024 12:58:22 -0400 Subject: [PATCH 06/18] added comments --- microsetta_private_api/repo/tests/test_qiita.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/microsetta_private_api/repo/tests/test_qiita.py b/microsetta_private_api/repo/tests/test_qiita.py index 7bcf5d3d5..8e657db8b 100644 --- a/microsetta_private_api/repo/tests/test_qiita.py +++ b/microsetta_private_api/repo/tests/test_qiita.py @@ -78,6 +78,7 @@ def test_lock_sample_to_survey(self): test_barcodes = [test_barcode] test_survey_id = '000a1da7d9d7e35b' + # first we need to disassociate the sample with the survey with Transaction() as t: answers_repo = SurveyAnswersRepo(t) answered_survey_ids = answers_repo.list_answered_surveys_by_sample( @@ -90,9 +91,11 @@ def test_lock_sample_to_survey(self): t.commit() + # now we can test the association lock with Transaction() as t: with t.cursor() as cur: for sample_barcode in test_barcodes: + # let's check to make sure the disassociation worked cur.execute("SELECT * FROM ag.source_barcodes_surveys " "WHERE barcode = %s AND survey_id = %s", (sample_barcode, test_survey_id)) @@ -101,6 +104,7 @@ def test_lock_sample_to_survey(self): qiita_repo = QiitaRepo(t) qiita_repo.lock_sample_to_survey(test_barcodes) + # now let's check make sure the association worked cur.execute("SELECT * FROM source_barcodes_surveys " "WHERE barcode=%s AND survey_id=%s", (sample_barcode, test_survey_id)) From 58f45a042867082b6d8c527462e8dc5f00c74323 Mon Sep 17 00:00:00 2001 From: ayobi Date: Wed, 17 Apr 2024 14:58:31 -0400 Subject: [PATCH 07/18] changed test acct --- microsetta_private_api/repo/tests/test_qiita.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/microsetta_private_api/repo/tests/test_qiita.py b/microsetta_private_api/repo/tests/test_qiita.py index 8e657db8b..670ba1709 100644 --- a/microsetta_private_api/repo/tests/test_qiita.py +++ b/microsetta_private_api/repo/tests/test_qiita.py @@ -71,12 +71,12 @@ def test_push_metadata_to_qiita(self, test_retrieve_metadata, "matching this template id")}]) def test_lock_sample_to_survey(self): - test_account_id = 'ed5ab96f-fc55-ead5-e040-8a80115d1c4b' - test_source_id = '1d7138e7-f1a7-421b-8c58-9245b2bc343e' - test_sample_id = 'ed5ab96f-fc57-ead5-e040-8a80115d1c4b' - test_barcode = '000012914' + test_account_id = 'd8592c74-85ee-2135-e040-8a80115d6401' + test_source_id = '6c1c628e-7d78-4dc7-afd9-3061fa9866ba' + test_sample_id = 'd8592c74-85f0-2135-e040-8a80115d6401' + test_barcode = '000001766' test_barcodes = [test_barcode] - test_survey_id = '000a1da7d9d7e35b' + test_survey_id = 'd089fe280548bb96' # first we need to disassociate the sample with the survey with Transaction() as t: From c790b554e6c503979c404b5fb95cffae5c51acdc Mon Sep 17 00:00:00 2001 From: ayobi Date: Thu, 18 Apr 2024 13:30:56 -0400 Subject: [PATCH 08/18] removed test in qiita in favor of test_associate_sample_and_survey --- .../repo/tests/test_qiita.py | 45 ------------------- 1 file changed, 45 deletions(-) diff --git a/microsetta_private_api/repo/tests/test_qiita.py b/microsetta_private_api/repo/tests/test_qiita.py index 670ba1709..5d9cb9069 100644 --- a/microsetta_private_api/repo/tests/test_qiita.py +++ b/microsetta_private_api/repo/tests/test_qiita.py @@ -1,6 +1,5 @@ from unittest import TestCase, main from unittest.mock import patch -from microsetta_private_api.repo.survey_answers_repo import SurveyAnswersRepo from microsetta_private_api.repo.transaction import Transaction from microsetta_private_api.repo.qiita_repo import QiitaRepo @@ -70,50 +69,6 @@ def test_push_metadata_to_qiita(self, test_retrieve_metadata, "associated with any surveys " "matching this template id")}]) - def test_lock_sample_to_survey(self): - test_account_id = 'd8592c74-85ee-2135-e040-8a80115d6401' - test_source_id = '6c1c628e-7d78-4dc7-afd9-3061fa9866ba' - test_sample_id = 'd8592c74-85f0-2135-e040-8a80115d6401' - test_barcode = '000001766' - test_barcodes = [test_barcode] - test_survey_id = 'd089fe280548bb96' - - # first we need to disassociate the sample with the survey - with Transaction() as t: - answers_repo = SurveyAnswersRepo(t) - answered_survey_ids = answers_repo.list_answered_surveys_by_sample( - test_account_id, test_source_id, test_sample_id) - - for curr_answered_survey_id in answered_survey_ids: - answers_repo.dissociate_answered_survey_from_sample( - test_account_id, test_source_id, - test_sample_id, curr_answered_survey_id) - - t.commit() - - # now we can test the association lock - with Transaction() as t: - with t.cursor() as cur: - for sample_barcode in test_barcodes: - # let's check to make sure the disassociation worked - cur.execute("SELECT * FROM ag.source_barcodes_surveys " - "WHERE barcode = %s AND survey_id = %s", - (sample_barcode, test_survey_id)) - barcode_does_not_exist_before = cur.fetchone() is None - - qiita_repo = QiitaRepo(t) - qiita_repo.lock_sample_to_survey(test_barcodes) - - # now let's check make sure the association worked - cur.execute("SELECT * FROM source_barcodes_surveys " - "WHERE barcode=%s AND survey_id=%s", - (sample_barcode, test_survey_id)) - inserted_found = cur.fetchone() - barcode_exists_after = inserted_found is not None - - self.assertTrue(barcode_does_not_exist_before) - self.assertTrue(barcode_exists_after) - if __name__ == '__main__': main() From 08fd3b4c7efab1f37b908b66f1a9de4b5fdb142a Mon Sep 17 00:00:00 2001 From: ayobi Date: Thu, 18 Apr 2024 16:58:55 -0400 Subject: [PATCH 09/18] added test --- .../repo/tests/test_qiita.py | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/microsetta_private_api/repo/tests/test_qiita.py b/microsetta_private_api/repo/tests/test_qiita.py index 5d9cb9069..3fe6ef547 100644 --- a/microsetta_private_api/repo/tests/test_qiita.py +++ b/microsetta_private_api/repo/tests/test_qiita.py @@ -1,5 +1,6 @@ from unittest import TestCase, main from unittest.mock import patch +from microsetta_private_api.repo.survey_answers_repo import SurveyAnswersRepo from microsetta_private_api.repo.transaction import Transaction from microsetta_private_api.repo.qiita_repo import QiitaRepo @@ -69,6 +70,65 @@ def test_push_metadata_to_qiita(self, test_retrieve_metadata, "associated with any surveys " "matching this template id")}]) + def test_lock_sample_to_survey(self): + + test_barcode = '000069747' + test_barcodes = [test_barcode] + + with Transaction() as t: + with t.dict_cursor() as cur: + # first, find the ids for the barcode and survey we're using + # as they are dynamically generated. + cur.execute("select ag_login_id, source_id from " + "ag_login_surveys a join source_barcodes_surveys b" + " on a.survey_id = b.survey_id and b.barcode = " + "'000069747' and survey_template_id = 1") + row = cur.fetchone() + account_id = row[0] + source_id = row[1] + + cur.execute("select ag_kit_barcode_id from ag_kit_barcodes " + "where barcode = '000069747'") + row = cur.fetchone() + + cur.execute("SELECT * FROM source_barcodes_surveys " + "WHERE barcode = '000069747'") + rows_before = cur.fetchall() + + # submit a survey for the barcode + sar = SurveyAnswersRepo(t) + survey_10 = { + '22': 'Unspecified', + '108': 'Unspecified', + '109': 'Unspecified', + '110': 'Unspecified', + '111': 'Unspecified', + '112': '1990', + '113': 'Unspecified', + '115': 'Unspecified', + '148': 'Unspecified', + '492': 'Unspecified', + '493': 'Unspecified', + '502': 'Male' + } + sar.submit_answered_survey( + account_id, + source_id, + 'en_US', 10, survey_10) + t.commit() + + # now lock the barcode to the survey that was recently submitted + with Transaction() as t: + qiita_repo = QiitaRepo(t) + qiita_repo.lock_sample_to_survey(test_barcodes) + + with t.dict_cursor() as cur: + cur.execute("SELECT * FROM source_barcodes_surveys " + "WHERE barcode = '000069747'") + rows_after = cur.fetchall() + + self.assertGreater(len(rows_after), len(rows_before)) + if __name__ == '__main__': main() From 476ce7c6fb7233b5a38ed04ed33d3f640b3f6a6b Mon Sep 17 00:00:00 2001 From: ayobi Date: Mon, 22 Apr 2024 19:23:32 -0400 Subject: [PATCH 10/18] changes per suggestions --- microsetta_private_api/repo/qiita_repo.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/microsetta_private_api/repo/qiita_repo.py b/microsetta_private_api/repo/qiita_repo.py index 97b65be05..eff3f974e 100644 --- a/microsetta_private_api/repo/qiita_repo.py +++ b/microsetta_private_api/repo/qiita_repo.py @@ -1,4 +1,3 @@ -from microsetta_private_api.exceptions import RepoException from microsetta_private_api.repo.admin_repo import AdminRepo from microsetta_private_api.repo.base_repo import BaseRepo from microsetta_private_api.qiita import qclient @@ -9,7 +8,7 @@ class QiitaRepo(BaseRepo): - def lock_sample_to_survey(self, barcodes): + def lock_completed_surveys_to_barcodes(self, barcodes): # lock survey-sample association with Transaction() as t: admin_repo = AdminRepo(t) @@ -30,8 +29,6 @@ def lock_sample_to_survey(self, barcodes): for survey_id in survey_ids: sar_repo.associate_answered_survey_with_sample( account_id, source_id, sample_id, survey_id) - else: - raise RepoException("Survey IDs not found for barcode") t.commit() @@ -96,9 +93,6 @@ def push_metadata_to_qiita(self, barcodes=None): else: barcodes = set(barcodes) - # lock survey-sample association - self.lock_sample_to_survey(barcodes) - # determine what samples are already known in qiita samples_in_qiita = set(qclient.get('/api/v1/study/10317/samples')) @@ -118,6 +112,9 @@ def push_metadata_to_qiita(self, barcodes=None): # calls to this function if and as needed. to_push = list(barcodes - samples_in_qiita)[:1000] + # lock survey-sample association + self.lock_completed_surveys_to_barcodes(barcodes) + # short circuit if we do not have anything to push if len(to_push) == 0: return 0, [] From f7005745d0ea7b61f089b4543544ec5dccc46b1f Mon Sep 17 00:00:00 2001 From: ayobi Date: Mon, 22 Apr 2024 19:50:04 -0400 Subject: [PATCH 11/18] updated test --- microsetta_private_api/repo/tests/test_qiita.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsetta_private_api/repo/tests/test_qiita.py b/microsetta_private_api/repo/tests/test_qiita.py index 3fe6ef547..3fed2ae30 100644 --- a/microsetta_private_api/repo/tests/test_qiita.py +++ b/microsetta_private_api/repo/tests/test_qiita.py @@ -120,7 +120,7 @@ def test_lock_sample_to_survey(self): # now lock the barcode to the survey that was recently submitted with Transaction() as t: qiita_repo = QiitaRepo(t) - qiita_repo.lock_sample_to_survey(test_barcodes) + qiita_repo.lock_completed_surveys_to_barcodes(test_barcodes) with t.dict_cursor() as cur: cur.execute("SELECT * FROM source_barcodes_surveys " From c642cdb32625581c49909a18aaa33713ae5c4d71 Mon Sep 17 00:00:00 2001 From: ayobi Date: Wed, 24 Apr 2024 18:45:07 -0400 Subject: [PATCH 12/18] additional changes --- microsetta_private_api/repo/qiita_repo.py | 2 +- microsetta_private_api/repo/tests/test_qiita.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/microsetta_private_api/repo/qiita_repo.py b/microsetta_private_api/repo/qiita_repo.py index eff3f974e..0133171ba 100644 --- a/microsetta_private_api/repo/qiita_repo.py +++ b/microsetta_private_api/repo/qiita_repo.py @@ -113,7 +113,7 @@ def push_metadata_to_qiita(self, barcodes=None): to_push = list(barcodes - samples_in_qiita)[:1000] # lock survey-sample association - self.lock_completed_surveys_to_barcodes(barcodes) + self.lock_completed_surveys_to_barcodes(to_push) # short circuit if we do not have anything to push if len(to_push) == 0: diff --git a/microsetta_private_api/repo/tests/test_qiita.py b/microsetta_private_api/repo/tests/test_qiita.py index 3fed2ae30..1624b2a6b 100644 --- a/microsetta_private_api/repo/tests/test_qiita.py +++ b/microsetta_private_api/repo/tests/test_qiita.py @@ -70,7 +70,7 @@ def test_push_metadata_to_qiita(self, test_retrieve_metadata, "associated with any surveys " "matching this template id")}]) - def test_lock_sample_to_survey(self): + def test_lock_completed_surveys_to_barcodes(self): test_barcode = '000069747' test_barcodes = [test_barcode] @@ -115,7 +115,6 @@ def test_lock_sample_to_survey(self): account_id, source_id, 'en_US', 10, survey_10) - t.commit() # now lock the barcode to the survey that was recently submitted with Transaction() as t: From ba756b1612bc6fa4963a4667620292d4e4f89702 Mon Sep 17 00:00:00 2001 From: ayobi Date: Wed, 24 Apr 2024 18:54:30 -0400 Subject: [PATCH 13/18] added back commit --- microsetta_private_api/repo/tests/test_qiita.py | 1 + 1 file changed, 1 insertion(+) diff --git a/microsetta_private_api/repo/tests/test_qiita.py b/microsetta_private_api/repo/tests/test_qiita.py index 1624b2a6b..3d9919885 100644 --- a/microsetta_private_api/repo/tests/test_qiita.py +++ b/microsetta_private_api/repo/tests/test_qiita.py @@ -115,6 +115,7 @@ def test_lock_completed_surveys_to_barcodes(self): account_id, source_id, 'en_US', 10, survey_10) + t.commit() # now lock the barcode to the survey that was recently submitted with Transaction() as t: From b50d6318929de07326c5b6c5e065c2cac27b2402 Mon Sep 17 00:00:00 2001 From: ayobi Date: Wed, 24 Apr 2024 22:00:47 -0400 Subject: [PATCH 14/18] towards moving test into one transaction --- microsetta_private_api/repo/qiita_repo.py | 5 +---- microsetta_private_api/repo/tests/test_qiita.py | 5 ++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/microsetta_private_api/repo/qiita_repo.py b/microsetta_private_api/repo/qiita_repo.py index 0133171ba..1f5cde4fd 100644 --- a/microsetta_private_api/repo/qiita_repo.py +++ b/microsetta_private_api/repo/qiita_repo.py @@ -4,13 +4,12 @@ from microsetta_private_api.repo.metadata_repo import retrieve_metadata from microsetta_private_api.repo.metadata_repo._constants import MISSING_VALUE from microsetta_private_api.repo.survey_answers_repo import SurveyAnswersRepo -from microsetta_private_api.repo.transaction import Transaction class QiitaRepo(BaseRepo): def lock_completed_surveys_to_barcodes(self, barcodes): # lock survey-sample association - with Transaction() as t: + with self._transaction as t: admin_repo = AdminRepo(t) sar_repo = SurveyAnswersRepo(t) @@ -30,8 +29,6 @@ def lock_completed_surveys_to_barcodes(self, barcodes): sar_repo.associate_answered_survey_with_sample( account_id, source_id, sample_id, survey_id) - t.commit() - def push_metadata_to_qiita(self, barcodes=None): """Attempt to format and push metadata for the set of barcodes diff --git a/microsetta_private_api/repo/tests/test_qiita.py b/microsetta_private_api/repo/tests/test_qiita.py index 3d9919885..a87a77445 100644 --- a/microsetta_private_api/repo/tests/test_qiita.py +++ b/microsetta_private_api/repo/tests/test_qiita.py @@ -115,10 +115,8 @@ def test_lock_completed_surveys_to_barcodes(self): account_id, source_id, 'en_US', 10, survey_10) - t.commit() - # now lock the barcode to the survey that was recently submitted - with Transaction() as t: + # now lock the barcode to the survey that was recently submitted qiita_repo = QiitaRepo(t) qiita_repo.lock_completed_surveys_to_barcodes(test_barcodes) @@ -126,6 +124,7 @@ def test_lock_completed_surveys_to_barcodes(self): cur.execute("SELECT * FROM source_barcodes_surveys " "WHERE barcode = '000069747'") rows_after = cur.fetchall() + t.commit() self.assertGreater(len(rows_after), len(rows_before)) From 27ae47cfc64ebc67384bd2d38724aa017091e0ae Mon Sep 17 00:00:00 2001 From: ayobi Date: Wed, 24 Apr 2024 22:18:53 -0400 Subject: [PATCH 15/18] remove commit --- microsetta_private_api/repo/tests/test_qiita.py | 1 - 1 file changed, 1 deletion(-) diff --git a/microsetta_private_api/repo/tests/test_qiita.py b/microsetta_private_api/repo/tests/test_qiita.py index a87a77445..cdb39f8dd 100644 --- a/microsetta_private_api/repo/tests/test_qiita.py +++ b/microsetta_private_api/repo/tests/test_qiita.py @@ -124,7 +124,6 @@ def test_lock_completed_surveys_to_barcodes(self): cur.execute("SELECT * FROM source_barcodes_surveys " "WHERE barcode = '000069747'") rows_after = cur.fetchall() - t.commit() self.assertGreater(len(rows_after), len(rows_before)) From fc7d4ceb411066c117a15cfc97a99e140bf5bad3 Mon Sep 17 00:00:00 2001 From: ayobi Date: Thu, 25 Apr 2024 22:02:43 -0400 Subject: [PATCH 16/18] added suggestion --- microsetta_private_api/repo/qiita_repo.py | 29 +++++++++++------------ 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/microsetta_private_api/repo/qiita_repo.py b/microsetta_private_api/repo/qiita_repo.py index 1f5cde4fd..9f31150e0 100644 --- a/microsetta_private_api/repo/qiita_repo.py +++ b/microsetta_private_api/repo/qiita_repo.py @@ -9,25 +9,24 @@ class QiitaRepo(BaseRepo): def lock_completed_surveys_to_barcodes(self, barcodes): # lock survey-sample association - with self._transaction as t: - admin_repo = AdminRepo(t) - sar_repo = SurveyAnswersRepo(t) + admin_repo = AdminRepo(self._transaction) + sar_repo = SurveyAnswersRepo(self._transaction) - for sample_barcode in barcodes: - ids = admin_repo._get_ids_relevant_to_barcode(sample_barcode) + for sample_barcode in barcodes: + ids = admin_repo._get_ids_relevant_to_barcode(sample_barcode) - if ids is not None: - account_id = ids.get('account_id') - source_id = ids.get('source_id') - sample_id = ids.get('sample_id') + if ids is not None: + account_id = ids.get('account_id') + source_id = ids.get('source_id') + sample_id = ids.get('sample_id') - survey_ids = sar_repo.list_answered_surveys( - account_id, source_id) + survey_ids = sar_repo.list_answered_surveys( + account_id, source_id) - if survey_ids is not None: - for survey_id in survey_ids: - sar_repo.associate_answered_survey_with_sample( - account_id, source_id, sample_id, survey_id) + if survey_ids is not None: + for survey_id in survey_ids: + sar_repo.associate_answered_survey_with_sample( + account_id, source_id, sample_id, survey_id) def push_metadata_to_qiita(self, barcodes=None): """Attempt to format and push metadata for the set of barcodes From 20dbb3ab8993b1eaeaf7f56b07ce0896b609b7bc Mon Sep 17 00:00:00 2001 From: ayobi Date: Wed, 2 Oct 2024 18:45:30 -0400 Subject: [PATCH 17/18] add commit to qitta metadata update --- microsetta_private_api/tasks.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/microsetta_private_api/tasks.py b/microsetta_private_api/tasks.py index 6e3ef228a..2aea6c244 100644 --- a/microsetta_private_api/tasks.py +++ b/microsetta_private_api/tasks.py @@ -86,3 +86,5 @@ def update_qiita_metadata(): {"what": "qiita metadata push errors", "content": json.dumps(error, indent=2)}, EN_US) + else: + t.commit() From 2576156682d4f6fab7e147a6990da7101719a0ff Mon Sep 17 00:00:00 2001 From: Cassidy Symons <83246693+cassidysymons@users.noreply.github.com> Date: Wed, 2 Oct 2024 15:51:42 -0700 Subject: [PATCH 18/18] Update microsetta_private_api/tasks.py --- microsetta_private_api/tasks.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/microsetta_private_api/tasks.py b/microsetta_private_api/tasks.py index 2aea6c244..d42cf1ff3 100644 --- a/microsetta_private_api/tasks.py +++ b/microsetta_private_api/tasks.py @@ -86,5 +86,4 @@ def update_qiita_metadata(): {"what": "qiita metadata push errors", "content": json.dumps(error, indent=2)}, EN_US) - else: - t.commit() + t.commit()