Mercurial > kallithea
annotate rhodecode/tests/__init__.py @ 1887:3246fcce2402
backported fixes for statistics from beta branch, try to fix issue #271
- version bump
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 12 Jan 2012 06:21:48 +0200 |
parents | 95c3e33ef32e |
children | 82a88013a3fd |
rev | line source |
---|---|
0 | 1 """Pylons application test package |
2 | |
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` | |
5 command. | |
6 | |
7 This module initializes the application via ``websetup`` (`paster | |
8 setup-app`) and provides the base testing objects. | |
9 """ | |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1047
diff
changeset
|
10 import os |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1047
diff
changeset
|
11 from os.path import join as jn |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1047
diff
changeset
|
12 |
0 | 13 from unittest import TestCase |
14 | |
15 from paste.deploy import loadapp | |
16 from paste.script.appinstall import SetupCommand | |
17 from pylons import config, url | |
18 from routes.util import URLGenerator | |
19 from webtest import TestApp | |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1047
diff
changeset
|
20 |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
535
diff
changeset
|
21 from rhodecode.model import meta |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
469
diff
changeset
|
22 import logging |
491
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
483
diff
changeset
|
23 |
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
483
diff
changeset
|
24 |
688
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
548
diff
changeset
|
25 log = logging.getLogger(__name__) |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
469
diff
changeset
|
26 |
0 | 27 import pylons.test |
28 | |
688
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
548
diff
changeset
|
29 __all__ = ['environ', 'url', 'TestController', 'TESTS_TMP_PATH', 'HG_REPO', |
1418 | 30 'GIT_REPO', 'NEW_HG_REPO', 'NEW_GIT_REPO', 'HG_FORK', 'GIT_FORK', |
1416
df04752daa64
test env update
Marcin Kuzminski <marcin@python-works.com>
parents:
1397
diff
changeset
|
31 'TEST_USER_ADMIN_LOGIN', 'TEST_USER_ADMIN_PASS' ] |
0 | 32 |
33 # Invoke websetup with the current config file | |
491
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
483
diff
changeset
|
34 #SetupCommand('setup-app').run([config_file]) |
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
483
diff
changeset
|
35 |
535
72778dda34cf
some fixups in cache, added fallback and cache invalidation when key not found in cached repos list,
Marcin Kuzminski <marcin@python-works.com>
parents:
534
diff
changeset
|
36 ##RUNNING DESIRED TESTS |
1416
df04752daa64
test env update
Marcin Kuzminski <marcin@python-works.com>
parents:
1397
diff
changeset
|
37 # nosetests -x rhodecode.tests.functional.test_admin_settings:TestSettingsController.test_my_account |
df04752daa64
test env update
Marcin Kuzminski <marcin@python-works.com>
parents:
1397
diff
changeset
|
38 # nosetests --pdb --pdb-failures |
0 | 39 environ = {} |
40 | |
688
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
548
diff
changeset
|
41 #SOME GLOBALS FOR TESTS |
1397
dc960653f8d2
Added new random directory for each test to be better sandboxed
Marcin Kuzminski <marcin@python-works.com>
parents:
1389
diff
changeset
|
42 from tempfile import _RandomNameSequence |
dc960653f8d2
Added new random directory for each test to be better sandboxed
Marcin Kuzminski <marcin@python-works.com>
parents:
1389
diff
changeset
|
43 TESTS_TMP_PATH = jn('/', 'tmp', 'rc_test_%s' % _RandomNameSequence().next()) |
1416
df04752daa64
test env update
Marcin Kuzminski <marcin@python-works.com>
parents:
1397
diff
changeset
|
44 TEST_USER_ADMIN_LOGIN = 'test_admin' |
df04752daa64
test env update
Marcin Kuzminski <marcin@python-works.com>
parents:
1397
diff
changeset
|
45 TEST_USER_ADMIN_PASS = 'test12' |
688
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
548
diff
changeset
|
46 HG_REPO = 'vcs_test_hg' |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
548
diff
changeset
|
47 GIT_REPO = 'vcs_test_git' |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
548
diff
changeset
|
48 |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
548
diff
changeset
|
49 NEW_HG_REPO = 'vcs_test_hg_new' |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
548
diff
changeset
|
50 NEW_GIT_REPO = 'vcs_test_git_new' |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
548
diff
changeset
|
51 |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
548
diff
changeset
|
52 HG_FORK = 'vcs_test_hg_fork' |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
548
diff
changeset
|
53 GIT_FORK = 'vcs_test_git_fork' |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
548
diff
changeset
|
54 |
0 | 55 class TestController(TestCase): |
56 | |
57 def __init__(self, *args, **kwargs): | |
459
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
0
diff
changeset
|
58 wsgiapp = pylons.test.pylonsapp |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
0
diff
changeset
|
59 config = wsgiapp.config |
688
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
548
diff
changeset
|
60 |
0 | 61 self.app = TestApp(wsgiapp) |
62 url._push_object(URLGenerator(config['routes.map'], environ)) | |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
459
diff
changeset
|
63 self.sa = meta.Session |
688
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
548
diff
changeset
|
64 self.index_location = config['app_conf']['index_dir'] |
0 | 65 TestCase.__init__(self, *args, **kwargs) |
688
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
548
diff
changeset
|
66 |
1416
df04752daa64
test env update
Marcin Kuzminski <marcin@python-works.com>
parents:
1397
diff
changeset
|
67 def log_user(self, username=TEST_USER_ADMIN_LOGIN, |
df04752daa64
test env update
Marcin Kuzminski <marcin@python-works.com>
parents:
1397
diff
changeset
|
68 password=TEST_USER_ADMIN_PASS): |
464
cbe777be5b8c
some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
69 response = self.app.post(url(controller='login', action='index'), |
491
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
483
diff
changeset
|
70 {'username':username, |
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
483
diff
changeset
|
71 'password':password}) |
688
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
548
diff
changeset
|
72 |
534
12c976209b2e
fixed test for new version 100% test are ok
Marcin Kuzminski <marcin@python-works.com>
parents:
533
diff
changeset
|
73 if 'invalid user name' in response.body: |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1047
diff
changeset
|
74 self.fail('could not login using %s %s' % (username, password)) |
688
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
548
diff
changeset
|
75 |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1047
diff
changeset
|
76 self.assertEqual(response.status, '302 Found') |
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1047
diff
changeset
|
77 self.assertEqual(response.session['rhodecode_user'].username, username) |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
469
diff
changeset
|
78 return response.follow() |
1382
c310e1e1e757
Added CheckSessionFlash into init.
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
79 |
c310e1e1e757
Added CheckSessionFlash into init.
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
80 def checkSessionFlash(self, response, msg): |
c310e1e1e757
Added CheckSessionFlash into init.
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
81 self.assertTrue('flash' in response.session) |
c310e1e1e757
Added CheckSessionFlash into init.
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
82 self.assertTrue(msg in response.session['flash'][0][1]) |
c310e1e1e757
Added CheckSessionFlash into init.
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
83 |