Example #1
0
 def testGetSurveysForUserByEmail(self):
     user = connection.execute(auth_user_table.select().where(
         auth_user_table.c.email == 'test_email')).first()
     condition = survey_table.c.auth_user_id == user.auth_user_id
     surveys = connection.execute(survey_table.select().where(
         condition)).fetchall()
     surveys_by_email = get_surveys_by_email(connection, user.email)
     self.assertEqual(len(surveys), len(surveys_by_email))
     self.assertEqual(surveys[0].survey_id,
                      surveys_by_email[0].survey_id)
Example #2
0
 def testSurveyInsert(self):
     auth_user_id = connection.execute(auth_user_table.select().where(
         auth_user_table.c.email == 'test_email')).first().auth_user_id
     stmt = survey_insert(survey_title='test insert',
                          survey_metadata=None,
                          auth_user_id=auth_user_id)
     survey_id = connection.execute(stmt).inserted_primary_key[0]
     condition = survey_table.c.survey_title == 'test insert'
     get_stmt = connection.execute(
         survey_table.select().where(condition)).first()
     self.assertEqual(get_stmt.survey_id, survey_id)
Example #3
0
 def testDeleteRecord(self):
     auth_user_id = connection.execute(auth_user_table.select().where(
         auth_user_table.c.email == 'test_email')).first().auth_user_id
     exec_stmt = connection.execute(survey_insert(
         survey_title='delete me',
         survey_metadata={},
         auth_user_id=auth_user_id))
     survey_id = exec_stmt.inserted_primary_key[0]
     connection.execute(delete_record(survey_table, 'survey_id', survey_id))
     condition = survey_table.c.survey_id == survey_id
     self.assertEqual(
         connection.execute(
             survey_table.select().where(condition)).rowcount,
         0)
Example #4
0
 def testSurveySelect(self):
     user = connection.execute(auth_user_table.select().where(
         auth_user_table.c.email == 'test_email')).first()
     survey = connection.execute(survey_table.select().where(
         survey_table.c.survey_title == 'test_title')).first()
     self.assertEqual(survey.survey_title,
                      survey_select(connection, survey.survey_id,
                                    auth_user_id=user.auth_user_id)
                      .survey_title)
     self.assertEqual(survey.survey_title,
                      survey_select(connection, survey.survey_id,
                                    email=user.email).survey_title)
     self.assertRaises(TypeError, survey_select, connection,
                       survey.survey_id,
                       auth_user_id=user.auth_user_id,
                       email=user.email)
     self.assertRaises(TypeError, survey_select, connection,
                       survey.survey_id)
Example #5
0
    def testGetFreeTitle(self):
        auth_user_id = connection.execute(auth_user_table.select().where(
            auth_user_table.c.email == 'test_email')).first().auth_user_id

        self.assertEqual(
            get_free_title(connection, 'test insert', auth_user_id),
            'test insert')

        stmt = survey_insert(survey_title='test insert',
                             survey_metadata={},
                             auth_user_id=auth_user_id)
        connection.execute(stmt)
        self.assertEqual(
            get_free_title(connection, 'test insert', auth_user_id),
            'test insert(1)')
        stmt2 = survey_insert(survey_title='test insert(1)',
                              survey_metadata={},
                              auth_user_id=auth_user_id)
        connection.execute(stmt2)
        self.assertEqual(
            get_free_title(connection, 'test insert', auth_user_id),
            'test insert(2)')
Example #6
0
 def testSubmissionSelect(self):
     survey_id = connection.execute(survey_table.select().where(
         survey_table.c.survey_title == 'test_title')).first().survey_id
     submission_exec = connection.execute(
         submission_insert(submitter='test_submitter',
                           submitter_email='*****@*****.**',
                           survey_id=survey_id))
     submission_id = submission_exec.inserted_primary_key[0]
     submission = submission_select(connection, submission_id,
                                    email='test_email')
     self.assertEqual(submission_id, submission.submission_id)
     user_id = connection.execute(auth_user_table.select().where(
         auth_user_table.c.email == 'test_email')).first().auth_user_id
     submission2 = submission_select(connection, submission_id,
                                     auth_user_id=user_id)
     self.assertEqual(submission_id,
                      submission2.submission_id)
     self.assertRaises(TypeError, submission_select, connection,
                       submission_id,
                       auth_user_id='', email='')
     self.assertRaises(TypeError, submission_select, connection,
                       submission_id)
Example #7
0
    def testUpdateRecord(self):
        auth_user_id = connection.execute(auth_user_table.select().where(
            auth_user_table.c.email == 'test_email')).first().auth_user_id
        exec_stmt = connection.execute(survey_insert(
            survey_title='update me',
            survey_metadata={},
            auth_user_id=auth_user_id))
        survey_id = exec_stmt.inserted_primary_key[0]
        connection.execute(update_record(survey_table, 'survey_id', survey_id,
                                         survey_title='updated'))
        condition = survey_table.c.survey_id == survey_id
        new_record = connection.execute(
            survey_table.select().where(condition)).first()
        self.assertEqual(new_record.survey_title, 'updated')
        self.assertNotEqual(new_record.survey_last_update_time,
                            new_record.created_on)

        connection.execute(update_record(
            survey_table, 'survey_id', survey_id,
            values_dict={'survey_title': 'update2'}))

        new_record = connection.execute(survey_table.select().where(
            condition)).first()
        self.assertEqual(new_record.survey_title, 'update2')

        self.assertRaises(TypeError, update_record, survey_table,
                          'survey_id',
                          survey_id,
                          values_dict={'survey_title': 'updated2'},
                          survey_title='updated3')
        self.assertRaises(TypeError, update_record, survey_table,
                          'survey_id',
                          survey_id)

        connection.execute(delete_record(survey_table, 'survey_id', survey_id))

        if __name__ == '__main__':
            unittest.main()
Example #8
0
 def testCreateAuthUser(self):
     connection.execute(create_auth_user(email='a'))
     self.assertEqual(len(connection.execute(
         auth_user_table.select().where(
             auth_user_table.c.email == 'a')).fetchall()), 1)