예제 #1
0
def delete(connection: Connection, survey_id: str):
    """
    Delete the survey specified by the given survey_id

    :param connection: a SQLAlchemy connection
    :param survey_id: the UUID of the survey
    """
    with connection.begin():
        connection.execute(delete_record(survey_table, 'survey_id', survey_id))
    return json_response('Survey deleted')
예제 #2
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)
예제 #3
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()