comparison pylons_app/tests/functional/test_admin_settings.py @ 491:fefffd6fd5f4 celery

Added some more tests, rewrite testing schema, to autogenerate fresh db, new index. cleaned up some codes that involves testing.
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 21 Sep 2010 01:08:01 +0200
parents 7c978511c951
children 53aa1ee1af86
comparison
equal deleted inserted replaced
490:74b9bed279ae 491:fefffd6fd5f4
1 from pylons_app.tests import * 1 from pylons_app.tests import *
2 from pylons_app.model.db import User
2 3
3 class TestSettingsController(TestController): 4 class TestSettingsController(TestController):
4 5
5 def test_index(self): 6 def test_index(self):
6 response = self.app.get(url('admin_settings')) 7 response = self.app.get(url('admin_settings'))
39 def test_edit(self): 40 def test_edit(self):
40 response = self.app.get(url('admin_edit_setting', setting_id=1)) 41 response = self.app.get(url('admin_edit_setting', setting_id=1))
41 42
42 def test_edit_as_xml(self): 43 def test_edit_as_xml(self):
43 response = self.app.get(url('formatted_admin_edit_setting', setting_id=1, format='xml')) 44 response = self.app.get(url('formatted_admin_edit_setting', setting_id=1, format='xml'))
45
46 def test_my_account(self):
47 self.log_user()
48 response = self.app.get(url('admin_settings_my_account'))
49 print response
50 assert 'value="test_admin' in response.body
51
52
53
54 def test_my_account_update(self):
55 self.log_user()
56 new_email = 'new@mail.pl'
57 response = self.app.post(url('admin_settings_my_account_update'), params=dict(
58 _method='put',
59 username='test_admin',
60 new_password='test',
61 password='',
62 name='NewName',
63 lastname='NewLastname',
64 email=new_email,))
65 response.follow()
66 print response
67
68 print 'x' * 100
69 print response.session
70 assert 'Your account was updated succesfully' in response.session['flash'][0][1], 'no flash message about success of change'
71 user = self.sa.query(User).filter(User.username == 'test_admin').one()
72 assert user.email == new_email , 'incorrect user email after update got %s vs %s' % (user.email, new_email)
73
74 def test_my_account_update_own_email_ok(self):
75 self.log_user()
76
77 new_email = 'new@mail.pl'
78 response = self.app.post(url('admin_settings_my_account_update'), params=dict(
79 _method='put',
80 username='test_admin',
81 new_password='test',
82 name='NewName',
83 lastname='NewLastname',
84 email=new_email,))
85 print response
86
87 def test_my_account_update_err_email_exists(self):
88 self.log_user()
89
90 new_email = 'test_regular@mail.com'#already exisitn email
91 response = self.app.post(url('admin_settings_my_account_update'), params=dict(
92 _method='put',
93 username='test_admin',
94 new_password='test',
95 name='NewName',
96 lastname='NewLastname',
97 email=new_email,))
98 print response
99
100 assert 'That e-mail address is already taken' in response.body, 'Missing error message about existing email'
101
102
103 def test_my_account_update_err(self):
104 self.log_user()
105
106 new_email = 'newmail.pl'
107 response = self.app.post(url('admin_settings_my_account_update'), params=dict(
108 _method='put',
109 username='test_regular2',
110 new_password='test',
111 name='NewName',
112 lastname='NewLastname',
113 email=new_email,))
114 print response
115 assert 'An email address must contain a single @' in response.body, 'Missing error message about wrong email'
116 assert 'This username already exists' in response.body, 'Missing error message about existing user'