Commit c11c6638 authored by Michal Čihař's avatar Michal Čihař

Test custom registration

parent ae413903
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2013 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
Replace this with more appropriate tests for your application.
"""
Tests for user handling.
"""
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
from django.core import mail
class RegistrationTest(TestCase):
def test_register(self):
response = self.client.post(
reverse('weblate_register'),
{
'username': 'username',
'email': 'noreply@weblate.org',
'password1': 'password',
'password2': 'password',
'first_name': 'First',
'last_name': 'Last',
}
)
# Check we did succeed
self.assertRedirects(response, reverse('registration_complete'))
# Check registration mail
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(
mail.outbox[0].subject,
'Your registration on Weblate'
)
# Get confirmation URL from mail
line = ''
for line in mail.outbox[0].body.splitlines():
if line.startswith('http://example.com'):
break
# Confirm account
response = self.client.get(line[18:])
self.assertRedirects(
response,
reverse('registration_activation_complete')
)
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
user = User.objects.get(username='username')
# Verify user is active
self.assertTrue(user.is_active)
# Verify stored first/last name
self.assertEqual(user.first_name, 'First')
self.assertEqual(user.last_name, 'Last')
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