Пример #1
0
 def testGetSurveyIdFromPrefix(self):
     survey_id = connection.execute(survey_table.select().where(
         survey_table.c.survey_title == 'test_title')).first().survey_id
     self.assertEqual(
         get_survey_id_from_prefix(connection, survey_id[:10]),
         survey_id)
     self.assertRaises(SurveyPrefixDoesNotIdentifyASurveyError,
                       get_survey_id_from_prefix, connection,
                       str(uuid.uuid4()))
Пример #2
0
 def get(self, survey_prefix: str):
     try:
         survey_id = get_survey_id_from_prefix(self.db, survey_prefix)
         if len(survey_prefix) < 36:
             self.redirect('/survey/{}'.format(survey_id), permanent=False)
         else:
             survey = survey_api.display_survey(self.db,
                                                survey_id)['result']
             self.render('survey.html',
                         survey=json_encode(survey),
                         survey_version=survey['survey_version'],
                         survey_title=survey['survey_title'])
     except (SurveyPrefixDoesNotIdentifyASurveyError,
             SurveyPrefixTooShortError):
         raise tornado.web.HTTPError(404)