Changeset - d4e1692e25ab
[Not reviewed]
default
0 2 0
domruf - 10 years ago 2016-05-02 22:41:51
dominikruf@gmail.com
tests: introduce webserver fixture

To be used for tests that actually access a running web server - especially to
make the manual vcs tests less manual.
2 files changed with 17 insertions and 2 deletions:
0 comments (0 inline, 0 general)
dev_requirements.txt
Show inline comments
 
babel >= 0.9.6, < 2.4
 
waitress >= 0.8.8, < 1.0
 
pytest ~= 3.0
 
pytest-runner
 
pytest-sugar>=0.7.0
 
pytest-catchlog
 
pytest-localserver
 
mock
 
sphinx
 
webtest < 3
kallithea/tests/conftest.py
Show inline comments
 
import os
 
import sys
 
import logging
 
import pkg_resources
 

	
 
from paste.deploy import loadwsgi
 
from routes.util import URLGenerator
 
import pytest
 
from pytest_localserver.http import WSGIServer
 

	
 
import pytest
 
from kallithea.controllers.root import RootController
 
from kallithea.lib.utils import repo2db_mapper
 
from kallithea.model.user import UserModel
 
from kallithea.model.meta import Session
 
from kallithea.model.db import Setting, User, UserIpMap
 
from kallithea.model.scm import ScmModel
 
from kallithea.tests.base import invalidate_all_caches, TEST_USER_REGULAR_LOGIN, TESTS_TMP_PATH
 
from kallithea.tests.base import invalidate_all_caches, TEST_USER_REGULAR_LOGIN, TESTS_TMP_PATH, \
 
    TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS
 
import kallithea.tests.base # FIXME: needed for setting testapp instance!!!
 

	
 
from tg.util.webtest import test_context
 

	
 
def pytest_configure():
 
    path = os.getcwd()
 
    sys.path.insert(0, path)
 
    pkg_resources.working_set.add_entry(path)
 

	
 
    # Disable INFO logging of test database creation, restore with NOTSET
 
    logging.disable(logging.INFO)
 

	
 
@@ -133,12 +135,24 @@ def test_context_fixture(app_fixture):
 
    executed inside the test context, that method is not possible.
 
    Even if there is no such setup code, the fixture may reduce code complexity
 
    if the entire test needs to run inside a test context.
 

	
 
    To apply this fixture (like any other fixture) to all test methods of a
 
    class, use the following class decorator:
 
        @pytest.mark.usefixtures("test_context_fixture")
 
        class TestFoo(TestController):
 
            ...
 
    """
 
    with test_context(app_fixture):
 
        yield
 

	
 

	
 
@pytest.yield_fixture(scope="session")
 
def webserver():
 
    """Start web server while tests are running.
 
    Useful for debugging and necessary for vcs operation tests."""
 
    server = WSGIServer(application=kallithea.tests.base.testapp)
 
    server.start()
 

	
 
    yield server
 

	
 
    server.stop()
0 comments (0 inline, 0 general)