Ejemplo n.º 1
0
 def testQuestionBranchInsert(self):
     survey_id = connection.execute(survey_table.select().where(
         survey_table.c.survey_title == 'test_title')).first().survey_id
     to_question = get_questions_no_credentials(
         connection, survey_id).fetchall()[-1]
     q_where = question_table.select().where(
         cast(cast(question_table.c.logic['allow_other'], Text),
              Boolean))
     from_question = connection.execute(q_where).fetchall()[0]
     choice = get_choices(
         connection, from_question.question_id).fetchall()[0]
     from_tcn = from_question.type_constraint_name
     branch_dict = {'question_choice_id': choice.question_choice_id,
                    'from_question_id': from_question.question_id,
                    'from_type_constraint': from_tcn,
                    'from_sequence_number':
                        from_question.sequence_number,
                    'from_allow_multiple':
                        from_question.allow_multiple,
                    'from_survey_id': survey_id,
                    'to_question_id': to_question.question_id,
                    'to_type_constraint':
                        to_question.type_constraint_name,
                    'to_sequence_number':
                        to_question.sequence_number,
                    'to_allow_multiple': to_question.allow_multiple,
                    'to_survey_id': survey_id}
     branch_exec = connection.execute(question_branch_insert(**branch_dict))
     inserted_id = branch_exec.inserted_primary_key[0]
     the_branch = connection.execute(question_branch_table.select().where(
         question_branch_table.c.question_branch_id ==
         inserted_id)).first()
     self.assertEqual(the_branch.to_question_id,
                      to_question.question_id)
Ejemplo n.º 2
0
 def testQuestionSelect(self):
     survey_id = connection.execute(survey_table.select().where(
         survey_table.c.survey_title == 'test_title')).first().survey_id
     question_id = get_questions_no_credentials(
         connection, survey_id).first().question_id
     question = question_select(connection, question_id)
     self.assertEqual(question.question_id, question_id)
Ejemplo n.º 3
0
 def tearDown(self):
     survey_id = connection.execute(survey_table.select().where(
         survey_table.c.survey_title == 'test_title')).first().survey_id
     to_question = get_questions_no_credentials(
         connection, survey_id).fetchall()[-1]
     connection.execute(question_branch_table.delete().where(
         question_branch_table.c.to_question_id ==
         to_question.question_id))
Ejemplo n.º 4
0
def _to_json(connection: Connection, survey: RowProxy) -> dict:
    """
    Return the JSON representation of the given survey

    :param connection: a SQLAlchemy Connection
    :param survey: the survey object
    :return: a JSON dict representation
    """
    questions = get_questions_no_credentials(connection, survey.survey_id)
    q_fields = [_get_fields(connection, question) for question in questions]
    return {'survey_id': survey.survey_id,
            'survey_title': survey.survey_title,
            'survey_version': survey.survey_version,
            'survey_metadata': survey.survey_metadata,
            'questions': q_fields,
            'last_updated': survey.survey_last_update_time.isoformat(),
            'created_on': survey.created_on.isoformat()}
Ejemplo n.º 5
0
 def testGetQuestionsNoCredentials(self):
     survey_id = connection.execute(survey_table.select().where(
         survey_table.c.survey_title == 'test_title')).first().survey_id
     questions = get_questions_no_credentials(connection, survey_id)
     self.assertGreater(questions.rowcount, 0)