modernize unit tests

This commit is contained in:
Jan Dittberner 2010-05-03 20:18:23 +02:00
parent 2d12dd6a28
commit f5f5e366ea
4 changed files with 46 additions and 23 deletions

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# DDPortfolio service tests package # DDPortfolio service tests package
# Copyright (c) 2009 Jan Dittberner <jan@dittberner.info> # Copyright © 2009, 2010 Jan Dittberner <jan@dittberner.info>
# #
# This file is part of DDPortfolio service. # This file is part of DDPortfolio service.
# #
@ -34,29 +34,26 @@ import os
import sys import sys
from unittest import TestCase from unittest import TestCase
import pkg_resources
import paste.fixture
import paste.script.appinstall
from paste.deploy import loadapp from paste.deploy import loadapp
from routes import url_for from paste.script.appinstall import SetupCommand
from pylons import url
from routes.util import URLGenerator
from webtest import TestApp
__all__ = ['url_for', 'TestController'] import pylons.test
here_dir = os.path.dirname(os.path.abspath(__file__)) __all__ = ['environ', 'url', 'TestController']
conf_dir = os.path.dirname(os.path.dirname(here_dir))
sys.path.insert(0, conf_dir) # Invoke websetup with the current config file
pkg_resources.working_set.add_entry(conf_dir) SetupCommand('setup-app').run([pylons.test.pylonsapp.config['__file__']])
pkg_resources.require('Paste')
pkg_resources.require('PasteScript')
test_file = os.path.join(conf_dir, 'test.ini') environ = {}
cmd = paste.script.appinstall.SetupCommand('setup-app')
cmd.run([test_file])
class TestController(TestCase): class TestController(TestCase):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
wsgiapp = loadapp('config:test.ini', relative_to=conf_dir) wsgiapp = pylons.test.pylonsapp
self.app = paste.fixture.TestApp(wsgiapp) config = wsgiapp.config
self.app = TestApp(wsgiapp)
url._push_object(URLGenerator(config['routes.map'], environ))
TestCase.__init__(self, *args, **kwargs) TestCase.__init__(self, *args, **kwargs)

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# DDPortfolio service DdportfolioController test # DDPortfolio service DdportfolioController test
# Copyright (c) 2009 Jan Dittberner <jan@dittberner.info> # Copyright © 2009, 2010 Jan Dittberner <jan@dittberner.info>
# #
# This file is part of DDPortfolio service. # This file is part of DDPortfolio service.
# #
@ -20,10 +20,11 @@
# License along with this program. If not, see # License along with this program. If not, see
# <http://www.gnu.org/licenses/>. # <http://www.gnu.org/licenses/>.
# #
from ddportfolioservice.tests import * from ddportfolioservice.tests import TestController, url
class TestDdportfolioController(TestController): class TestDdportfolioController(TestController):
def test_index(self): def test_index(self):
response = self.app.get(url_for(controller='ddportfolio', action='index')) response = self.app.get(url(controller='ddportfolio', action='index'))
# Test response... # Test response...

View file

@ -1,7 +1,29 @@
from ddportfolioservice.tests import * # -*- python -*-
# -*- coding: utf-8 -*-
#
# DDPortfolio service DdportfolioController test
# Copyright © 2009, 2010 Jan Dittberner <jan@dittberner.info>
#
# This file is part of DDPortfolio service.
#
# DDPortfolio service is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# DDPortfolio service is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public
# License along with this program. If not, see
# <http://www.gnu.org/licenses/>.
#
from ddportfolioservice.tests import TestController, url
class TestShowformscriptsController(TestController): class TestShowformscriptsController(TestController):
def test_index(self): def test_index(self):
response = self.app.get(url_for(controller='showformscripts', action='index')) response = self.app.get(url(controller='showformscripts', action='index'))
# Test response... # Test response...

View file

@ -25,6 +25,7 @@ import logging
from paste.deploy import appconfig from paste.deploy import appconfig
from pylons import config from pylons import config
import pylons.test
from ddportfolioservice.config.environment import load_environment from ddportfolioservice.config.environment import load_environment
@ -33,4 +34,6 @@ log = logging.getLogger(__name__)
def setup_config(command, filename, section, vars): def setup_config(command, filename, section, vars):
"""Place any commands to setup ddportfolioservice here""" """Place any commands to setup ddportfolioservice here"""
conf = appconfig('config:' + filename) conf = appconfig('config:' + filename)
load_environment(conf.global_conf, conf.local_conf)
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)