Commit a751572b authored by Christophe Siraut's avatar Christophe Siraut

Add functional tests.

parent ccf533c5
......@@ -4,3 +4,5 @@
fixtures
staticroot
local_settings.py
.coverage
htmlcov
......@@ -18,3 +18,8 @@ lint:
#django-lint
pylint --generated-members=objects,_meta,id meetingpoll
pylint --generated-members=objects,_meta,id accounts
test:
python-coverage run --source='.' manage.py test
python-coverage report
Nuages - Easy poll sharing
==========================
......@@ -95,6 +94,25 @@ Build database, collect static files and set permissions:
Set domain name: Point your browser to /admin/sites/site/1/ and modify the entry from "example.com" to your domain name.
Testing
=======
In order to test Nuages, you need the following dependencies:
webtest
coverage
django_webtest
django-discover-runner
On debian:
# aptitude install webtest coverage pip
# pip install django_webtest django-discover-runner
You can now validate your modifications with:
# make test
Email Service
=============
......
"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Replace these with more appropriate tests for your application.
"""
from django.core.urlresolvers import resolve
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.failUnlessEqual(1 + 1, 2)
__test__ = {"doctest": """
Another way to test that 1 + 1 is equal to 2.
>>> 1 + 1 == 2
True
"""}
......@@ -19,16 +19,19 @@ LOGIN_REDIRECT_URL = '/'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': os.path.join(PROJECT_DIR, 'nuages.sqlite'), # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(PROJECT_DIR, 'nuages.sqlite'),
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
},
}
ACCOUNT_ACTIVATION_DAYS = 7 # One-week activation window
ACCOUNT_ACTIVATION_DAYS = 7 # Activation window
#if django.VERSION[:2] < (1, 6):
TEST_RUNNER = 'discover_runner.DiscoverRunner'
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
......
#!/usr/bin/env python
from django.contrib.auth.models import User
from meetingpoll.models import Poll
def userFactory(**kwargs):
defaults = {
'username': 'username_1',
'password': 'password_1'
}
defaults.update(kwargs)
return User.objects.create_user(**defaults)
def pollFactory(**kwargs):
defaults = {
'title': 'Test poll',
'description': 'Test description',
'user': None
}
defaults.update(kwargs)
return Poll.objects.create(**defaults)
#!/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)
......@@ -7,7 +7,7 @@
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="{% trans 'Log in' %}" />
<input type="submit" value="{% trans 'Log in' %}" name="Log in" />
<input type="hidden" name="next" value="{{ next }}" />
</form>
<br />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment