##// END OF EJS Templates
test for register page
marcink -
r463:a0325027 default
parent child Browse files
Show More
@@ -15,7 +15,7 from pylons import config, url
15 15 from routes.util import URLGenerator
16 16 from webtest import TestApp
17 17 import os
18
18 from pylons_app.model import meta
19 19 import pylons.test
20 20
21 21 __all__ = ['environ', 'url', 'TestController']
@@ -32,5 +32,6 class TestController(TestCase):
32 32 config = wsgiapp.config
33 33 self.app = TestApp(wsgiapp)
34 34 url._push_object(URLGenerator(config['routes.map'], environ))
35 self.sa = meta.Session
35 36 TestCase.__init__(self, *args, **kwargs)
36 37
@@ -1,17 +1,20
1 1 from pylons_app.tests import *
2 from pylons_app.model.db import User
3 from pylons_app.lib.auth import check_password
4
2 5
3 6 class TestLoginController(TestController):
4 7
5 8 def test_index(self):
6 9 response = self.app.get(url(controller='login', action='index'))
7 assert response.status == '200 OK','Wrong response from login page'
10 assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status
8 11 # Test response...
9 12
10 13 def test_login_admin_ok(self):
11 14 response = self.app.post(url(controller='login', action='index'),
12 15 {'username':'test_admin',
13 16 'password':'test'})
14 assert response.status == '302 Found','Wrong response code from login'
17 assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status
15 18 assert response.session['hg_app_user'].username =='test_admin','wrong logged in user'
16 19 response = response.follow()
17 20 assert 'auto description for vcs_test' in response.body
@@ -20,7 +23,7 class TestLoginController(TestController
20 23 response = self.app.post(url(controller='login', action='index'),
21 24 {'username':'test_regular',
22 25 'password':'test'})
23 assert response.status == '302 Found','Wrong response code from login'
26 assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status
24 27 assert response.session['hg_app_user'].username =='test_regular','wrong logged in user'
25 28 response = response.follow()
26 29 assert 'auto description for vcs_test' in response.body
@@ -34,7 +37,7 class TestLoginController(TestController
34 37 assert response.status == '302 Found','Wrong response code from came from redirection'
35 38 response = response.follow()
36 39
37 assert response.status == '200 OK','Wrong response from login page'
40 assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status
38 41 assert 'Users administration' in response.body,'No proper title in response'
39 42
40 43
@@ -48,4 +51,62 class TestLoginController(TestController
48 51 assert 'invalid password' in response.body,'No error password message in response'
49 52
50 53
54 def test_register(self):
55 response = self.app.get(url(controller='login', action='register'))
56 assert 'Sign Up to hg-app' in response.body, 'wrong page for user registration'
57
58 def test_register_err_same_username(self):
59 response = self.app.post(url(controller='login', action='register'),
60 {'username':'test_admin',
61 'password':'test',
62 'email':'goodmail@domain.com',
63 'name':'test',
64 'lastname':'test'})
65
66 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
67 assert 'This username already exists' in response.body
68
69 def test_register_err_wrong_data(self):
70 response = self.app.post(url(controller='login', action='register'),
71 {'username':'xs',
72 'password':'',
73 'email':'goodmailm',
74 'name':'test',
75 'lastname':'test'})
76
77 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
78 assert 'An email address must contain a single @' in response.body
79 assert 'Enter a value 3 characters long or more' in response.body
80 assert 'Please enter a value<' in response.body
81
82
83
84 def test_register_ok(self):
85 username = 'test_regular2'
86 password = 'qweqwe'
87 email = 'goodmail@mail.com'
88 name = 'testname'
89 lastname = 'testlastname'
90
91 response = self.app.post(url(controller='login', action='register'),
92 {'username':username,
93 'password':password,
94 'email':email,
95 'name':name,
96 'lastname':lastname})
97
98 assert response.status == '302 Found', 'Wrong response from register page got %s' % response.status
99
100 ret = self.sa.query(User).filter(User.username == 'test_regular2').one()
101 assert ret.username == username , 'field mismatch %s %s' % (ret.username, username)
102 assert check_password(password,ret.password) == True , 'password mismatch'
103 assert ret.email == email , 'field mismatch %s %s' % (ret.email, email)
104 assert ret.name == name , 'field mismatch %s %s' % (ret.name, name)
105 assert ret.lastname == lastname , 'field mismatch %s %s' % (ret.lastname, lastname)
106
107
108
109
110
111
51 112 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now