|
1 | 1 | from unittest import TestCase, main
|
2 | 2 | from unittest.mock import patch
|
| 3 | +from microsetta_private_api.repo.survey_answers_repo import SurveyAnswersRepo |
3 | 4 | from microsetta_private_api.repo.transaction import Transaction
|
4 | 5 | from microsetta_private_api.repo.qiita_repo import QiitaRepo
|
5 | 6 |
|
@@ -69,6 +70,63 @@ def test_push_metadata_to_qiita(self, test_retrieve_metadata,
|
69 | 70 | "associated with any surveys "
|
70 | 71 | "matching this template id")}])
|
71 | 72 |
|
| 73 | + def test_lock_completed_surveys_to_barcodes(self): |
| 74 | + |
| 75 | + test_barcode = '000069747' |
| 76 | + test_barcodes = [test_barcode] |
| 77 | + |
| 78 | + with Transaction() as t: |
| 79 | + with t.dict_cursor() as cur: |
| 80 | + # first, find the ids for the barcode and survey we're using |
| 81 | + # as they are dynamically generated. |
| 82 | + cur.execute("select ag_login_id, source_id from " |
| 83 | + "ag_login_surveys a join source_barcodes_surveys b" |
| 84 | + " on a.survey_id = b.survey_id and b.barcode = " |
| 85 | + "'000069747' and survey_template_id = 1") |
| 86 | + row = cur.fetchone() |
| 87 | + account_id = row[0] |
| 88 | + source_id = row[1] |
| 89 | + |
| 90 | + cur.execute("select ag_kit_barcode_id from ag_kit_barcodes " |
| 91 | + "where barcode = '000069747'") |
| 92 | + row = cur.fetchone() |
| 93 | + |
| 94 | + cur.execute("SELECT * FROM source_barcodes_surveys " |
| 95 | + "WHERE barcode = '000069747'") |
| 96 | + rows_before = cur.fetchall() |
| 97 | + |
| 98 | + # submit a survey for the barcode |
| 99 | + sar = SurveyAnswersRepo(t) |
| 100 | + survey_10 = { |
| 101 | + '22': 'Unspecified', |
| 102 | + '108': 'Unspecified', |
| 103 | + '109': 'Unspecified', |
| 104 | + '110': 'Unspecified', |
| 105 | + '111': 'Unspecified', |
| 106 | + '112': '1990', |
| 107 | + '113': 'Unspecified', |
| 108 | + '115': 'Unspecified', |
| 109 | + '148': 'Unspecified', |
| 110 | + '492': 'Unspecified', |
| 111 | + '493': 'Unspecified', |
| 112 | + '502': 'Male' |
| 113 | + } |
| 114 | + sar.submit_answered_survey( |
| 115 | + account_id, |
| 116 | + source_id, |
| 117 | + 'en_US', 10, survey_10) |
| 118 | + |
| 119 | + # now lock the barcode to the survey that was recently submitted |
| 120 | + qiita_repo = QiitaRepo(t) |
| 121 | + qiita_repo.lock_completed_surveys_to_barcodes(test_barcodes) |
| 122 | + |
| 123 | + with t.dict_cursor() as cur: |
| 124 | + cur.execute("SELECT * FROM source_barcodes_surveys " |
| 125 | + "WHERE barcode = '000069747'") |
| 126 | + rows_after = cur.fetchall() |
| 127 | + |
| 128 | + self.assertGreater(len(rows_after), len(rows_before)) |
| 129 | + |
72 | 130 |
|
73 | 131 | if __name__ == '__main__':
|
74 | 132 | main()
|
0 commit comments