##// END OF EJS Templates
fixed tests import
marcink -
r1389:04edf762 beta
parent child Browse files
Show More
@@ -1,82 +1,81 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 import os
10 import os
11 from os.path import join as jn
11 from os.path import join as jn
12
12
13 from unittest import TestCase
13 from unittest import TestCase
14
14
15 from paste.deploy import loadapp
15 from paste.deploy import loadapp
16 from paste.script.appinstall import SetupCommand
16 from paste.script.appinstall import SetupCommand
17 from pylons import config, url
17 from pylons import config, url
18 from routes.util import URLGenerator
18 from routes.util import URLGenerator
19 from webtest import TestApp
19 from webtest import TestApp
20
20
21 from rhodecode.model import meta
21 from rhodecode.model import meta
22 import logging
22 import logging
23
23
24
24
25 log = logging.getLogger(__name__)
25 log = logging.getLogger(__name__)
26
26
27 import pylons.test
27 import pylons.test
28
28
29 __all__ = ['environ', 'url', 'TestController', 'TESTS_TMP_PATH', 'HG_REPO',
29 __all__ = ['environ', 'url', 'TestController', 'TESTS_TMP_PATH', 'HG_REPO',
30 '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', ]
31 'checkSessionFlash' ]
32
31
33 # Invoke websetup with the current config file
32 # Invoke websetup with the current config file
34 #SetupCommand('setup-app').run([config_file])
33 #SetupCommand('setup-app').run([config_file])
35
34
36 ##RUNNING DESIRED TESTS
35 ##RUNNING DESIRED TESTS
37 #nosetests -x rhodecode.tests.functional.test_admin_settings:TestSettingsController.test_my_account
36 #nosetests -x rhodecode.tests.functional.test_admin_settings:TestSettingsController.test_my_account
38
37
39 environ = {}
38 environ = {}
40
39
41 #SOME GLOBALS FOR TESTS
40 #SOME GLOBALS FOR TESTS
42 TESTS_TMP_PATH = jn('/', 'tmp')
41 TESTS_TMP_PATH = jn('/', 'tmp')
43
42
44 HG_REPO = 'vcs_test_hg'
43 HG_REPO = 'vcs_test_hg'
45 GIT_REPO = 'vcs_test_git'
44 GIT_REPO = 'vcs_test_git'
46
45
47 NEW_HG_REPO = 'vcs_test_hg_new'
46 NEW_HG_REPO = 'vcs_test_hg_new'
48 NEW_GIT_REPO = 'vcs_test_git_new'
47 NEW_GIT_REPO = 'vcs_test_git_new'
49
48
50 HG_FORK = 'vcs_test_hg_fork'
49 HG_FORK = 'vcs_test_hg_fork'
51 GIT_FORK = 'vcs_test_git_fork'
50 GIT_FORK = 'vcs_test_git_fork'
52
51
53 class TestController(TestCase):
52 class TestController(TestCase):
54
53
55 def __init__(self, *args, **kwargs):
54 def __init__(self, *args, **kwargs):
56 wsgiapp = pylons.test.pylonsapp
55 wsgiapp = pylons.test.pylonsapp
57 config = wsgiapp.config
56 config = wsgiapp.config
58
57
59 self.app = TestApp(wsgiapp)
58 self.app = TestApp(wsgiapp)
60 url._push_object(URLGenerator(config['routes.map'], environ))
59 url._push_object(URLGenerator(config['routes.map'], environ))
61 self.sa = meta.Session
60 self.sa = meta.Session
62 self.index_location = config['app_conf']['index_dir']
61 self.index_location = config['app_conf']['index_dir']
63 TestCase.__init__(self, *args, **kwargs)
62 TestCase.__init__(self, *args, **kwargs)
64
63
65 def log_user(self, username='test_admin', password='test12'):
64 def log_user(self, username='test_admin', password='test12'):
66 response = self.app.post(url(controller='login', action='index'),
65 response = self.app.post(url(controller='login', action='index'),
67 {'username':username,
66 {'username':username,
68 'password':password})
67 'password':password})
69
68
70 if 'invalid user name' in response.body:
69 if 'invalid user name' in response.body:
71 self.fail('could not login using %s %s' % (username, password))
70 self.fail('could not login using %s %s' % (username, password))
72
71
73 self.assertEqual(response.status, '302 Found')
72 self.assertEqual(response.status, '302 Found')
74 self.assertEqual(response.session['rhodecode_user'].username, username)
73 self.assertEqual(response.session['rhodecode_user'].username, username)
75 return response.follow()
74 return response.follow()
76
75
77
76
78
77
79 def checkSessionFlash(self, response, msg):
78 def checkSessionFlash(self, response, msg):
80 self.assertTrue('flash' in response.session)
79 self.assertTrue('flash' in response.session)
81 self.assertTrue(msg in response.session['flash'][0][1])
80 self.assertTrue(msg in response.session['flash'][0][1])
82
81
General Comments 0
You need to be logged in to leave comments. Login now