def setUp(self):
        with Transaction() as t:
            sr = SourceRepo(t)
            sar = SurveyAnswersRepo(t)

            sr.create_source(HUMAN_SOURCE)
            sar.submit_answered_survey(ACCOUNT_ID, HUMAN_SOURCE.id,
                                       'en_US', 1, SURVEY_ANSWERS,
                                       SURVEY_ID)
            t.commit()
def create_dummy_answered_survey(dummy_acct_id, dummy_source_id,
                                 survey_template_id=PRIMARY_SURVEY_TEMPLATE_ID,
                                 survey_answers_id=DUMMY_ANSWERED_SURVEY_ID,
                                 survey_model=None, dummy_sample_id=None):

    if survey_model is None:
        survey_model = DUMMY_SURVEY_ANSWERS_MODEL

    with Transaction() as t:
        survey_answers_repo = SurveyAnswersRepo(t)
        survey_answers_id = survey_answers_repo.submit_answered_survey(
            dummy_acct_id,
            dummy_source_id,
            localization.EN_US,
            survey_template_id,
            survey_model,
            survey_answers_id
        )

        if dummy_sample_id is not None:
            survey_answers_repo.associate_answered_survey_with_sample(
                dummy_acct_id, dummy_source_id, dummy_sample_id,
                survey_answers_id)

        t.commit()

    return survey_answers_id
示例#3
0
def submit_answered_survey(account_id, source_id, language_tag, body,
                           token_info):
    _validate_account_access(token_info, account_id)

    if body['survey_template_id'] == SurveyTemplateRepo.VIOSCREEN_ID:
        return _submit_vioscreen_status(account_id, source_id,
                                        body["survey_text"]["key"])

    # TODO: Is this supposed to return new survey id?
    # TODO: Rename survey_text to survey_model/model to match Vue's naming?
    with Transaction() as t:
        survey_answers_repo = SurveyAnswersRepo(t)
        survey_answers_id = survey_answers_repo.submit_answered_survey(
            account_id, source_id, language_tag, body["survey_template_id"],
            body["survey_text"])
        t.commit()

        response = flask.Response()
        response.status_code = 201
        response.headers['Location'] = '/api/accounts/%s' \
                                       '/sources/%s' \
                                       '/surveys/%s' % \
                                       (account_id,
                                        source_id,
                                        survey_answers_id)
        return response