Mercurial > kallithea
annotate pylons_app/tests/__init__.py @ 483:a9e50dce3081 celery
Removed config names from whoosh and celery,
celery is now configured based on the config name it's using
on celeryconfig. And whoosh uses it's own logger configured just for whoosh
Test creates a fresh whoosh index now, for more accurate checks
fixed tests for searching
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 17 Sep 2010 22:54:30 +0200 |
parents | 6b934c9607e7 |
children | fefffd6fd5f4 |
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 |
483
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
19 from pylons_app.lib.indexers import IDX_LOCATION |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
469
diff
changeset
|
20 import logging |
483
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
21 import shutil |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
469
diff
changeset
|
22 log = logging.getLogger(__name__) |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
469
diff
changeset
|
23 |
0 | 24 import pylons.test |
25 | |
26 __all__ = ['environ', 'url', 'TestController'] | |
27 | |
28 # 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
|
29 #SetupCommand('setup-app').run([pylons.test.pylonsapp.config['__file__']]) |
483
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
30 def create_index(repo_location, full_index): |
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
31 from pylons_app.lib.indexers import daemon |
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
32 from pylons_app.lib.indexers.daemon import WhooshIndexingDaemon |
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
33 from pylons_app.lib.indexers.pidlock import DaemonLock, LockHeld |
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
34 |
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
35 try: |
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
36 l = DaemonLock() |
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
37 WhooshIndexingDaemon(repo_location=repo_location)\ |
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
38 .run(full_index=full_index) |
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
39 l.release() |
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
40 except LockHeld: |
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
41 pass |
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
42 |
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
43 if os.path.exists(IDX_LOCATION): |
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
44 shutil.rmtree(IDX_LOCATION) |
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
45 |
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
46 create_index('/tmp/*', True) |
0 | 47 |
48 environ = {} | |
49 | |
50 class TestController(TestCase): | |
51 | |
52 def __init__(self, *args, **kwargs): | |
459
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
0
diff
changeset
|
53 wsgiapp = pylons.test.pylonsapp |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
0
diff
changeset
|
54 config = wsgiapp.config |
0 | 55 self.app = TestApp(wsgiapp) |
56 url._push_object(URLGenerator(config['routes.map'], environ)) | |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
459
diff
changeset
|
57 self.sa = meta.Session |
483
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
58 |
0 | 59 TestCase.__init__(self, *args, **kwargs) |
459
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
0
diff
changeset
|
60 |
464
cbe777be5b8c
some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
61 |
cbe777be5b8c
some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
62 def log_user(self): |
cbe777be5b8c
some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
63 response = self.app.post(url(controller='login', action='index'), |
cbe777be5b8c
some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
64 {'username':'test_admin', |
cbe777be5b8c
some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
65 'password':'test'}) |
cbe777be5b8c
some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
66 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
|
67 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
|
68 return response.follow() |
483
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
69 |
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
70 |