Show More
@@ -15,7 +15,7 b' from pylons import config, url' | |||||
15 | from routes.util import URLGenerator |
|
15 | from routes.util import URLGenerator | |
16 | from webtest import TestApp |
|
16 | from webtest import TestApp | |
17 | import os |
|
17 | import os | |
18 |
|
18 | from pylons_app.model import meta | ||
19 | import pylons.test |
|
19 | import pylons.test | |
20 |
|
20 | |||
21 | __all__ = ['environ', 'url', 'TestController'] |
|
21 | __all__ = ['environ', 'url', 'TestController'] | |
@@ -32,5 +32,6 b' class TestController(TestCase):' | |||||
32 | config = wsgiapp.config |
|
32 | config = wsgiapp.config | |
33 | self.app = TestApp(wsgiapp) |
|
33 | self.app = TestApp(wsgiapp) | |
34 | url._push_object(URLGenerator(config['routes.map'], environ)) |
|
34 | url._push_object(URLGenerator(config['routes.map'], environ)) | |
|
35 | self.sa = meta.Session | |||
35 | TestCase.__init__(self, *args, **kwargs) |
|
36 | TestCase.__init__(self, *args, **kwargs) | |
36 |
|
37 |
@@ -1,18 +1,21 b'' | |||||
1 | from pylons_app.tests import * |
|
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 | class TestLoginController(TestController): |
|
6 | class TestLoginController(TestController): | |
4 |
|
7 | |||
5 | def test_index(self): |
|
8 | def test_index(self): | |
6 | response = self.app.get(url(controller='login', action='index')) |
|
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 | # Test response... |
|
11 | # Test response... | |
9 |
|
12 | |||
10 | def test_login_admin_ok(self): |
|
13 | def test_login_admin_ok(self): | |
11 | response = self.app.post(url(controller='login', action='index'), |
|
14 | response = self.app.post(url(controller='login', action='index'), | |
12 | {'username':'test_admin', |
|
15 | {'username':'test_admin', | |
13 | 'password':'test'}) |
|
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 | assert response.session['hg_app_user'].username =='test_admin','wrong logged in user' |
|
18 | assert response.session['hg_app_user'].username == 'test_admin', 'wrong logged in user' | |
16 | response = response.follow() |
|
19 | response = response.follow() | |
17 | assert 'auto description for vcs_test' in response.body |
|
20 | assert 'auto description for vcs_test' in response.body | |
18 |
|
21 | |||
@@ -20,32 +23,89 b' class TestLoginController(TestController' | |||||
20 | response = self.app.post(url(controller='login', action='index'), |
|
23 | response = self.app.post(url(controller='login', action='index'), | |
21 | {'username':'test_regular', |
|
24 | {'username':'test_regular', | |
22 | 'password':'test'}) |
|
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 | assert response.session['hg_app_user'].username =='test_regular','wrong logged in user' |
|
27 | assert response.session['hg_app_user'].username == 'test_regular', 'wrong logged in user' | |
25 | response = response.follow() |
|
28 | response = response.follow() | |
26 | assert 'auto description for vcs_test' in response.body |
|
29 | assert 'auto description for vcs_test' in response.body | |
27 | assert '<a title="Admin" href="/_admin">' not in response.body |
|
30 | assert '<a title="Admin" href="/_admin">' not in response.body | |
28 |
|
31 | |||
29 | def test_login_ok_came_from(self): |
|
32 | def test_login_ok_came_from(self): | |
30 | test_came_from = '/_admin/users' |
|
33 | test_came_from = '/_admin/users' | |
31 | response = self.app.post(url(controller='login', action='index',came_from=test_came_from), |
|
34 | response = self.app.post(url(controller='login', action='index', came_from=test_came_from), | |
32 | {'username':'test_admin', |
|
35 | {'username':'test_admin', | |
33 | 'password':'test'}) |
|
36 | 'password':'test'}) | |
34 | assert response.status == '302 Found','Wrong response code from came from redirection' |
|
37 | assert response.status == '302 Found', 'Wrong response code from came from redirection' | |
35 | response = response.follow() |
|
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 | assert 'Users administration' in response.body,'No proper title in response' |
|
41 | assert 'Users administration' in response.body, 'No proper title in response' | |
39 |
|
42 | |||
40 |
|
43 | |||
41 | def test_login_wrong(self): |
|
44 | def test_login_wrong(self): | |
42 | response = self.app.post(url(controller='login', action='index'), |
|
45 | response = self.app.post(url(controller='login', action='index'), | |
43 | {'username':'error', |
|
46 | {'username':'error', | |
44 | 'password':'test'}) |
|
47 | 'password':'test'}) | |
45 | assert response.status == '200 OK','Wrong response from login page' |
|
48 | assert response.status == '200 OK', 'Wrong response from login page' | |
46 |
|
49 | |||
47 | assert 'invalid user name' in response.body,'No error username message in response' |
|
50 | assert 'invalid user name' in response.body, 'No error username message in response' | |
48 | assert 'invalid password' in response.body,'No error password message in response' |
|
51 | assert 'invalid password' in response.body, 'No error password message in response' | |
49 |
|
52 | |||
50 |
|
53 | |||
51 | No newline at end of file |
|
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 |
General Comments 0
You need to be logged in to leave comments.
Login now