Esempio n. 1
0
    def test_download_csv_free_text_question_short_name(self):
        question = FreeTextQuestion(
            title='is this a test', short_name='short')
        self.polls_index.add_child(instance=question)
        question.save_revision().publish()

        client = Client()
        client.login(username='******', password='******')
        response = client.get('/')
        self.assertContains(response, 'is this a test')

        client.post(reverse('molo.polls:free_text_vote',
                    kwargs={'question_id': question.id}),
                    {'answer': 'this is an answer'})
        response = download_as_csv(QuestionAdmin(Question, self.site),
                                   None,
                                   Question.objects.all())
        date = str(datetime.datetime.now().date())
        expected_output = ('Content-Type: text/csv\r\nContent-Disposition:'
                           ' attachment;filename=questions-' + date +
                           '.csv\r\n\r\n'
                           'title,date_submitted,user,answer'
                           '\r\nshort,' + date + ',superuser,'
                           'this is an answer\r\n')
        self.assertEquals(str(response), expected_output)
Esempio n. 2
0
    def test_numerical_text_vote_blank_answer(self):
        question = FreeTextQuestion(title="is this a test")
        self.polls_index.add_child(instance=question)
        question.save_revision().publish()

        client = Client()
        client.login(username="******", password="******")
        response = client.get("/")
        self.assertContains(response, "is this a test")

        response = client.post(reverse("molo.polls:free_text_vote", kwargs={"question_id": question.id}))
        self.assertContains(response, "field is required")
        self.assertEquals(FreeTextVote.objects.all().count(), 0)

        response = client.get("/")
        self.assertNotContains(response, "already been submitted.")
Esempio n. 3
0
    def test_numerical_text_vote_unsuccessful(self):
        question = FreeTextQuestion(title="is this a test", numerical=True)
        self.polls_index.add_child(instance=question)
        question.save_revision().publish()

        client = Client()
        client.login(username="******", password="******")
        response = client.get("/")
        self.assertContains(response, "is this a test")

        response = client.post(
            reverse("molo.polls:free_text_vote", kwargs={"question_id": question.id}), {"answer": "text answer"}
        )
        self.assertEquals(FreeTextVote.objects.all().count(), 0)
        self.assertContains(response, "You did not enter a numerical value")

        response = client.get("/")
        self.assertNotContains(response, "already been submitted.")
Esempio n. 4
0
    def test_free_text_question_reply_stored_against_main_language(self):
        client = Client()
        client.login(username='******', password='******')
        question = FreeTextQuestion(title='what is this')
        self.polls_index.add_child(instance=question)
        question.save_revision().publish()
        self.client.post(reverse(
            'add_translation', args=[question.id, 'fr']))

        page = FreeTextQuestion.objects.get(
            slug='french-translation-of-what-is-this')
        page.save_revision().publish()

        client.post(reverse(
            'molo.polls:free_text_vote',
            kwargs={'question_id': page.id}),
            {'answer': 'A test free text question '})
        answer = FreeTextVote.objects.all().first()
        self.assertEquals(answer.question.id, question.id)
Esempio n. 5
0
    def test_translated_free_text_question_exists(self):
        client = Client()
        client.login(username='******', password='******')
        question = FreeTextQuestion(title='what is this')
        self.polls_index.add_child(instance=question)
        question.save_revision().publish()
        self.client.post(reverse(
            'add_translation', args=[question.id, 'fr']))

        page = FreeTextQuestion.objects.get(
            slug='french-translation-of-what-is-this')
        page.save_revision().publish()

        response = self.client.get(reverse(
            'wagtailadmin_explore', args=[self.polls_index.id]))

        self.assertContains(response,
                            '<a href="/admin/pages/%s/edit/"'
                            % page.id)
Esempio n. 6
0
    def test_numerical_text_vote_successful(self):
        question = FreeTextQuestion(title="is this a test", numerical=True)
        self.polls_index.add_child(instance=question)
        question.save_revision().publish()

        client = Client()
        client.login(username="******", password="******")
        response = client.get("/")
        self.assertContains(response, "is this a test")

        client.post(reverse("molo.polls:free_text_vote", kwargs={"question_id": question.id}), {"answer": "1234"})
        response = client.get(reverse("molo.polls:results", kwargs={"poll_id": question.id}))

        self.assertEquals(FreeTextVote.objects.all().count(), 1)
        self.assertEquals(FreeTextVote.objects.all()[0].answer, "1234")
        self.assertContains(response, "Thank you for voting!")

        response = client.get("/")
        self.assertContains(response, "already been submitted.")
Esempio n. 7
0
    def test_numerical_text_vote_resubmission(self):
        question = FreeTextQuestion(title="is this a test")
        self.polls_index.add_child(instance=question)
        question.save_revision().publish()

        client = Client()
        client.login(username="******", password="******")
        response = client.get("/")
        self.assertContains(response, "is this a test")

        client.post(reverse("molo.polls:free_text_vote", kwargs={"question_id": question.id}), {"answer": "1234"})
        response = client.get(reverse("molo.polls:results", kwargs={"poll_id": question.id}))
        self.assertEquals(FreeTextVote.objects.all().count(), 1)
        self.assertEquals(FreeTextVote.objects.all()[0].answer, "1234")

        response = client.post(
            reverse("molo.polls:free_text_vote", kwargs={"question_id": question.id}), {"answer": "2345"}
        )
        self.assertRedirects(response, reverse("molo.polls:results", args=(question.id,)))
        self.assertEquals(FreeTextVote.objects.all().count(), 1)
        self.assertEquals(FreeTextVote.objects.all()[0].answer, "1234")
Esempio n. 8
0
    def test_freetextquestion_results_view(self):
        question = FreeTextQuestion(title='is this a test')
        self.polls_index.add_child(instance=question)
        question.save_revision().publish()

        free_text_vote = FreeTextVote(user=self.superuser, question=question,
                                      answer='yeah probably')
        free_text_vote.save()

        response = self.client.get(
            '/admin/polls/question/{0}/results/'.format(question.id)
        )

        expected_headings_html = '<tr><th>Submission Date</th><th>Answer</th>'\
                                 '<th>User</th></tr>'

        expected_data_html = '<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>' \
            .format(datetime.today().strftime('%B %d, %Y'),
                    free_text_vote.answer,
                    self.superuser.username)

        self.assertContains(response, expected_headings_html, html=True)
        self.assertContains(response, expected_data_html, html=True)

        # test CSV download
        response = self.client.get(
            '/admin/polls/question/{0}/results/?action=download'.format(
                question.id)
        )

        expected_output = (
            'Submission Date,Answer,User\r\n'
            '%s,yeah probably,superuser\r\n'
            % datetime.today().strftime('%Y-%m-%d')
        )

        self.assertContains(response, expected_output)