예제 #1
0
def get_one(connection: Connection, submission_id: str, email: str) -> dict:
    """
    Create a JSON representation of a submission.

    :param connection: a SQLAlchemy Connection
    :param submission_id: the UUID of the submission
    :param email: the user's e-mail address
    :return: a JSON dict
    """
    submission = submission_select(connection, submission_id, email=email)
    answers = _get_comparable(get_answers(connection, submission_id))
    choices = _get_comparable(get_answer_choices(connection, submission_id))
    # The merge is necessary to get the answers in sequence number order.
    result = merge(answers, choices)
    c = connection
    sub_dict = {
        'submission_id': submission_id,
        'survey_id': submission.survey_id,
        'submitter': submission.submitter,
        'submitter_email': submission.submitter_email,
        'submission_time': submission.submission_time.isoformat(),
        'save_time': submission.save_time.isoformat(),
        'answers': [_get_fields(c, answer) for num, answer in result]
    }
    return json_response(sub_dict)
예제 #2
0
 def testGetAnswerChoices(self):
     survey_id = connection.execute(survey_table.select().where(
         survey_table.c.survey_title == 'test_title')).first().survey_id
     q_where = question_table.select().where(
         question_table.c.type_constraint_name == 'multiple_choice')
     question = connection.execute(q_where).first()
     question_id = question.question_id
     tcn = question.type_constraint_name
     seq = question.sequence_number
     mul = question.allow_multiple
     submission_exec = connection.execute(submission_insert(
         submitter='test_submitter', submitter_email='*****@*****.**',
         survey_id=survey_id))
     submission_id = submission_exec.inserted_primary_key[0]
     choices = get_choices(connection, question_id)
     the_choice = choices.first()
     connection.execute(answer_choice_insert(
         question_choice_id=the_choice.question_choice_id,
         answer_choice_metadata={},
         question_id=question_id,
         submission_id=submission_id,
         survey_id=survey_id, type_constraint_name=tcn, sequence_number=seq,
         allow_multiple=mul))
     self.assertEqual(
         get_answer_choices(connection, submission_id).rowcount, 1)