def _generate_message_parameters(want_permutations=False): """Generate message parameters for test cases. Args: want_permutations: bool, whether or not to run the messages through various permutations. Yields: A list containing the list of messages. """ answer_message = survey_messages.Answer(text='Left my laptop at home.', more_info_enabled=False, placeholder_text=None) survey_messages_1 = survey_messages.Question( question_type=survey_models.QuestionType.ASSIGNMENT, question_text=_QUESTION.format(num=1), answers=[answer_message], rand_weight=1, required=True) survey_messages_2 = survey_messages.Question( question_type=survey_models.QuestionType.ASSIGNMENT, question_text=_QUESTION.format(num=2), answers=[answer_message], rand_weight=1, enabled=False, required=False) survey_messages_3 = survey_messages.Question( question_type=survey_models.QuestionType.RETURN, question_text=_QUESTION.format(num=3), answers=[answer_message], rand_weight=1, enabled=True) messages = [survey_messages_1, survey_messages_2, survey_messages_3] if want_permutations: for p in itertools.permutations(messages): yield [p] else: yield [messages]
def _build_survey_messages(question_model): """Builds a Question message from a Question NDB model instance. Args: question_model: survey_models.Question, An instance of the Question NDB model from datastore. Returns: A populated survey question message. """ message = survey_messages.Question( question_type=question_model.question_type, question_text=question_model.question_text, enabled=question_model.enabled, rand_weight=question_model.rand_weight, question_urlsafe_key=question_model.key.urlsafe(), required=config_model.Config.get('require_surveys'), ) for answer in question_model.answers: message.answers.append(survey_messages.Answer( text=answer.text, more_info_enabled=answer.more_info_enabled, placeholder_text=answer.placeholder_text)) return message