Commit 0bfecb16 authored by Pascal's avatar Pascal
Browse files

allow to restrict test to single branch

parent 9847bd45
......@@ -10,6 +10,19 @@ from requests import Session
from urllib.parse import urljoin
from configparser import ConfigParser
def onlybranch(branch):
def inner(func):
def wrapped(*args, **kwargs):
if pytest.current_branch != branch:
pytest.skip()
return func(*args, **kwargs)
return wrapped
return inner
def pytest_configure(config):
pytest.current_branch = None
pytest.onlybranch = onlybranch
def pytest_addoption(parser):
parser.addoption("--project", action="store")
parser.addini('project', 'path or git repo of the lektor test project')
......@@ -63,6 +76,8 @@ def pytest_generate_tests(metafunc):
@pytest.fixture(scope='session')
def lektorproject(project_path, branchname, packages):
pytest.current_branch = branchname
output_path = tempfile.mkdtemp()
print('OUT: ', output_path)
......@@ -79,7 +94,7 @@ def lektorproject(project_path, branchname, packages):
git_clone(p, packages_path)
print('OUTPUT PATH = %s'%output_path)
yield output_path
yield { 'path' : output_path, 'branch' : branchname }
try:
shutil.rmtree(output_path)
......@@ -107,9 +122,10 @@ class BaseUrlSession(requests.Session):
@pytest.fixture(scope='module')
def server(lektorproject, port):
path = lektorproject['path']
servercmd = 'lektor server -p %d'%port
print("[START LEKTOR SERVER]")
server = subprocess.Popen(["lektor", "server", "-p %d"%port], cwd = lektorproject)
server = subprocess.Popen(["lektor", "server", "-p %d"%port], cwd = path)
server.base_url = 'http://localhost:%d'%port
time.sleep(5)
#while True:
......@@ -170,11 +186,11 @@ def draft(server):
### API
@pytest.fixture(scope='module')
def project(lektorproject, branchname):
if branchname != 'lektor-admin-extra':
pytest.skip('already tested')
def project(lektorproject):
#if lektorproject['branch'] != 'lektor-admin-extra':
# pytest.skip('already tested')
from lektor.project import Project
return Project.from_path(lektorproject)
return Project.from_path(lektorproject['path'])
@pytest.fixture(scope='module')
def env(request, project):
......
......@@ -4,19 +4,22 @@ import os
@pytest.mark.project
def test_project(lektorproject):
print(lektorproject)
for (dirpath, dirnames, files) in os.walk(lektorproject):
path = lektorproject['path']
for (dirpath, dirnames, files) in os.walk(path):
#dirnames[:] = [ d for d in dirnames if d[0] != '.' ]
dirnames[:] = [ d for d in dirnames if d[0] != '.' ]
print(dirnames, files)
assert os.path.exists(os.path.join(lektorproject,'packages/lektor-admin-extra'))
assert os.path.exists(os.path.join(path,'packages/lektor-admin-extra'))
@pytest.mark.api
@pytest.onlybranch('lektor-admin-extra')
def test_webclient_index(webclient):
rv = webclient.get('/')
print(rv.data)
assert b'<body>' in rv.data
@pytest.mark.api
@pytest.onlybranch('lektor-admin-extra')
def test_webclient_buttons(webclient):
rv = webclient.get('/')
assert b'auth-button-div' in rv.data
......@@ -25,6 +28,7 @@ def test_webclient_buttons(webclient):
# add route dynamically
@pytest.mark.api
@pytest.onlybranch('lektor-admin-extra')
def test_webclient_add_button(env, webclient):
from lektor.pluginsystem import get_plugin
plugin = get_plugin('admin-extra', env)
......@@ -40,6 +44,7 @@ def test_webclient_add_button(env, webclient):
assert b'zorglub' in rv.data
@pytest.mark.api
@pytest.onlybranch('lektor-admin-extra')
def test_webclient_add_serve_button(env, webclient):
from lektor.pluginsystem import get_plugin
plugin = get_plugin('admin-extra', env)
......@@ -54,6 +59,7 @@ def test_webclient_add_serve_button(env, webclient):
assert b'albatros' not in rv.data
@pytest.mark.api
@pytest.onlybranch('lektor-admin-extra')
def test_webclient_add_dash_button(env, webclient):
from lektor.pluginsystem import get_plugin
plugin = get_plugin('admin-extra', env)
......@@ -88,3 +94,9 @@ def test_help_page(anonymous):
rv = anonymous.get('/admin-pages/help', timeout=0.1)
assert 'Aide' in rv.text
@pytest.mark.server
def test_config_button(anonymous):
rv = anonymous.get('/', timeout=0.1)
assert 'tooltip' in rv.text
rv = anonymous.get('/admin', timeout=0.1)
assert 'tooltip' in rv.text
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment