##// END OF EJS Templates
Use only mustcontain for testing response body
marcink -
r3646:63e49418 beta
parent child Browse files
Show More
@@ -1,208 +1,210 b''
1 1 """Pylons application test package
2 2
3 3 This package assumes the Pylons environment is already loaded, such as
4 4 when this script is imported from the `nosetests --with-pylons=test.ini`
5 5 command.
6 6
7 7 This module initializes the application via ``websetup`` (`paster
8 8 setup-app`) and provides the base testing objects.
9 9
10 10 nosetests -x - fail on first error
11 11 nosetests rhodecode.tests.functional.test_admin_settings:TestSettingsController.test_my_account
12 12 nosetests --pdb --pdb-failures
13 13 nosetests --with-coverage --cover-package=rhodecode.model.validators rhodecode.tests.test_validators
14 14
15 15 optional FLAGS:
16 16 RC_WHOOSH_TEST_DISABLE=1 - skip whoosh index building and tests
17 17 RC_NO_TMP_PATH=1 - disable new temp path for tests, used mostly for test_vcs_operations
18 18
19 19 """
20 20 import os
21 21 import time
22 22 import logging
23 23 import datetime
24 24 import hashlib
25 25 import tempfile
26 26 from os.path import join as jn
27 27
28 28 from unittest import TestCase
29 29 from tempfile import _RandomNameSequence
30 30
31 31 from paste.deploy import loadapp
32 32 from paste.script.appinstall import SetupCommand
33 33 from pylons import config, url
34 34 from routes.util import URLGenerator
35 35 from webtest import TestApp
36 from nose.plugins.skip import SkipTest
36 37
37 38 from rhodecode import is_windows
38 39 from rhodecode.model.meta import Session
39 40 from rhodecode.model.db import User
40 41 from rhodecode.tests.nose_parametrized import parameterized
41 42
42 43 import pylons.test
43 44 from rhodecode.lib.utils2 import safe_unicode, safe_str
44 45
45 46
46 47 os.environ['TZ'] = 'UTC'
47 48 if not is_windows:
48 49 time.tzset()
49 50
50 51 log = logging.getLogger(__name__)
51 52
52 53 __all__ = [
53 54 'parameterized', 'environ', 'url', 'get_new_dir', 'TestController',
55 'SkipTest',
54 56 'TESTS_TMP_PATH', 'HG_REPO', 'GIT_REPO', 'NEW_HG_REPO', 'NEW_GIT_REPO',
55 57 'HG_FORK', 'GIT_FORK', 'TEST_USER_ADMIN_LOGIN', 'TEST_USER_ADMIN_PASS',
56 58 'TEST_USER_REGULAR_LOGIN', 'TEST_USER_REGULAR_PASS',
57 59 'TEST_USER_REGULAR_EMAIL', 'TEST_USER_REGULAR2_LOGIN',
58 60 'TEST_USER_REGULAR2_PASS', 'TEST_USER_REGULAR2_EMAIL', 'TEST_HG_REPO',
59 61 'TEST_HG_REPO_CLONE', 'TEST_HG_REPO_PULL', 'TEST_GIT_REPO',
60 62 'TEST_GIT_REPO_CLONE', 'TEST_GIT_REPO_PULL', 'HG_REMOTE_REPO',
61 63 'GIT_REMOTE_REPO', 'SCM_TESTS', '_get_repo_create_params',
62 64 '_get_group_create_params'
63 65 ]
64 66
65 67 # Invoke websetup with the current config file
66 68 # SetupCommand('setup-app').run([config_file])
67 69
68 70 environ = {}
69 71
70 72 #SOME GLOBALS FOR TESTS
71 73
72 74 TESTS_TMP_PATH = jn('/', 'tmp', 'rc_test_%s' % _RandomNameSequence().next())
73 75 TEST_USER_ADMIN_LOGIN = 'test_admin'
74 76 TEST_USER_ADMIN_PASS = 'test12'
75 77 TEST_USER_ADMIN_EMAIL = 'test_admin@mail.com'
76 78
77 79 TEST_USER_REGULAR_LOGIN = 'test_regular'
78 80 TEST_USER_REGULAR_PASS = 'test12'
79 81 TEST_USER_REGULAR_EMAIL = 'test_regular@mail.com'
80 82
81 83 TEST_USER_REGULAR2_LOGIN = 'test_regular2'
82 84 TEST_USER_REGULAR2_PASS = 'test12'
83 85 TEST_USER_REGULAR2_EMAIL = 'test_regular2@mail.com'
84 86
85 87 HG_REPO = 'vcs_test_hg'
86 88 GIT_REPO = 'vcs_test_git'
87 89
88 90 NEW_HG_REPO = 'vcs_test_hg_new'
89 91 NEW_GIT_REPO = 'vcs_test_git_new'
90 92
91 93 HG_FORK = 'vcs_test_hg_fork'
92 94 GIT_FORK = 'vcs_test_git_fork'
93 95
94 96 ## VCS
95 97 SCM_TESTS = ['hg', 'git']
96 98 uniq_suffix = str(int(time.mktime(datetime.datetime.now().timetuple())))
97 99
98 100 GIT_REMOTE_REPO = 'git://github.com/codeinn/vcs.git'
99 101
100 102 TEST_GIT_REPO = jn(TESTS_TMP_PATH, GIT_REPO)
101 103 TEST_GIT_REPO_CLONE = jn(TESTS_TMP_PATH, 'vcsgitclone%s' % uniq_suffix)
102 104 TEST_GIT_REPO_PULL = jn(TESTS_TMP_PATH, 'vcsgitpull%s' % uniq_suffix)
103 105
104 106
105 107 HG_REMOTE_REPO = 'http://bitbucket.org/marcinkuzminski/vcs'
106 108
107 109 TEST_HG_REPO = jn(TESTS_TMP_PATH, HG_REPO)
108 110 TEST_HG_REPO_CLONE = jn(TESTS_TMP_PATH, 'vcshgclone%s' % uniq_suffix)
109 111 TEST_HG_REPO_PULL = jn(TESTS_TMP_PATH, 'vcshgpull%s' % uniq_suffix)
110 112
111 113 TEST_DIR = tempfile.gettempdir()
112 114 TEST_REPO_PREFIX = 'vcs-test'
113 115
114 116 # cached repos if any !
115 117 # comment out to get some other repos from bb or github
116 118 GIT_REMOTE_REPO = jn(TESTS_TMP_PATH, GIT_REPO)
117 119 HG_REMOTE_REPO = jn(TESTS_TMP_PATH, HG_REPO)
118 120
119 121
120 122 def get_new_dir(title):
121 123 """
122 124 Returns always new directory path.
123 125 """
124 126 from rhodecode.tests.vcs.utils import get_normalized_path
125 127 name = TEST_REPO_PREFIX
126 128 if title:
127 129 name = '-'.join((name, title))
128 130 hex = hashlib.sha1(str(time.time())).hexdigest()
129 131 name = '-'.join((name, hex))
130 132 path = os.path.join(TEST_DIR, name)
131 133 return get_normalized_path(path)
132 134
133 135
134 136 class TestController(TestCase):
135 137
136 138 def __init__(self, *args, **kwargs):
137 139 wsgiapp = pylons.test.pylonsapp
138 140 config = wsgiapp.config
139 141
140 142 self.app = TestApp(wsgiapp)
141 143 url._push_object(URLGenerator(config['routes.map'], environ))
142 144 self.Session = Session
143 145 self.index_location = config['app_conf']['index_dir']
144 146 TestCase.__init__(self, *args, **kwargs)
145 147
146 148 def log_user(self, username=TEST_USER_ADMIN_LOGIN,
147 149 password=TEST_USER_ADMIN_PASS):
148 150 self._logged_username = username
149 151 response = self.app.post(url(controller='login', action='index'),
150 152 {'username': username,
151 153 'password': password})
152 154
153 155 if 'invalid user name' in response.body:
154 156 self.fail('could not login using %s %s' % (username, password))
155 157
156 158 self.assertEqual(response.status, '302 Found')
157 159 ses = response.session['rhodecode_user']
158 160 self.assertEqual(ses.get('username'), username)
159 161 response = response.follow()
160 162 self.assertEqual(ses.get('is_authenticated'), True)
161 163
162 164 return response.session['rhodecode_user']
163 165
164 166 def _get_logged_user(self):
165 167 return User.get_by_username(self._logged_username)
166 168
167 169 def checkSessionFlash(self, response, msg):
168 170 self.assertTrue('flash' in response.session,
169 171 msg='Response session:%r have no flash'
170 172 % response.session)
171 173 if not msg in response.session['flash'][0][1]:
172 174 msg = u'msg `%s` not found in session flash: got `%s` instead' % (
173 175 msg, response.session['flash'][0][1])
174 176 self.fail(safe_str(msg))
175 177
176 178
177 179 ## HELPERS ##
178 180
179 181 def _get_repo_create_params(**custom):
180 182 defs = {
181 183 'repo_name': None,
182 184 'repo_type': 'hg',
183 185 'clone_uri': '',
184 186 'repo_group': '',
185 187 'repo_description': 'DESC',
186 188 'repo_private': False,
187 189 'repo_landing_rev': 'tip'
188 190 }
189 191 defs.update(custom)
190 192 if 'repo_name_full' not in custom:
191 193 defs.update({'repo_name_full': defs['repo_name']})
192 194
193 195 return defs
194 196
195 197
196 198 def _get_group_create_params(**custom):
197 199 defs = dict(
198 200 group_name=None,
199 201 group_description='DESC',
200 202 group_parent_id=None,
201 203 perms_updates=[],
202 204 perms_new=[],
203 205 enable_locking=False,
204 206 recursive=False
205 207 )
206 208 defs.update(custom)
207 209
208 210 return defs
@@ -1,88 +1,85 b''
1 1 from rhodecode.tests import *
2 2 from rhodecode.model.db import RhodeCodeSetting
3 from nose.plugins.skip import SkipTest
4 3
5 4 skip_ldap_test = False
6 5 try:
7 6 import ldap
8 7 except ImportError:
9 8 # means that python-ldap is not installed
10 9 skip_ldap_test = True
11 10 pass
12 11
13 12
14 13 class TestLdapSettingsController(TestController):
15 14
16 15 def test_index(self):
17 16 self.log_user()
18 17 response = self.app.get(url(controller='admin/ldap_settings',
19 18 action='index'))
20 self.assertTrue('LDAP administration' in response.body)
19 response.mustcontain('LDAP administration')
21 20
22 21 def test_ldap_save_settings(self):
23 22 self.log_user()
24 23 if skip_ldap_test:
25 24 raise SkipTest('skipping due to missing ldap lib')
26 25
27 26 test_url = url(controller='admin/ldap_settings',
28 27 action='ldap_settings')
29 28
30 29 response = self.app.post(url=test_url,
31 30 params={'ldap_host' : u'dc.example.com',
32 31 'ldap_port' : '999',
33 32 'ldap_tls_kind' : 'PLAIN',
34 33 'ldap_tls_reqcert' : 'NEVER',
35 34 'ldap_dn_user':'test_user',
36 35 'ldap_dn_pass':'test_pass',
37 36 'ldap_base_dn':'test_base_dn',
38 37 'ldap_filter':'test_filter',
39 38 'ldap_search_scope':'BASE',
40 39 'ldap_attr_login':'test_attr_login',
41 40 'ldap_attr_firstname':'ima',
42 41 'ldap_attr_lastname':'tester',
43 42 'ldap_attr_email':'test@example.com' })
44 43
45 44 new_settings = RhodeCodeSetting.get_ldap_settings()
46 45 self.assertEqual(new_settings['ldap_host'], u'dc.example.com',
47 46 'fail db write compare')
48 47
49 48 self.checkSessionFlash(response,
50 49 'LDAP settings updated successfully')
51 50
52 51 def test_ldap_error_form(self):
53 52 self.log_user()
54 53 if skip_ldap_test:
55 54 raise SkipTest('skipping due to missing ldap lib')
56 55
57 56 test_url = url(controller='admin/ldap_settings',
58 57 action='ldap_settings')
59 58
60 59 response = self.app.post(url=test_url,
61 60 params={'ldap_host' : '',
62 61 'ldap_port' : 'i-should-be-number',
63 62 'ldap_tls_kind' : 'PLAIN',
64 63 'ldap_tls_reqcert' : 'NEVER',
65 64 'ldap_dn_user':'',
66 65 'ldap_dn_pass':'',
67 66 'ldap_base_dn':'',
68 67 'ldap_filter':'',
69 68 'ldap_search_scope':'BASE',
70 69 'ldap_attr_login':'', # <----- missing required input
71 70 'ldap_attr_firstname':'',
72 71 'ldap_attr_lastname':'',
73 72 'ldap_attr_email':'' })
74 73
75 self.assertTrue("""<span class="error-message">The LDAP Login"""
76 """ attribute of the CN must be specified""" in
77 response.body)
74 response.mustcontain("""<span class="error-message">The LDAP Login"""
75 """ attribute of the CN must be specified""")
78 76
79 77
80
81 self.assertTrue("""<span class="error-message">Please """
82 """enter a number</span>""" in response.body)
78 response.mustcontain("""<span class="error-message">Please """
79 """enter a number</span>""")
83 80
84 81 def test_ldap_login(self):
85 82 pass
86 83
87 84 def test_ldap_login_incorrect(self):
88 85 pass
@@ -1,106 +1,105 b''
1 1 from rhodecode.tests import *
2 2 from rhodecode.model.db import Notification, User
3 3
4 4 from rhodecode.model.user import UserModel
5 5 from rhodecode.model.notification import NotificationModel
6 6
7 7
8 8 class TestNotificationsController(TestController):
9 9
10 10 def tearDown(self):
11 11 for n in Notification.query().all():
12 12 inst = Notification.get(n.notification_id)
13 13 self.Session().delete(inst)
14 14 self.Session().commit()
15 15
16 16 def test_index(self):
17 17 self.log_user()
18 18
19 19 u1 = UserModel().create_or_update(username='u1', password='qweqwe',
20 20 email='u1@rhodecode.org',
21 21 firstname='u1', lastname='u1')
22 22 u1 = u1.user_id
23 23
24 24 response = self.app.get(url('notifications'))
25 self.assertTrue('''<div class="table">No notifications here yet</div>'''
26 in response.body)
25 response.mustcontain('<div class="table">No notifications here yet</div>')
27 26
28 27 cur_user = self._get_logged_user()
29 28
30 29 NotificationModel().create(created_by=u1, subject=u'test_notification_1',
31 30 body=u'notification_1',
32 31 recipients=[cur_user])
33 32 self.Session().commit()
34 33 response = self.app.get(url('notifications'))
35 self.assertTrue(u'test_notification_1' in response.body)
34 response.mustcontain(u'test_notification_1')
36 35
37 36 # def test_index_as_xml(self):
38 37 # response = self.app.get(url('formatted_notifications', format='xml'))
39 38 #
40 39 # def test_create(self):
41 40 # response = self.app.post(url('notifications'))
42 41 #
43 42 # def test_new(self):
44 43 # response = self.app.get(url('new_notification'))
45 44 #
46 45 # def test_new_as_xml(self):
47 46 # response = self.app.get(url('formatted_new_notification', format='xml'))
48 47 #
49 48 # def test_update(self):
50 49 # response = self.app.put(url('notification', notification_id=1))
51 50 #
52 51 # def test_update_browser_fakeout(self):
53 52 # response = self.app.post(url('notification', notification_id=1), params=dict(_method='put'))
54 53
55 54 def test_delete(self):
56 55 self.log_user()
57 56 cur_user = self._get_logged_user()
58 57
59 58 u1 = UserModel().create_or_update(username='u1', password='qweqwe',
60 59 email='u1@rhodecode.org',
61 60 firstname='u1', lastname='u1')
62 61 u2 = UserModel().create_or_update(username='u2', password='qweqwe',
63 62 email='u2@rhodecode.org',
64 63 firstname='u2', lastname='u2')
65 64
66 65 # make notifications
67 66 notification = NotificationModel().create(created_by=cur_user,
68 67 subject=u'test',
69 68 body=u'hi there',
70 69 recipients=[cur_user, u1, u2])
71 70 self.Session().commit()
72 71 u1 = User.get(u1.user_id)
73 72 u2 = User.get(u2.user_id)
74 73
75 74 # check DB
76 75 get_notif = lambda un: [x.notification for x in un]
77 76 self.assertEqual(get_notif(cur_user.notifications), [notification])
78 77 self.assertEqual(get_notif(u1.notifications), [notification])
79 78 self.assertEqual(get_notif(u2.notifications), [notification])
80 79 cur_usr_id = cur_user.user_id
81 80
82 81 response = self.app.delete(url('notification',
83 82 notification_id=
84 83 notification.notification_id))
85 84 self.assertEqual(response.body, 'ok')
86 85
87 86 cur_user = User.get(cur_usr_id)
88 87 self.assertEqual(cur_user.notifications, [])
89 88
90 89 def test_show(self):
91 90 self.log_user()
92 91 cur_user = self._get_logged_user()
93 92 u1 = UserModel().create_or_update(username='u1', password='qweqwe',
94 93 email='u1@rhodecode.org',
95 94 firstname='u1', lastname='u1')
96 95 u2 = UserModel().create_or_update(username='u2', password='qweqwe',
97 96 email='u2@rhodecode.org',
98 97 firstname='u2', lastname='u2')
99 98
100 99 notification = NotificationModel().create(created_by=cur_user,
101 100 subject=u'test',
102 101 body=u'hi there',
103 102 recipients=[cur_user, u1, u2])
104 103
105 104 response = self.app.get(url('notification',
106 105 notification_id=notification.notification_id))
@@ -1,265 +1,264 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 from rhodecode.lib.auth import get_crypt_password, check_password
4 4 from rhodecode.model.db import User, RhodeCodeSetting, Repository
5 5 from rhodecode.tests import *
6 6 from rhodecode.lib import helpers as h
7 7 from rhodecode.model.user import UserModel
8 8 from rhodecode.model.scm import ScmModel
9 9
10 10
11 11 class TestAdminSettingsController(TestController):
12 12
13 13 def test_index(self):
14 14 response = self.app.get(url('admin_settings'))
15 15 # Test response...
16 16
17 17 def test_index_as_xml(self):
18 18 response = self.app.get(url('formatted_admin_settings', format='xml'))
19 19
20 20 def test_create(self):
21 21 response = self.app.post(url('admin_settings'))
22 22
23 23 def test_new(self):
24 24 response = self.app.get(url('admin_new_setting'))
25 25
26 26 def test_new_as_xml(self):
27 27 response = self.app.get(url('formatted_admin_new_setting', format='xml'))
28 28
29 29 def test_update(self):
30 30 response = self.app.put(url('admin_setting', setting_id=1))
31 31
32 32 def test_update_browser_fakeout(self):
33 33 response = self.app.post(url('admin_setting', setting_id=1), params=dict(_method='put'))
34 34
35 35 def test_delete(self):
36 36 response = self.app.delete(url('admin_setting', setting_id=1))
37 37
38 38 def test_delete_browser_fakeout(self):
39 39 response = self.app.post(url('admin_setting', setting_id=1), params=dict(_method='delete'))
40 40
41 41 def test_show(self):
42 42 response = self.app.get(url('admin_setting', setting_id=1))
43 43
44 44 def test_show_as_xml(self):
45 45 response = self.app.get(url('formatted_admin_setting', setting_id=1, format='xml'))
46 46
47 47 def test_edit(self):
48 48 response = self.app.get(url('admin_edit_setting', setting_id=1))
49 49
50 50 def test_edit_as_xml(self):
51 51 response = self.app.get(url('formatted_admin_edit_setting',
52 52 setting_id=1, format='xml'))
53 53
54 54 def test_ga_code_active(self):
55 55 self.log_user()
56 56 old_title = 'RhodeCode'
57 57 old_realm = 'RhodeCode authentication'
58 58 new_ga_code = 'ga-test-123456789'
59 59 response = self.app.post(url('admin_setting', setting_id='global'),
60 60 params=dict(
61 61 _method='put',
62 62 rhodecode_title=old_title,
63 63 rhodecode_realm=old_realm,
64 64 rhodecode_ga_code=new_ga_code
65 65 ))
66 66
67 67 self.checkSessionFlash(response, 'Updated application settings')
68 68
69 69 self.assertEqual(RhodeCodeSetting
70 70 .get_app_settings()['rhodecode_ga_code'], new_ga_code)
71 71
72 72 response = response.follow()
73 73 response.mustcontain("""_gaq.push(['_setAccount', '%s']);""" % new_ga_code)
74 74
75 75 def test_ga_code_inactive(self):
76 76 self.log_user()
77 77 old_title = 'RhodeCode'
78 78 old_realm = 'RhodeCode authentication'
79 79 new_ga_code = ''
80 80 response = self.app.post(url('admin_setting', setting_id='global'),
81 81 params=dict(
82 82 _method='put',
83 83 rhodecode_title=old_title,
84 84 rhodecode_realm=old_realm,
85 85 rhodecode_ga_code=new_ga_code
86 86 ))
87 87
88 88 self.checkSessionFlash(response, 'Updated application settings')
89 89 self.assertEqual(RhodeCodeSetting
90 90 .get_app_settings()['rhodecode_ga_code'], new_ga_code)
91 91
92 92 response = response.follow()
93 self.assertFalse("""_gaq.push(['_setAccount', '%s']);""" % new_ga_code
94 in response.body)
93 response.mustcontain(no=["_gaq.push(['_setAccount', '%s']);" % new_ga_code])
95 94
96 95 def test_title_change(self):
97 96 self.log_user()
98 97 old_title = 'RhodeCode'
99 98 new_title = old_title + '_changed'
100 99 old_realm = 'RhodeCode authentication'
101 100
102 101 for new_title in ['Changed', 'Ε»Γ³Ε‚wik', old_title]:
103 102 response = self.app.post(url('admin_setting', setting_id='global'),
104 103 params=dict(
105 104 _method='put',
106 105 rhodecode_title=new_title,
107 106 rhodecode_realm=old_realm,
108 107 rhodecode_ga_code=''
109 108 ))
110 109
111 110 self.checkSessionFlash(response, 'Updated application settings')
112 111 self.assertEqual(RhodeCodeSetting
113 112 .get_app_settings()['rhodecode_title'],
114 113 new_title.decode('utf-8'))
115 114
116 115 response = response.follow()
117 116 response.mustcontain("""<h1><a href="/">%s</a></h1>""" % new_title)
118 117
119 118 def test_my_account(self):
120 119 self.log_user()
121 120 response = self.app.get(url('admin_settings_my_account'))
122 121
123 self.assertTrue('value="test_admin' in response.body)
122 response.mustcontain('value="test_admin')
124 123
125 124 @parameterized.expand([('firstname', 'new_username'),
126 125 ('lastname', 'new_username'),
127 126 ('admin', True),
128 127 ('admin', False),
129 128 ('ldap_dn', 'test'),
130 129 ('ldap_dn', None),
131 130 ('active', False),
132 131 ('active', True),
133 132 ('email', 'some@email.com'),
134 133 ])
135 134 def test_my_account_update(self, name, expected):
136 135 uname = 'testme'
137 136 usr = UserModel().create_or_update(username=uname, password='qweqwe',
138 137 email='testme@rhodecod.org')
139 138 self.Session().commit()
140 139 params = usr.get_api_data()
141 140 user_id = usr.user_id
142 141 self.log_user(username=uname, password='qweqwe')
143 142 params.update({name: expected})
144 143 params.update({'password_confirmation': ''})
145 144 params.update({'new_password': ''})
146 145
147 146 try:
148 147 response = self.app.put(url('admin_settings_my_account_update',
149 148 id=user_id), params)
150 149
151 150 self.checkSessionFlash(response,
152 151 'Your account was updated successfully')
153 152
154 153 updated_user = User.get_by_username(uname)
155 154 updated_params = updated_user.get_api_data()
156 155 updated_params.update({'password_confirmation': ''})
157 156 updated_params.update({'new_password': ''})
158 157
159 158 params['last_login'] = updated_params['last_login']
160 159 if name == 'email':
161 160 params['emails'] = [expected]
162 161 if name == 'ldap_dn':
163 162 #cannot update this via form
164 163 params['ldap_dn'] = None
165 164 if name == 'active':
166 165 #my account cannot deactivate account
167 166 params['active'] = True
168 167 if name == 'admin':
169 168 #my account cannot make you an admin !
170 169 params['admin'] = False
171 170
172 171 self.assertEqual(params, updated_params)
173 172
174 173 finally:
175 174 UserModel().delete('testme')
176 175
177 176 def test_my_account_update_err_email_exists(self):
178 177 self.log_user()
179 178
180 179 new_email = 'test_regular@mail.com' # already exisitn email
181 180 response = self.app.put(url('admin_settings_my_account_update'),
182 181 params=dict(
183 182 username='test_admin',
184 183 new_password='test12',
185 184 password_confirmation='test122',
186 185 firstname='NewName',
187 186 lastname='NewLastname',
188 187 email=new_email,)
189 188 )
190 189
191 190 response.mustcontain('This e-mail address is already taken')
192 191
193 192 def test_my_account_update_err(self):
194 193 self.log_user('test_regular2', 'test12')
195 194
196 195 new_email = 'newmail.pl'
197 196 response = self.app.post(url('admin_settings_my_account_update'),
198 197 params=dict(
199 198 _method='put',
200 199 username='test_admin',
201 200 new_password='test12',
202 201 password_confirmation='test122',
203 202 firstname='NewName',
204 203 lastname='NewLastname',
205 204 email=new_email,)
206 205 )
207 206
208 207 response.mustcontain('An email address must contain a single @')
209 208 from rhodecode.model import validators
210 209 msg = validators.ValidUsername(edit=False,
211 210 old_data={})._messages['username_exists']
212 211 msg = h.html_escape(msg % {'username': 'test_admin'})
213 212 response.mustcontain(u"%s" % msg)
214 213
215 214 def test_set_repo_fork_has_no_self_id(self):
216 215 self.log_user()
217 216 repo = Repository.get_by_repo_name(HG_REPO)
218 217 response = self.app.get(url('edit_repo', repo_name=HG_REPO))
219 218 opt = """<option value="%s">vcs_test_git</option>""" % repo.repo_id
220 assert opt not in response.body
219 response.mustcontain(no=[opt])
221 220
222 221 def test_set_fork_of_repo(self):
223 222 self.log_user()
224 223 repo = Repository.get_by_repo_name(HG_REPO)
225 224 repo2 = Repository.get_by_repo_name(GIT_REPO)
226 225 response = self.app.put(url('repo_as_fork', repo_name=HG_REPO),
227 226 params=dict(
228 227 id_fork_of=repo2.repo_id
229 228 ))
230 229 repo = Repository.get_by_repo_name(HG_REPO)
231 230 repo2 = Repository.get_by_repo_name(GIT_REPO)
232 231 self.checkSessionFlash(response,
233 232 'Marked repo %s as fork of %s' % (repo.repo_name, repo2.repo_name))
234 233
235 234 assert repo.fork == repo2
236 235 response = response.follow()
237 236 # check if given repo is selected
238 237
239 238 opt = """<option value="%s" selected="selected">%s</option>""" % (
240 239 repo2.repo_id, repo2.repo_name)
241 240 response.mustcontain(opt)
242 241
243 242 # clean session flash
244 243 #response = self.app.get(url('edit_repo', repo_name=HG_REPO))
245 244
246 245 ## mark it as None
247 246 response = self.app.put(url('repo_as_fork', repo_name=HG_REPO),
248 247 params=dict(
249 248 id_fork_of=None
250 249 ))
251 250 repo = Repository.get_by_repo_name(HG_REPO)
252 251 repo2 = Repository.get_by_repo_name(GIT_REPO)
253 252 self.checkSessionFlash(response,
254 253 'Marked repo %s as fork of %s' % (repo.repo_name, "Nothing"))
255 254 assert repo.fork == None
256 255
257 256 def test_set_fork_of_same_repo(self):
258 257 self.log_user()
259 258 repo = Repository.get_by_repo_name(HG_REPO)
260 259 response = self.app.put(url('repo_as_fork', repo_name=HG_REPO),
261 260 params=dict(
262 261 id_fork_of=repo.repo_id
263 262 ))
264 263 self.checkSessionFlash(response,
265 264 'An error occurred during this operation')
@@ -1,13 +1,24 b''
1 1 from rhodecode.tests import *
2 2
3
3 4 class TestFollowersController(TestController):
4 5
5 def test_index(self):
6 def test_index_hg(self):
6 7 self.log_user()
7 8 repo_name = HG_REPO
8 9 response = self.app.get(url(controller='followers',
9 10 action='followers',
10 11 repo_name=repo_name))
11 12
12 self.assertTrue("""test_admin""" in response.body)
13 self.assertTrue("""Started following""" in response.body)
13 response.mustcontain("""test_admin""")
14 response.mustcontain("""Started following""")
15
16 def test_index_git(self):
17 self.log_user()
18 repo_name = GIT_REPO
19 response = self.app.get(url(controller='followers',
20 action='followers',
21 repo_name=repo_name))
22
23 response.mustcontain("""test_admin""")
24 response.mustcontain("""Started following""")
@@ -1,176 +1,176 b''
1 1 from rhodecode.tests import *
2 2
3 3 from rhodecode.model.db import Repository
4 4 from rhodecode.model.repo import RepoModel
5 5 from rhodecode.model.user import UserModel
6 6 from rhodecode.model.meta import Session
7 7
8 8
9 9 class TestForksController(TestController):
10 10
11 11 def setUp(self):
12 12 self.username = u'forkuser'
13 13 self.password = u'qweqwe'
14 14 self.u1 = UserModel().create_or_update(
15 15 username=self.username, password=self.password,
16 16 email=u'fork_king@rhodecode.org', firstname=u'u1', lastname=u'u1'
17 17 )
18 18 Session().commit()
19 19
20 20 def tearDown(self):
21 21 Session().delete(self.u1)
22 22 Session().commit()
23 23
24 24 def test_index(self):
25 25 self.log_user()
26 26 repo_name = HG_REPO
27 27 response = self.app.get(url(controller='forks', action='forks',
28 28 repo_name=repo_name))
29 29
30 self.assertTrue("""There are no forks yet""" in response.body)
30 response.mustcontain("""There are no forks yet""")
31 31
32 32 def test_no_permissions_to_fork(self):
33 33 usr = self.log_user(TEST_USER_REGULAR_LOGIN,
34 34 TEST_USER_REGULAR_PASS)['user_id']
35 35 user_model = UserModel()
36 36 user_model.revoke_perm(usr, 'hg.fork.repository')
37 37 user_model.grant_perm(usr, 'hg.fork.none')
38 38 u = UserModel().get(usr)
39 39 u.inherit_default_permissions = False
40 40 Session().commit()
41 41 # try create a fork
42 42 repo_name = HG_REPO
43 43 self.app.post(url(controller='forks', action='fork_create',
44 44 repo_name=repo_name), {}, status=403)
45 45
46 46 def test_index_with_fork_hg(self):
47 47 self.log_user()
48 48
49 49 # create a fork
50 50 fork_name = HG_FORK
51 51 description = 'fork of vcs test'
52 52 repo_name = HG_REPO
53 53 org_repo = Repository.get_by_repo_name(repo_name)
54 54 response = self.app.post(url(controller='forks',
55 55 action='fork_create',
56 56 repo_name=repo_name),
57 57 {'repo_name': fork_name,
58 58 'repo_group': '',
59 59 'fork_parent_id': org_repo.repo_id,
60 60 'repo_type': 'hg',
61 61 'description': description,
62 62 'private': 'False',
63 63 'landing_rev': 'tip'})
64 64
65 65 response = self.app.get(url(controller='forks', action='forks',
66 66 repo_name=repo_name))
67 67
68 68 response.mustcontain(
69 69 """<a href="/%s">%s</a>""" % (fork_name, fork_name)
70 70 )
71 71
72 72 #remove this fork
73 73 response = self.app.delete(url('repo', repo_name=fork_name))
74 74
75 75 def test_index_with_fork_git(self):
76 76 self.log_user()
77 77
78 78 # create a fork
79 79 fork_name = GIT_FORK
80 80 description = 'fork of vcs test'
81 81 repo_name = GIT_REPO
82 82 org_repo = Repository.get_by_repo_name(repo_name)
83 83 response = self.app.post(url(controller='forks',
84 84 action='fork_create',
85 85 repo_name=repo_name),
86 86 {'repo_name': fork_name,
87 87 'repo_group': '',
88 88 'fork_parent_id': org_repo.repo_id,
89 89 'repo_type': 'git',
90 90 'description': description,
91 91 'private': 'False',
92 92 'landing_rev': 'tip'})
93 93
94 94 response = self.app.get(url(controller='forks', action='forks',
95 95 repo_name=repo_name))
96 96
97 97 response.mustcontain(
98 98 """<a href="/%s">%s</a>""" % (fork_name, fork_name)
99 99 )
100 100
101 101 #remove this fork
102 102 response = self.app.delete(url('repo', repo_name=fork_name))
103 103
104 104 def test_z_fork_create(self):
105 105 self.log_user()
106 106 fork_name = HG_FORK
107 107 description = 'fork of vcs test'
108 108 repo_name = HG_REPO
109 109 org_repo = Repository.get_by_repo_name(repo_name)
110 110 response = self.app.post(url(controller='forks', action='fork_create',
111 111 repo_name=repo_name),
112 112 {'repo_name': fork_name,
113 113 'repo_group':'',
114 114 'fork_parent_id':org_repo.repo_id,
115 115 'repo_type':'hg',
116 116 'description':description,
117 117 'private':'False',
118 118 'landing_rev': 'tip'})
119 119
120 120 #test if we have a message that fork is ok
121 121 self.checkSessionFlash(response,
122 122 'Forked repository %s as <a href="/%s">%s</a>'
123 123 % (repo_name, fork_name, fork_name))
124 124
125 125 #test if the fork was created in the database
126 126 fork_repo = Session().query(Repository)\
127 127 .filter(Repository.repo_name == fork_name).one()
128 128
129 129 self.assertEqual(fork_repo.repo_name, fork_name)
130 130 self.assertEqual(fork_repo.fork.repo_name, repo_name)
131 131
132 132 #test if fork is visible in the list ?
133 133 response = response.follow()
134 134
135 135 response = self.app.get(url(controller='summary', action='index',
136 136 repo_name=fork_name))
137 137
138 self.assertTrue('Fork of %s' % repo_name in response.body)
138 response.mustcontain('Fork of %s' % repo_name)
139 139
140 140 def test_zz_fork_permission_page(self):
141 141 usr = self.log_user(self.username, self.password)['user_id']
142 142 repo_name = HG_REPO
143 143
144 144 forks = Session().query(Repository)\
145 145 .filter(Repository.fork_id != None)\
146 146 .all()
147 147 self.assertEqual(1, len(forks))
148 148
149 149 # set read permissions for this
150 150 RepoModel().grant_user_permission(repo=forks[0],
151 151 user=usr,
152 152 perm='repository.read')
153 153 Session().commit()
154 154
155 155 response = self.app.get(url(controller='forks', action='forks',
156 156 repo_name=repo_name))
157 157
158 158 response.mustcontain('<div style="padding:5px 3px 3px 42px;">fork of vcs test</div>')
159 159
160 160 def test_zzz_fork_permission_page(self):
161 161 usr = self.log_user(self.username, self.password)['user_id']
162 162 repo_name = HG_REPO
163 163
164 164 forks = Session().query(Repository)\
165 165 .filter(Repository.fork_id != None)\
166 166 .all()
167 167 self.assertEqual(1, len(forks))
168 168
169 169 # set none
170 170 RepoModel().grant_user_permission(repo=forks[0],
171 171 user=usr, perm='repository.none')
172 172 Session().commit()
173 173 # fork shouldn't be there
174 174 response = self.app.get(url(controller='forks', action='forks',
175 175 repo_name=repo_name))
176 176 response.mustcontain('There are no forks yet')
@@ -1,114 +1,112 b''
1 1 import os
2 2 from rhodecode.tests import *
3 from nose.plugins.skip import SkipTest
4 3
5 4
6 5 class TestSearchController(TestController):
7 6
8 7 def test_index(self):
9 8 self.log_user()
10 9 response = self.app.get(url(controller='search', action='index'))
11 10
12 self.assertTrue('class="small" id="q" name="q" type="text"' in
13 response.body)
11 response.mustcontain('class="small" id="q" name="q" type="text"')
14 12 # Test response...
15 13
16 14 def test_empty_search(self):
17 15 if os.path.isdir(self.index_location):
18 16 raise SkipTest('skipped due to existing index')
19 17 else:
20 18 self.log_user()
21 19 response = self.app.get(url(controller='search', action='index'),
22 20 {'q': HG_REPO})
23 self.assertTrue('There is no index to search in. '
24 'Please run whoosh indexer' in response.body)
21 response.mustcontain('There is no index to search in. '
22 'Please run whoosh indexer')
25 23
26 24 def test_normal_search(self):
27 25 self.log_user()
28 26 response = self.app.get(url(controller='search', action='index'),
29 27 {'q': 'def repo'})
30 28 response.mustcontain('39 results')
31 29
32 30 def test_repo_search(self):
33 31 self.log_user()
34 32 response = self.app.get(url(controller='search', action='index'),
35 33 {'q': 'repository:%s def test' % HG_REPO})
36 34
37 35 response.mustcontain('4 results')
38 36
39 37 def test_search_last(self):
40 38 self.log_user()
41 39 response = self.app.get(url(controller='search', action='index'),
42 40 {'q': 'last:t', 'type': 'commit'})
43 41
44 42 response.mustcontain('2 results')
45 43
46 44 def test_search_commit_message(self):
47 45 self.log_user()
48 46 response = self.app.get(url(controller='search', action='index'),
49 47 {'q': 'bother to ask where to fetch repo during tests',
50 48 'type': 'commit'})
51 49
52 50 response.mustcontain('2 results')
53 51 response.mustcontain('a00c1b6f5d7a6ae678fd553a8b81d92367f7ecf1')
54 52 response.mustcontain('c6eb379775c578a95dad8ddab53f963b80894850')
55 53
56 54 def test_search_commit_message_hg_repo(self):
57 55 self.log_user()
58 56 response = self.app.get(url(controller='search', action='index',
59 57 repo_name=HG_REPO),
60 58 {'q': 'bother to ask where to fetch repo during tests',
61 59 'type': 'commit'})
62 60
63 61 response.mustcontain('1 results')
64 62 response.mustcontain('a00c1b6f5d7a6ae678fd553a8b81d92367f7ecf1')
65 63
66 64 def test_search_commit_changed_file(self):
67 65 self.log_user()
68 66 response = self.app.get(url(controller='search', action='index'),
69 67 {'q': 'changed:tests/utils.py',
70 68 'type': 'commit'})
71 69
72 70 response.mustcontain('20 results')
73 71
74 72 def test_search_commit_changed_files_get_commit(self):
75 73 self.log_user()
76 74 response = self.app.get(url(controller='search', action='index'),
77 75 {'q': 'changed:vcs/utils/lazy.py',
78 76 'type': 'commit'})
79 77
80 78 response.mustcontain('7 results')
81 79 response.mustcontain('36e0fc9d2808c5022a24f49d6658330383ed8666')
82 80 response.mustcontain('af182745859d779f17336241a0815d15166ae1ee')
83 81 response.mustcontain('17438a11f72b93f56d0e08e7d1fa79a378578a82')
84 82 response.mustcontain('33fa3223355104431402a888fa77a4e9956feb3e')
85 83 response.mustcontain('d1f898326327e20524fe22417c22d71064fe54a1')
86 84 response.mustcontain('fe568b4081755c12abf6ba673ba777fc02a415f3')
87 85 response.mustcontain('bafe786f0d8c2ff7da5c1dcfcfa577de0b5e92f1')
88 86
89 87 def test_search_commit_added_file(self):
90 88 self.log_user()
91 89 response = self.app.get(url(controller='search', action='index'),
92 90 {'q': 'added:README.rst',
93 91 'type': 'commit'})
94 92
95 93 response.mustcontain('2 results')
96 94 #HG
97 95 response.mustcontain('3803844fdbd3b711175fc3da9bdacfcd6d29a6fb')
98 96 #GIT
99 97 response.mustcontain('ff7ca51e58c505fec0dd2491de52c622bb7a806b')
100 98
101 99 def test_search_author(self):
102 100 self.log_user()
103 101 response = self.app.get(url(controller='search', action='index'),
104 102 {'q': 'author:marcin@python-blog.com raw_id:b986218ba1c9b0d6a259fac9b050b1724ed8e545',
105 103 'type': 'commit'})
106 104
107 105 response.mustcontain('1 results')
108 106
109 107 def test_search_file_name(self):
110 108 self.log_user()
111 109 response = self.app.get(url(controller='search', action='index'),
112 110 {'q': 'README.rst', 'type': 'path'})
113 111
114 112 response.mustcontain('2 results')
General Comments 0
You need to be logged in to leave comments. Login now