コード例 #1
0
ファイル: survey_api_test.py プロジェクト: virniles/loaner
    def create_test_models(self, iterations):
        """Creates models directly for testing.

    Args:
      iterations: int, The number of Answers and Questions to create.

    Returns:
      Two ndb.Key lists for the manually created Answers and Questions.
    """
        question_keys = []
        answers = []
        for i in xrange(iterations):
            answers.append(
                survey_models.Answer.create(
                    text='Answer {num}'.format(num=i),
                    more_info_enabled=True,
                    placeholder_text='PlaceHolder {num}'.format(num=i)))
            question_keys.append(
                survey_models.Question(
                    question_type=survey_models.QuestionType.ASSIGNMENT,
                    question_text=_QUESTION.format(num=i),
                    enabled=True,
                    rand_weight=1,
                    answers=answers).put())
        return answers, question_keys
コード例 #2
0
  def initialize_tables(self):
    """Performs first-time setup by creating dataset/tables."""
    if constants.ON_LOCAL:
      logging.debug('On local, not connecting to BQ.')
      return

    logging.info('Beginning BigQuery initialization.')
    try:
      self._dataset.create()
    except cloud.exceptions.Conflict:
      logging.warning(
          'Dataset %s already exists, not creating.', self._dataset.name)
    else:
      logging.info('Dataset %s successfully created.', self._dataset.name)

    self._create_table(constants.BIGQUERY_DEVICE_TABLE, device_model.Device())
    self._create_table(constants.BIGQUERY_SHELF_TABLE, shelf_model.Shelf())
    self._create_table(
        constants.BIGQUERY_SURVEY_TABLE, survey_models.Question())

    logging.info('BigQuery successfully initialized.')