Mercurial > kallithea
annotate pylons_app/tests/__init__.py @ 473:6b934c9607e7 celery
Improved testing scenarios. Made test env creator
Fixed hg_model error message
some other tweeks and fixes
Models fixe for uniq email, and removed some extra not needed imports from model main module
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 13 Sep 2010 01:23:58 +0200 |
parents | e94f4e54dc03 |
children | a9e50dce3081 |
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 """ | |
10 from unittest import TestCase | |
11 | |
12 from paste.deploy import loadapp | |
13 from paste.script.appinstall import SetupCommand | |
14 from pylons import config, url | |
15 from routes.util import URLGenerator | |
16 from webtest import TestApp | |
459
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
0
diff
changeset
|
17 import os |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
459
diff
changeset
|
18 from pylons_app.model import meta |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
469
diff
changeset
|
19 import logging |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
469
diff
changeset
|
20 log = logging.getLogger(__name__) |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
469
diff
changeset
|
21 |
0 | 22 import pylons.test |
23 | |
24 __all__ = ['environ', 'url', 'TestController'] | |
25 | |
26 # Invoke websetup with the current config file | |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
469
diff
changeset
|
27 #SetupCommand('setup-app').run([pylons.test.pylonsapp.config['__file__']]) |
0 | 28 |
29 environ = {} | |
30 | |
31 class TestController(TestCase): | |
32 | |
33 def __init__(self, *args, **kwargs): | |
459
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
0
diff
changeset
|
34 wsgiapp = pylons.test.pylonsapp |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
0
diff
changeset
|
35 config = wsgiapp.config |
0 | 36 self.app = TestApp(wsgiapp) |
37 url._push_object(URLGenerator(config['routes.map'], environ)) | |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
459
diff
changeset
|
38 self.sa = meta.Session |
0 | 39 TestCase.__init__(self, *args, **kwargs) |
459
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
0
diff
changeset
|
40 |
464
cbe777be5b8c
some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
41 |
cbe777be5b8c
some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
42 def log_user(self): |
cbe777be5b8c
some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
43 response = self.app.post(url(controller='login', action='index'), |
cbe777be5b8c
some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
44 {'username':'test_admin', |
cbe777be5b8c
some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
45 'password':'test'}) |
cbe777be5b8c
some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
46 assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status |
cbe777be5b8c
some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
47 assert response.session['hg_app_user'].username == 'test_admin', 'wrong logged in user' |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
469
diff
changeset
|
48 return response.follow() |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
469
diff
changeset
|
49 |