annotate pylons_app/tests/__init__.py @ 469:e94f4e54dc03

tests fix, put vcs testing tarball
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 11 Sep 2010 03:35:33 +0200
parents cbe777be5b8c
children 6b934c9607e7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
1 """Pylons application test package
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
2
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
3 This package assumes the Pylons environment is already loaded, such as
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
4 when this script is imported from the `nosetests --with-pylons=test.ini`
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
5 command.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
6
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
7 This module initializes the application via ``websetup`` (`paster
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
8 setup-app`) and provides the base testing objects.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
9 """
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
10 from unittest import TestCase
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
11
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
12 from paste.deploy import loadapp
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
13 from paste.script.appinstall import SetupCommand
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
14 from pylons import config, url
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
15 from routes.util import URLGenerator
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
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
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
19 import pylons.test
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
20
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
21 __all__ = ['environ', 'url', 'TestController']
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
22
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
23 # Invoke websetup with the current config file
459
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 0
diff changeset
24 SetupCommand('setup-app').run([pylons.test.pylonsapp.config['__file__']])
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
25
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
26 environ = {}
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
27
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
28 class TestController(TestCase):
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
29
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
30 def __init__(self, *args, **kwargs):
459
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 0
diff changeset
31 wsgiapp = pylons.test.pylonsapp
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 0
diff changeset
32 config = wsgiapp.config
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
33 self.app = TestApp(wsgiapp)
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
34 url._push_object(URLGenerator(config['routes.map'], environ))
463
a03250279b15 test for register page
Marcin Kuzminski <marcin@python-works.com>
parents: 459
diff changeset
35 self.sa = meta.Session
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
36 TestCase.__init__(self, *args, **kwargs)
459
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 0
diff changeset
37
464
cbe777be5b8c some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents: 463
diff changeset
38
cbe777be5b8c some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents: 463
diff changeset
39 def log_user(self):
cbe777be5b8c some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents: 463
diff changeset
40 response = self.app.post(url(controller='login', action='index'),
cbe777be5b8c some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents: 463
diff changeset
41 {'username':'test_admin',
cbe777be5b8c some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents: 463
diff changeset
42 'password':'test'})
cbe777be5b8c some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents: 463
diff changeset
43 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
44 assert response.session['hg_app_user'].username == 'test_admin', 'wrong logged in user'
cbe777be5b8c some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents: 463
diff changeset
45 return response.follow()