Beispiel #1
0
    def test_make_new_survey(self):
        chains = mommy.make(Chain, _quantity=4)

        choices = []
        for chain in chains:
            seed_message = mommy.make(Message, chain=chain)
            choices.append(seed_message)

        questions = []
        for seed_message in choices:
            response = mommy.make(Message, chain=seed_message.chain,
                                  parent=seed_message)
            questions.append(response)

        choices_str = ','.join([str(message.id) for message in choices])
        questions_str = ','.join([str(message.id) for message in questions])

        survey_form = NewSurveyForm({'name': 'Test Survey',
                                     'questions': questions_str,
                                     'choices': choices_str})
        self.assertTrue(survey_form.is_valid())
        survey = survey_form.save()  # should not raise
        self.assertEquals(Survey.objects.count(), 1)

        self.assertEquals(survey.questions.count(), 4)
Beispiel #2
0
    def test_make_new_survey(self):
        chains = mommy.make(Chain, _quantity=4)

        choices = []
        for chain in chains:
            seed_message = mommy.make(Message, chain=chain)
            choices.append(seed_message)

        questions = []
        for seed_message in choices:
            response = mommy.make(Message,
                                  chain=seed_message.chain,
                                  parent=seed_message)
            questions.append(response)

        choices_str = ','.join([str(message.id) for message in choices])
        questions_str = ','.join([str(message.id) for message in questions])

        survey_form = NewSurveyForm({
            'name': 'Test Survey',
            'questions': questions_str,
            'choices': choices_str
        })
        self.assertTrue(survey_form.is_valid())
        survey = survey_form.save()  # should not raise
        self.assertEquals(Survey.objects.count(), 1)

        self.assertEquals(survey.questions.count(), 4)
Beispiel #3
0
 def handle(self, *args, **options):
     """Create a survey via form kwargs passed from the command line."""
     questions = determine_questions(**options)
     keys = ['name', 'num_questions_per_player', 'determine_correct']
     data = {k: options[k] for k in keys}
     data['choices'] = id_str(options['choices'])
     data['questions'] = id_str(determine_questions(**options))
     form = NewSurveyForm(data)
     if not form.is_valid():
         raise CommandError('form not valid:\n\n{}\n\n'.format(form.errors))
     survey = form.save()
Beispiel #4
0
    def test_make_new_survey(self):
        question_ids, choice_ids = self.create_choice_and_question_message_ids()

        questions_str = ','.join(question_ids)
        choices_str = ','.join(choice_ids)

        survey_form = NewSurveyForm({
            'name': 'Test Survey',
            'num_questions_per_player': 4,
            'questions': questions_str,
            'choices': choices_str,
        })

        self.assertTrue(survey_form.is_valid())
        survey = survey_form.save()  # should not raise
        self.assertEquals(Survey.objects.count(), 1)

        self.assertEquals(survey.questions.count(), 4)
Beispiel #5
0
    def create_survey(self, survey_name, from_game):
        game = Game.objects.get(name=from_game)
        chains = game.chain_set.all()

        questions = []
        choices = []

        for chain in chains:
            filled_messages = list(chain.message_set.exclude(audio=''))
            choices.append(filled_messages[0].id)
            questions.append(filled_messages[-1].id)

        questions_str = ','.join(map(str, questions))
        choices_str = ','.join(map(str, choices))

        survey_form = NewSurveyForm({
            'name': survey_name,
            'questions': questions_str,
            'choices': choices_str,
        })
        survey_form.full_clean()
        survey = survey_form.save()
        return survey