def delete_dummy_accts(): all_sample_ids = [] acct_ids = [ACCT_ID_1, ACCT_ID_2] with Transaction() as t: acct_repo = AccountRepo(t) source_repo = SourceRepo(t) survey_answers_repo = SurveyAnswersRepo(t) sample_repo = SampleRepo(t) for curr_acct_id in acct_ids: sources = source_repo.get_sources_in_account(curr_acct_id) for curr_source in sources: source_samples = sample_repo.get_samples_by_source( curr_acct_id, curr_source.id) sample_ids = [x.id for x in source_samples] all_sample_ids.extend(sample_ids) # Dissociate all samples linked to this source from all # answered surveys linked to this source, then delete all # answered surveys delete_dummy_answered_surveys_from_source_with_t( t, curr_acct_id, curr_source.id, sample_ids, survey_answers_repo) # Now dissociate all the samples from this source for curr_sample_id in sample_ids: sample_repo.dissociate_sample(curr_acct_id, curr_source.id, curr_sample_id) # Finally, delete the source source_repo.delete_source(curr_acct_id, curr_source.id) # Delete the account acct_repo.delete_account(curr_acct_id) # Belt and suspenders: these test emails are used by some tests outside # of this module as well, so can't be sure they are paired with the # above dummy account ids acct_repo.delete_account_by_email(TEST_EMAIL) acct_repo.delete_account_by_email(TEST_EMAIL_2) # Delete the kit and all samples that were attached to any sources # NB: This won't clean up any samples that were created but NOT # attached to any sources ... if len(all_sample_ids) == 0: all_sample_ids = None _remove_mock_kit(t, mock_sample_ids=all_sample_ids) t.commit()
def delete_dummy_accts(): with Transaction() as t: source_repo = SourceRepo(t) survey_answers_repo = SurveyAnswersRepo(t) sources = source_repo.get_sources_in_account(ACCT_ID_1) for curr_source in sources: answers = survey_answers_repo.list_answered_surveys( ACCT_ID_1, curr_source.id) for survey_id in answers: survey_answers_repo.delete_answered_survey( ACCT_ID_1, survey_id) source_repo.delete_source(ACCT_ID_1, curr_source.id) acct_repo = AccountRepo(t) acct_repo.delete_account(ACCT_ID_1) acct_repo.delete_account(ACCT_ID_2) # Belt and suspenders: these test emails are used by some tests outside # of this module as well, so can't be sure they are paired with the # above dummy account ids acct_repo.delete_account_by_email(TEST_EMAIL) acct_repo.delete_account_by_email(TEST_EMAIL_2) t.commit()