test_functional.py 1.55 KB
Newer Older
chris's avatar
chris committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#!/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):
        response = self.app.get(self.poll.link)
        self.assertEqual(response.status_code, 200)
        self.assertTrue('form' in response.context)
        self.assertEqual(response.context['object'].id, self.poll.id)

    def test_404(self):
        response = self.app.get('/%s/' % createId(5), status=404)
        self.assertEqual(response.status_code, 404)

    def test_creation(self):
        new = self.app.get(reverse('new'))
        form = new.forms[0]
        form['title'] = 'fake title'
        form['description'] = 'fake description'
        edition = form.submit().follow()
        self.assertContains(
            edition, 'Manage choices', count=1, status_code=200)
        form = edition.forms[0]
        form['choice_set-0-choice_0'] = '06/06/2013 17:00'
        form['choice_set-0-details'] = 'fake detail'
        votepage = form.submit().follow()
        form = votepage.forms[0]
        form['2013-06-06 17:00:00-voice'] = 1
        form['2013-06-06 17:00:00-comment'] = "jaw-dropping comment"
        votepageagain = form.submit()
        self.assertContains(
            votepageagain, 'jaw-dropping comment', count=1, status_code=200)
        self.assertContains(
            votepageagain, 'cell-header', count=1, status_code=200)