Show More
@@ -1,202 +1,208 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 | ||
|
10 | nosetests -x - fail on first error | |
|
11 | nosetests rhodecode.tests.functional.test_admin_settings:TestSettingsController.test_my_account | |
|
12 | nosetests --pdb --pdb-failures | |
|
13 | nosetests --with-coverage --cover-package=rhodecode.model.validators rhodecode.tests.test_validators | |
|
14 | ||
|
15 | optional FLAGS: | |
|
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 | |
|
18 | ||
|
9 | 19 | """ |
|
10 | 20 | import os |
|
11 | 21 | import time |
|
12 | 22 | import logging |
|
13 | 23 | import datetime |
|
14 | 24 | import hashlib |
|
15 | 25 | import tempfile |
|
16 | 26 | from os.path import join as jn |
|
17 | 27 | |
|
18 | 28 | from unittest import TestCase |
|
19 | 29 | from tempfile import _RandomNameSequence |
|
20 | 30 | |
|
21 | 31 | from paste.deploy import loadapp |
|
22 | 32 | from paste.script.appinstall import SetupCommand |
|
23 | 33 | from pylons import config, url |
|
24 | 34 | from routes.util import URLGenerator |
|
25 | 35 | from webtest import TestApp |
|
26 | 36 | |
|
27 | 37 | from rhodecode import is_windows |
|
28 | 38 | from rhodecode.model.meta import Session |
|
29 | 39 | from rhodecode.model.db import User |
|
30 | 40 | from rhodecode.tests.nose_parametrized import parameterized |
|
31 | 41 | |
|
32 | 42 | import pylons.test |
|
33 | 43 | from rhodecode.lib.utils2 import safe_unicode, safe_str |
|
34 | 44 | |
|
35 | 45 | |
|
36 | 46 | os.environ['TZ'] = 'UTC' |
|
37 | 47 | if not is_windows: |
|
38 | 48 | time.tzset() |
|
39 | 49 | |
|
40 | 50 | log = logging.getLogger(__name__) |
|
41 | 51 | |
|
42 | 52 | __all__ = [ |
|
43 | 53 | 'parameterized', 'environ', 'url', 'get_new_dir', 'TestController', |
|
44 | 54 | 'TESTS_TMP_PATH', 'HG_REPO', 'GIT_REPO', 'NEW_HG_REPO', 'NEW_GIT_REPO', |
|
45 | 55 | 'HG_FORK', 'GIT_FORK', 'TEST_USER_ADMIN_LOGIN', 'TEST_USER_ADMIN_PASS', |
|
46 | 56 | 'TEST_USER_REGULAR_LOGIN', 'TEST_USER_REGULAR_PASS', |
|
47 | 57 | 'TEST_USER_REGULAR_EMAIL', 'TEST_USER_REGULAR2_LOGIN', |
|
48 | 58 | 'TEST_USER_REGULAR2_PASS', 'TEST_USER_REGULAR2_EMAIL', 'TEST_HG_REPO', |
|
49 | 59 | 'TEST_HG_REPO_CLONE', 'TEST_HG_REPO_PULL', 'TEST_GIT_REPO', |
|
50 | 60 | 'TEST_GIT_REPO_CLONE', 'TEST_GIT_REPO_PULL', 'HG_REMOTE_REPO', |
|
51 | 61 | 'GIT_REMOTE_REPO', 'SCM_TESTS', '_get_repo_create_params', |
|
52 | 62 | '_get_group_create_params' |
|
53 | 63 | ] |
|
54 | 64 | |
|
55 | 65 | # Invoke websetup with the current config file |
|
56 | 66 | # SetupCommand('setup-app').run([config_file]) |
|
57 | 67 | |
|
58 | ##RUNNING DESIRED TESTS | |
|
59 | # nosetests -x rhodecode.tests.functional.test_admin_settings:TestSettingsController.test_my_account | |
|
60 | # nosetests --pdb --pdb-failures | |
|
61 | # nosetests --with-coverage --cover-package=rhodecode.model.validators rhodecode.tests.test_validators | |
|
62 | 68 | environ = {} |
|
63 | 69 | |
|
64 | 70 | #SOME GLOBALS FOR TESTS |
|
65 | 71 | |
|
66 | 72 | TESTS_TMP_PATH = jn('/', 'tmp', 'rc_test_%s' % _RandomNameSequence().next()) |
|
67 | 73 | TEST_USER_ADMIN_LOGIN = 'test_admin' |
|
68 | 74 | TEST_USER_ADMIN_PASS = 'test12' |
|
69 | 75 | TEST_USER_ADMIN_EMAIL = 'test_admin@mail.com' |
|
70 | 76 | |
|
71 | 77 | TEST_USER_REGULAR_LOGIN = 'test_regular' |
|
72 | 78 | TEST_USER_REGULAR_PASS = 'test12' |
|
73 | 79 | TEST_USER_REGULAR_EMAIL = 'test_regular@mail.com' |
|
74 | 80 | |
|
75 | 81 | TEST_USER_REGULAR2_LOGIN = 'test_regular2' |
|
76 | 82 | TEST_USER_REGULAR2_PASS = 'test12' |
|
77 | 83 | TEST_USER_REGULAR2_EMAIL = 'test_regular2@mail.com' |
|
78 | 84 | |
|
79 | 85 | HG_REPO = 'vcs_test_hg' |
|
80 | 86 | GIT_REPO = 'vcs_test_git' |
|
81 | 87 | |
|
82 | 88 | NEW_HG_REPO = 'vcs_test_hg_new' |
|
83 | 89 | NEW_GIT_REPO = 'vcs_test_git_new' |
|
84 | 90 | |
|
85 | 91 | HG_FORK = 'vcs_test_hg_fork' |
|
86 | 92 | GIT_FORK = 'vcs_test_git_fork' |
|
87 | 93 | |
|
88 | 94 | ## VCS |
|
89 | 95 | SCM_TESTS = ['hg', 'git'] |
|
90 | 96 | uniq_suffix = str(int(time.mktime(datetime.datetime.now().timetuple()))) |
|
91 | 97 | |
|
92 | 98 | GIT_REMOTE_REPO = 'git://github.com/codeinn/vcs.git' |
|
93 | 99 | |
|
94 | 100 | TEST_GIT_REPO = jn(TESTS_TMP_PATH, GIT_REPO) |
|
95 | 101 | TEST_GIT_REPO_CLONE = jn(TESTS_TMP_PATH, 'vcsgitclone%s' % uniq_suffix) |
|
96 | 102 | TEST_GIT_REPO_PULL = jn(TESTS_TMP_PATH, 'vcsgitpull%s' % uniq_suffix) |
|
97 | 103 | |
|
98 | 104 | |
|
99 | 105 | HG_REMOTE_REPO = 'http://bitbucket.org/marcinkuzminski/vcs' |
|
100 | 106 | |
|
101 | 107 | TEST_HG_REPO = jn(TESTS_TMP_PATH, HG_REPO) |
|
102 | 108 | TEST_HG_REPO_CLONE = jn(TESTS_TMP_PATH, 'vcshgclone%s' % uniq_suffix) |
|
103 | 109 | TEST_HG_REPO_PULL = jn(TESTS_TMP_PATH, 'vcshgpull%s' % uniq_suffix) |
|
104 | 110 | |
|
105 | 111 | TEST_DIR = tempfile.gettempdir() |
|
106 | 112 | TEST_REPO_PREFIX = 'vcs-test' |
|
107 | 113 | |
|
108 | 114 | # cached repos if any ! |
|
109 | 115 | # comment out to get some other repos from bb or github |
|
110 | 116 | GIT_REMOTE_REPO = jn(TESTS_TMP_PATH, GIT_REPO) |
|
111 | 117 | HG_REMOTE_REPO = jn(TESTS_TMP_PATH, HG_REPO) |
|
112 | 118 | |
|
113 | 119 | |
|
114 | 120 | def get_new_dir(title): |
|
115 | 121 | """ |
|
116 | 122 | Returns always new directory path. |
|
117 | 123 | """ |
|
118 | 124 | from rhodecode.tests.vcs.utils import get_normalized_path |
|
119 | 125 | name = TEST_REPO_PREFIX |
|
120 | 126 | if title: |
|
121 | 127 | name = '-'.join((name, title)) |
|
122 | 128 | hex = hashlib.sha1(str(time.time())).hexdigest() |
|
123 | 129 | name = '-'.join((name, hex)) |
|
124 | 130 | path = os.path.join(TEST_DIR, name) |
|
125 | 131 | return get_normalized_path(path) |
|
126 | 132 | |
|
127 | 133 | |
|
128 | 134 | class TestController(TestCase): |
|
129 | 135 | |
|
130 | 136 | def __init__(self, *args, **kwargs): |
|
131 | 137 | wsgiapp = pylons.test.pylonsapp |
|
132 | 138 | config = wsgiapp.config |
|
133 | 139 | |
|
134 | 140 | self.app = TestApp(wsgiapp) |
|
135 | 141 | url._push_object(URLGenerator(config['routes.map'], environ)) |
|
136 | 142 | self.Session = Session |
|
137 | 143 | self.index_location = config['app_conf']['index_dir'] |
|
138 | 144 | TestCase.__init__(self, *args, **kwargs) |
|
139 | 145 | |
|
140 | 146 | def log_user(self, username=TEST_USER_ADMIN_LOGIN, |
|
141 | 147 | password=TEST_USER_ADMIN_PASS): |
|
142 | 148 | self._logged_username = username |
|
143 | 149 | response = self.app.post(url(controller='login', action='index'), |
|
144 | 150 | {'username': username, |
|
145 | 151 | 'password': password}) |
|
146 | 152 | |
|
147 | 153 | if 'invalid user name' in response.body: |
|
148 | 154 | self.fail('could not login using %s %s' % (username, password)) |
|
149 | 155 | |
|
150 | 156 | self.assertEqual(response.status, '302 Found') |
|
151 | 157 | ses = response.session['rhodecode_user'] |
|
152 | 158 | self.assertEqual(ses.get('username'), username) |
|
153 | 159 | response = response.follow() |
|
154 | 160 | self.assertEqual(ses.get('is_authenticated'), True) |
|
155 | 161 | |
|
156 | 162 | return response.session['rhodecode_user'] |
|
157 | 163 | |
|
158 | 164 | def _get_logged_user(self): |
|
159 | 165 | return User.get_by_username(self._logged_username) |
|
160 | 166 | |
|
161 | 167 | def checkSessionFlash(self, response, msg): |
|
162 | 168 | self.assertTrue('flash' in response.session, |
|
163 | 169 | msg='Response session:%r have no flash' |
|
164 | 170 | % response.session) |
|
165 | 171 | if not msg in response.session['flash'][0][1]: |
|
166 | 172 | msg = u'msg `%s` not found in session flash: got `%s` instead' % ( |
|
167 | 173 | msg, response.session['flash'][0][1]) |
|
168 | 174 | self.fail(safe_str(msg)) |
|
169 | 175 | |
|
170 | 176 | |
|
171 | 177 | ## HELPERS ## |
|
172 | 178 | |
|
173 | 179 | def _get_repo_create_params(**custom): |
|
174 | 180 | defs = { |
|
175 | 181 | 'repo_name': None, |
|
176 | 182 | 'repo_type': 'hg', |
|
177 | 183 | 'clone_uri': '', |
|
178 | 184 | 'repo_group': '', |
|
179 | 185 | 'repo_description': 'DESC', |
|
180 | 186 | 'repo_private': False, |
|
181 | 187 | 'repo_landing_rev': 'tip' |
|
182 | 188 | } |
|
183 | 189 | defs.update(custom) |
|
184 | 190 | if 'repo_name_full' not in custom: |
|
185 | 191 | defs.update({'repo_name_full': defs['repo_name']}) |
|
186 | 192 | |
|
187 | 193 | return defs |
|
188 | 194 | |
|
189 | 195 | |
|
190 | 196 | def _get_group_create_params(**custom): |
|
191 | 197 | defs = dict( |
|
192 | 198 | group_name=None, |
|
193 | 199 | group_description='DESC', |
|
194 | 200 | group_parent_id=None, |
|
195 | 201 | perms_updates=[], |
|
196 | 202 | perms_new=[], |
|
197 | 203 | enable_locking=False, |
|
198 | 204 | recursive=False |
|
199 | 205 | ) |
|
200 | 206 | defs.update(custom) |
|
201 | 207 | |
|
202 | 208 | return defs |
General Comments 0
You need to be logged in to leave comments.
Login now