Mercurial > kallithea
comparison rhodecode/tests/__init__.py @ 2031:82a88013a3fd
merge 1.3 into stable
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 26 Feb 2012 17:25:09 +0200 |
parents | 95c3e33ef32e cf51bbfb120e |
children | a437a986d399 |
comparison
equal
deleted
inserted
replaced
2005:ab0e122b38a7 | 2031:82a88013a3fd |
---|---|
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 import os | 10 import os |
11 import time | |
12 import logging | |
11 from os.path import join as jn | 13 from os.path import join as jn |
12 | 14 |
13 from unittest import TestCase | 15 from unittest import TestCase |
16 from tempfile import _RandomNameSequence | |
14 | 17 |
15 from paste.deploy import loadapp | 18 from paste.deploy import loadapp |
16 from paste.script.appinstall import SetupCommand | 19 from paste.script.appinstall import SetupCommand |
17 from pylons import config, url | 20 from pylons import config, url |
18 from routes.util import URLGenerator | 21 from routes.util import URLGenerator |
19 from webtest import TestApp | 22 from webtest import TestApp |
20 | 23 |
21 from rhodecode.model import meta | 24 from rhodecode.model.meta import Session |
22 import logging | 25 from rhodecode.model.db import User |
23 | 26 |
27 import pylons.test | |
28 | |
29 os.environ['TZ'] = 'UTC' | |
30 time.tzset() | |
24 | 31 |
25 log = logging.getLogger(__name__) | 32 log = logging.getLogger(__name__) |
26 | 33 |
27 import pylons.test | 34 __all__ = [ |
28 | 35 'environ', 'url', 'TestController', 'TESTS_TMP_PATH', 'HG_REPO', |
29 __all__ = ['environ', 'url', 'TestController', 'TESTS_TMP_PATH', 'HG_REPO', | 36 'GIT_REPO', 'NEW_HG_REPO', 'NEW_GIT_REPO', 'HG_FORK', 'GIT_FORK', |
30 'GIT_REPO', 'NEW_HG_REPO', 'NEW_GIT_REPO', 'HG_FORK', 'GIT_FORK', | 37 'TEST_USER_ADMIN_LOGIN', 'TEST_USER_REGULAR_LOGIN', 'TEST_USER_REGULAR_PASS', |
31 'TEST_USER_ADMIN_LOGIN', 'TEST_USER_ADMIN_PASS' ] | 38 'TEST_USER_REGULAR_EMAIL', 'TEST_USER_REGULAR2_LOGIN', |
39 'TEST_USER_REGULAR2_PASS', 'TEST_USER_REGULAR2_EMAIL' | |
40 ] | |
32 | 41 |
33 # Invoke websetup with the current config file | 42 # Invoke websetup with the current config file |
34 #SetupCommand('setup-app').run([config_file]) | 43 # SetupCommand('setup-app').run([config_file]) |
35 | 44 |
36 ##RUNNING DESIRED TESTS | 45 ##RUNNING DESIRED TESTS |
37 # nosetests -x rhodecode.tests.functional.test_admin_settings:TestSettingsController.test_my_account | 46 # nosetests -x rhodecode.tests.functional.test_admin_settings:TestSettingsController.test_my_account |
38 # nosetests --pdb --pdb-failures | 47 # nosetests --pdb --pdb-failures |
39 environ = {} | 48 environ = {} |
40 | 49 |
41 #SOME GLOBALS FOR TESTS | 50 #SOME GLOBALS FOR TESTS |
42 from tempfile import _RandomNameSequence | 51 |
43 TESTS_TMP_PATH = jn('/', 'tmp', 'rc_test_%s' % _RandomNameSequence().next()) | 52 TESTS_TMP_PATH = jn('/', 'tmp', 'rc_test_%s' % _RandomNameSequence().next()) |
44 TEST_USER_ADMIN_LOGIN = 'test_admin' | 53 TEST_USER_ADMIN_LOGIN = 'test_admin' |
45 TEST_USER_ADMIN_PASS = 'test12' | 54 TEST_USER_ADMIN_PASS = 'test12' |
55 TEST_USER_ADMIN_EMAIL = 'test_admin@mail.com' | |
56 | |
57 TEST_USER_REGULAR_LOGIN = 'test_regular' | |
58 TEST_USER_REGULAR_PASS = 'test12' | |
59 TEST_USER_REGULAR_EMAIL = 'test_regular@mail.com' | |
60 | |
61 TEST_USER_REGULAR2_LOGIN = 'test_regular2' | |
62 TEST_USER_REGULAR2_PASS = 'test12' | |
63 TEST_USER_REGULAR2_EMAIL = 'test_regular2@mail.com' | |
64 | |
46 HG_REPO = 'vcs_test_hg' | 65 HG_REPO = 'vcs_test_hg' |
47 GIT_REPO = 'vcs_test_git' | 66 GIT_REPO = 'vcs_test_git' |
48 | 67 |
49 NEW_HG_REPO = 'vcs_test_hg_new' | 68 NEW_HG_REPO = 'vcs_test_hg_new' |
50 NEW_GIT_REPO = 'vcs_test_git_new' | 69 NEW_GIT_REPO = 'vcs_test_git_new' |
58 wsgiapp = pylons.test.pylonsapp | 77 wsgiapp = pylons.test.pylonsapp |
59 config = wsgiapp.config | 78 config = wsgiapp.config |
60 | 79 |
61 self.app = TestApp(wsgiapp) | 80 self.app = TestApp(wsgiapp) |
62 url._push_object(URLGenerator(config['routes.map'], environ)) | 81 url._push_object(URLGenerator(config['routes.map'], environ)) |
63 self.sa = meta.Session | 82 self.Session = Session |
64 self.index_location = config['app_conf']['index_dir'] | 83 self.index_location = config['app_conf']['index_dir'] |
65 TestCase.__init__(self, *args, **kwargs) | 84 TestCase.__init__(self, *args, **kwargs) |
66 | 85 |
67 def log_user(self, username=TEST_USER_ADMIN_LOGIN, | 86 def log_user(self, username=TEST_USER_ADMIN_LOGIN, |
68 password=TEST_USER_ADMIN_PASS): | 87 password=TEST_USER_ADMIN_PASS): |
88 self._logged_username = username | |
69 response = self.app.post(url(controller='login', action='index'), | 89 response = self.app.post(url(controller='login', action='index'), |
70 {'username':username, | 90 {'username':username, |
71 'password':password}) | 91 'password':password}) |
72 | 92 |
73 if 'invalid user name' in response.body: | 93 if 'invalid user name' in response.body: |
74 self.fail('could not login using %s %s' % (username, password)) | 94 self.fail('could not login using %s %s' % (username, password)) |
75 | 95 |
76 self.assertEqual(response.status, '302 Found') | 96 self.assertEqual(response.status, '302 Found') |
77 self.assertEqual(response.session['rhodecode_user'].username, username) | 97 ses = response.session['rhodecode_user'] |
78 return response.follow() | 98 self.assertEqual(ses.get('username'), username) |
99 response = response.follow() | |
100 self.assertEqual(ses.get('is_authenticated'), True) | |
101 | |
102 return response.session['rhodecode_user'] | |
103 | |
104 def _get_logged_user(self): | |
105 return User.get_by_username(self._logged_username) | |
79 | 106 |
80 def checkSessionFlash(self, response, msg): | 107 def checkSessionFlash(self, response, msg): |
81 self.assertTrue('flash' in response.session) | 108 self.assertTrue('flash' in response.session) |
82 self.assertTrue(msg in response.session['flash'][0][1]) | 109 self.assertTrue(msg in response.session['flash'][0][1]) |
83 |