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