示例#1
0
    def test_logParticipantSample_tomultiplesurveys(self):
        ag_login_id = '5a10ea3e-9c7f-4ec3-9e96-3dc42e896668'
        participant_name = "Name - )?Åú*IüKb+"
        barcode = "000027913"

        # check that there are no barcode <-> survey assignments, prior to
        # logging
        with TRN:
            sql = """SELECT COUNT(*) FROM ag.source_barcodes_surveys
                     WHERE survey_id IN (SELECT survey_id
                                         FROM ag.ag_login_surveys
                                         WHERE ag_login_id = %s
                                         AND participant_name = %s)"""
            TRN.add(sql, [ag_login_id, participant_name])
            self.assertEqual(TRN.execute_fetchindex()[0][0], 0)

        self.ag_data.logParticipantSample(ag_login_id, barcode, 'Stool', None,
                                          datetime.date(2015, 9, 27),
                                          datetime.time(15, 54),
                                          participant_name, '')

        # check that single barcode gets assigned to BOTH surveys
        with TRN:
            TRN.add(sql, [ag_login_id, participant_name])
            self.assertEqual(TRN.execute_fetchindex()[0][0], 2)
    def test_deleteSample_removeallsurveys(self):
        ag_login_id = '5a10ea3e-9c7f-4ec3-9e96-3dc42e896668'
        participant_name = "Name - )?Åú*IüKb+"
        barcode = "000027913"
        self.ag_data.logParticipantSample(
            ag_login_id, barcode, 'Stool', None, datetime.date(2015, 9, 27),
            datetime.time(15, 54), participant_name, '')

        sql = """SELECT COUNT(*)
                 FROM ag.source_barcodes_surveys
                 WHERE barcode = %s"""
        # check that barcodes are assigned to surveys
        with TRN:
            TRN.add(sql, [barcode])
            self.assertEqual(TRN.execute_fetchindex()[0][0], 2)

        self.ag_data.deleteSample(barcode, ag_login_id)

        # ensure barcode to survey assignment is deleted
        with TRN:
            TRN.add(sql, [barcode])
            self.assertEqual(TRN.execute_fetchindex()[0][0], 0)
    def test_logParticipantSample_tomultiplesurveys(self):
        ag_login_id = '5a10ea3e-9c7f-4ec3-9e96-3dc42e896668'
        participant_name = "Name - )?Åú*IüKb+"
        barcode = "000027913"

        # check that there are no barcode <-> survey assignments, prior to
        # logging
        with TRN:
            sql = """SELECT COUNT(*) FROM ag.source_barcodes_surveys
                     WHERE survey_id IN (SELECT survey_id
                                         FROM ag.ag_login_surveys
                                         WHERE ag_login_id = %s
                                         AND participant_name = %s)"""
            TRN.add(sql, [ag_login_id, participant_name])
            self.assertEqual(TRN.execute_fetchindex()[0][0], 0)

        self.ag_data.logParticipantSample(
            ag_login_id, barcode, 'Stool', None, datetime.date(2015, 9, 27),
            datetime.time(15, 54), participant_name, '')

        # check that single barcode gets assigned to BOTH surveys
        with TRN:
            TRN.add(sql, [ag_login_id, participant_name])
            self.assertEqual(TRN.execute_fetchindex()[0][0], 2)
    def test_deleteAGParticipantSurvey(self):
        ag_login_id = '000fc4cd-8fa4-db8b-e050-8a800c5d02b5'

        with TRN:
            sql = """SELECT survey_id
                     FROM ag.ag_login_surveys
                     WHERE ag_login_id = %s"""
            TRN.add(sql, [ag_login_id])
            old_survey_ids = [x[0] for x in TRN.execute_fetchindex()]

            sql = """SELECT barcode
                     FROM ag.source_barcodes_surveys
                     WHERE survey_id IN %s"""
            TRN.add(sql, [tuple(old_survey_ids)])
            old_barcodes = [x[0] for x in TRN.execute_fetchindex()]

        # make sure we can get the corresponding survey by ID
        self.ag_data.getConsent('8b2b45bb3390b585')

        names = self.ag_data.ut_get_participant_names_from_ag_login_id(
            ag_login_id)
        self.ag_data.deleteAGParticipantSurvey(ag_login_id, names[0])

        with self.assertRaises(ValueError):
            self.ag_data.getConsent('8b2b45bb3390b585')

        res = self.ag_data.get_withdrawn()
        today = datetime.datetime.now().date()
        self.assertIn(ag_login_id, [r[0] for r in res])
        # we cannot check name and email since they get randomly scrubbed
        for r in res:
            if r[0] == ag_login_id:
                self.assertEqual(r[3], today)

        with TRN:
            # check that barcode are really deleted from
            # source_barcodes_surveys
            sql = """SELECT COUNT(*)
                     FROM ag.source_barcodes_surveys
                     WHERE barcode IN %s"""
            TRN.add(sql, [tuple(old_barcodes)])
            self.assertEqual(TRN.execute_fetchindex()[0][0], 0)

            # check that survey_ids are really deleted from
            # source_barcodes_surveys
            sql = """SELECT COUNT(*)
                     FROM ag.source_barcodes_surveys
                     WHERE survey_id IN %s"""
            TRN.add(sql, [tuple(old_survey_ids)])
            self.assertEqual(TRN.execute_fetchindex()[0][0], 0)

            # check that barcode are really deleted from
            # ag_kit_barcodes
            sql = """SELECT COUNT(*)
                     FROM ag.ag_kit_barcodes
                     WHERE barcode IN %s"""
            TRN.add(sql, [tuple(old_barcodes)])
            self.assertEqual(TRN.execute_fetchindex()[0][0], 0)