test_functional.py 1.7 KB
Newer Older
Christophe Siraut's avatar
Christophe Siraut 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 43 44 45 46 47 48 49 50 51 52 53 54 55
#!/usr/bin/environ python
from django.core.urlresolvers import reverse
from django_webtest import WebTest
from meetingpoll.models import createId
from test_factories import userFactory, pollFactory


class LoginProcess(WebTest):
    def setUp(self):
        userFactory()

    def testLoginProcess(self):
        login = self.app.get(reverse('auth_login'))
        login.form['username'] = 'username_1'
        login.form['password'] = 'password_1'
        response = login.form.submit('Log in').follow()
        self.assertEquals('200 OK', response.status)
        self.assertContains(
            response, 'My account', count=1, status_code=200)

    def testLoginWithInvalidCredentials(self):
        login = self.app.get(reverse('auth_login'))
        login.form['username'] = 'foo'
        login.form['password'] = 'bar'
        response = login.form.submit('Log in')
        self.assertContains(
            response,
            'Please enter a correct username and password.',
            count=1,
            status_code=200
        )


class HomePage(WebTest):

    def test_is_responding(self):
        home = self.app.get(reverse('home'))
        assert home.status_code == 200
        assert 'Nuages - Easy poll sharing' in home.content


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)