test_functional.py 2.57 KB
Newer Older
chris's avatar
chris committed
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/usr/bin/env python
from django.core.urlresolvers import reverse
from django_webtest import WebTest
from meetingpoll.models import createId
from nuages.test_factories import userFactory, pollFactory


class MeetingPoll(WebTest):

    def setUp(self):
        self.poll = pollFactory()

    def test_is_displayed(self):
14 15
        # Mary got a poll URL
        # She can successfully open it
chris's avatar
chris committed
16 17
        response = self.app.get(self.poll.link)
        self.assertEqual(response.status_code, 200)
18
        # There is a form displayed waiting for her to answer
chris's avatar
chris committed
19 20 21 22
        self.assertTrue('form' in response.context)
        self.assertEqual(response.context['object'].id, self.poll.id)

    def test_404(self):
23
        # Test random URL failing
chris's avatar
chris committed
24 25 26
        response = self.app.get('/%s/' % createId(5), status=404)
        self.assertEqual(response.status_code, 404)

27
    def test_poll_creation(self):
28 29
        # Anne wants to create a poll
        # She forget to fill the form title
30 31 32 33 34 35 36 37 38 39 40 41 42
        new = self.app.get(reverse('new'))
        form = new.forms[0]
        form['description'] = 'fake description'
        edition = form.submit()
        self.assertContains(edition,
                            'Manage choices',
                            count=0,
                            status_code=200)
        self.assertContains(edition,
                            'This field is required',
                            count=1,
                            status_code=200)
        # He then fills the poll form
chris's avatar
chris committed
43 44 45 46 47
        new = self.app.get(reverse('new'))
        form = new.forms[0]
        form['title'] = 'fake title'
        form['description'] = 'fake description'
        edition = form.submit().follow()
48 49 50 51
        self.assertContains(edition,
                            'Manage choices',
                            count=1,
                            status_code=200)
chris's avatar
chris committed
52
        form = edition.forms[0]
53
        form['choice_set-0-choice'] = '30/06/13 17:00'
chris's avatar
chris committed
54 55
        form['choice_set-0-details'] = 'fake detail'
        votepage = form.submit().follow()
56 57 58 59 60
        # Anne reaches the voting page
        self.assertContains(votepage,
                            'Posted by',
                            count=1,
                            status_code=200)
chris's avatar
chris committed
61
        form = votepage.forms[0]
62 63
        form['2013-06-30 17:00:00-voice'] = 1
        form['2013-06-30 17:00:00-comment'] = "jaw-dropping comment"
chris's avatar
chris committed
64 65 66 67 68
        votepageagain = form.submit()
        self.assertContains(
            votepageagain, 'jaw-dropping comment', count=1, status_code=200)
        self.assertContains(
            votepageagain, 'cell-header', count=1, status_code=200)