Created
September 27, 2012 22:02
-
-
Save moschlar/3796718 to your computer and use it in GitHub Desktop.
Badass speedup of simple tg site tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
This test module will run setUp and tearDown only *once* for all test cases in this module. | |
This is very convenient for users who want to just test multiple urls whether they are reachable and respond with the correct http response code. | |
""" | |
import logging | |
log = logging.getLogger(__name__) | |
from os import path | |
import sys | |
from tg import config | |
from paste.deploy import loadapp | |
from paste.script.appinstall import SetupCommand | |
from webtest import TestApp | |
from tg2test.tests import teardown_db | |
from tg2test import model | |
app = None | |
def setUpModule(): | |
log.debug('Setting up module') | |
# Loading the application: | |
conf_dir = config.here | |
wsgiapp = loadapp('config:test.ini#main_without_authn', | |
relative_to=conf_dir) | |
global app | |
app = TestApp(wsgiapp) | |
# Setting it up: | |
test_file = path.join(conf_dir, 'test.ini') | |
cmd = SetupCommand('setup-app') | |
cmd.run([test_file]) | |
def tearDownModule(): | |
log.debug('Tearing down module') | |
model.DBSession.remove() | |
teardown_db() | |
class TestClass(object): | |
def _test_url(self, url): | |
app.get(url) | |
def test_urls(self): | |
for url in ('/', '/about', '/contact'): | |
yield self._test_url, url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment