tests: update root directory tests to use fixtures
This commit is contained in:
parent
3484ae5341
commit
1eda23197b
|
@ -1,7 +1,5 @@
|
||||||
import shutil
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from quixote import cleanup
|
from quixote import get_request
|
||||||
|
|
||||||
import wcs.forms.root
|
import wcs.forms.root
|
||||||
from wcs.categories import Category
|
from wcs.categories import Category
|
||||||
|
@ -9,16 +7,11 @@ from wcs.formdef import FormDef
|
||||||
from wcs.qommon import sessions
|
from wcs.qommon import sessions
|
||||||
from wcs.qommon.http_request import HTTPRequest
|
from wcs.qommon.http_request import HTTPRequest
|
||||||
|
|
||||||
from .utilities import create_temporary_pub, get_app
|
from .utilities import clean_temporary_pub, create_temporary_pub, get_app
|
||||||
|
|
||||||
|
|
||||||
def setup_module(module):
|
@pytest.fixture
|
||||||
cleanup()
|
def pub():
|
||||||
|
|
||||||
global pub, req
|
|
||||||
global user1, user2
|
|
||||||
global category
|
|
||||||
|
|
||||||
pub = create_temporary_pub()
|
pub = create_temporary_pub()
|
||||||
|
|
||||||
req = HTTPRequest(None, {'SCRIPT_NAME': '/'})
|
req = HTTPRequest(None, {'SCRIPT_NAME': '/'})
|
||||||
|
@ -26,59 +19,74 @@ def setup_module(module):
|
||||||
pub._set_request(req)
|
pub._set_request(req)
|
||||||
req.session = sessions.Session(id=1)
|
req.session = sessions.Session(id=1)
|
||||||
|
|
||||||
|
FormDef.wipe()
|
||||||
|
Category.wipe()
|
||||||
|
pub.user_class.wipe()
|
||||||
|
|
||||||
|
yield pub
|
||||||
|
clean_temporary_pub()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def user1(pub):
|
||||||
user1 = pub.user_class(name='user-one-role')
|
user1 = pub.user_class(name='user-one-role')
|
||||||
user1.id = 'user-one-role'
|
user1.id = 'user-one-role'
|
||||||
user1.roles = ['role-1']
|
user1.roles = ['role-1']
|
||||||
|
return user1
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def user2(pub):
|
||||||
user2 = pub.user_class(name='user-other-role')
|
user2 = pub.user_class(name='user-other-role')
|
||||||
user2.id = 'user-other-role'
|
user2.id = 'user-other-role'
|
||||||
user2.roles = ['role-2']
|
user2.roles = ['role-2']
|
||||||
|
return user2
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def category(pub):
|
||||||
category = Category()
|
category = Category()
|
||||||
category.name = 'category1'
|
category.name = 'category1'
|
||||||
category.store()
|
category.store()
|
||||||
|
return category
|
||||||
|
|
||||||
|
|
||||||
def create_formdef():
|
@pytest.fixture
|
||||||
global formdef1, formdef2
|
def formdef1(pub, category):
|
||||||
|
|
||||||
formdef1 = FormDef()
|
formdef1 = FormDef()
|
||||||
formdef1.category_id = category.id
|
formdef1.category_id = category.id
|
||||||
formdef1.name = formdef1.url_name = 'test-formdef-1'
|
formdef1.name = formdef1.url_name = 'test-formdef-1'
|
||||||
formdef1.store()
|
formdef1.store()
|
||||||
|
return formdef1
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def formdef2(pub, category):
|
||||||
formdef2 = FormDef()
|
formdef2 = FormDef()
|
||||||
formdef2.category_id = category.id
|
formdef2.category_id = category.id
|
||||||
formdef2.name = formdef2.url_name = 'test-formdef-2'
|
formdef2.name = formdef2.url_name = 'test-formdef-2'
|
||||||
formdef2.store()
|
formdef2.store()
|
||||||
|
return formdef2
|
||||||
|
|
||||||
def teardown_module(module):
|
|
||||||
shutil.rmtree(pub.APP_DIR)
|
|
||||||
|
|
||||||
|
|
||||||
def indexhtml(user=None):
|
def indexhtml(user=None):
|
||||||
|
req = get_request()
|
||||||
req._user = user
|
req._user = user
|
||||||
req.session.user = user.id if user else None
|
req.session.user = user.id if user else None
|
||||||
return str(wcs.forms.root.RootDirectory()._q_index())
|
return str(wcs.forms.root.RootDirectory()._q_index())
|
||||||
|
|
||||||
|
|
||||||
def test_empty_site():
|
def test_empty_site(pub):
|
||||||
FormDef.wipe()
|
|
||||||
assert indexhtml() == ''
|
assert indexhtml() == ''
|
||||||
|
|
||||||
|
|
||||||
def test_public_site_anonymous_access():
|
def test_public_site_anonymous_access(pub, formdef1, formdef2):
|
||||||
FormDef.wipe()
|
|
||||||
create_formdef()
|
|
||||||
output = indexhtml()
|
output = indexhtml()
|
||||||
assert 'href="category1/test-formdef-1/"' in output
|
assert 'href="category1/test-formdef-1/"' in output
|
||||||
assert 'href="category1/test-formdef-2/"' in output
|
assert 'href="category1/test-formdef-2/"' in output
|
||||||
|
|
||||||
|
|
||||||
def test_private_site_anonymous_access():
|
def test_private_site_anonymous_access(pub, formdef1, formdef2):
|
||||||
FormDef.wipe()
|
|
||||||
create_formdef()
|
|
||||||
formdef1.roles = formdef2.roles = ['role-1']
|
formdef1.roles = formdef2.roles = ['role-1']
|
||||||
formdef1.store()
|
formdef1.store()
|
||||||
formdef2.store()
|
formdef2.store()
|
||||||
|
@ -86,9 +94,7 @@ def test_private_site_anonymous_access():
|
||||||
indexhtml()
|
indexhtml()
|
||||||
|
|
||||||
|
|
||||||
def test_semi_private_site_anonymous_access():
|
def test_semi_private_site_anonymous_access(pub, formdef1, formdef2):
|
||||||
FormDef.wipe()
|
|
||||||
create_formdef()
|
|
||||||
formdef1.roles = ['role-1']
|
formdef1.roles = ['role-1']
|
||||||
formdef1.store()
|
formdef1.store()
|
||||||
output = indexhtml()
|
output = indexhtml()
|
||||||
|
@ -96,9 +102,7 @@ def test_semi_private_site_anonymous_access():
|
||||||
assert 'href="category1/test-formdef-2/"' in output
|
assert 'href="category1/test-formdef-2/"' in output
|
||||||
|
|
||||||
|
|
||||||
def test_private_site_authorized_access():
|
def test_private_site_authorized_access(pub, formdef1, formdef2, user1):
|
||||||
FormDef.wipe()
|
|
||||||
create_formdef()
|
|
||||||
formdef1.roles = formdef2.roles = ['role-1']
|
formdef1.roles = formdef2.roles = ['role-1']
|
||||||
formdef1.store()
|
formdef1.store()
|
||||||
formdef2.store()
|
formdef2.store()
|
||||||
|
@ -107,9 +111,7 @@ def test_private_site_authorized_access():
|
||||||
assert 'href="category1/test-formdef-2/"' in output
|
assert 'href="category1/test-formdef-2/"' in output
|
||||||
|
|
||||||
|
|
||||||
def test_private_site_unauthorized_access():
|
def test_private_site_unauthorized_access(pub, formdef1, formdef2, user2):
|
||||||
FormDef.wipe()
|
|
||||||
create_formdef()
|
|
||||||
formdef1.roles = formdef2.roles = ['role-1']
|
formdef1.roles = formdef2.roles = ['role-1']
|
||||||
formdef1.store()
|
formdef1.store()
|
||||||
formdef2.store()
|
formdef2.store()
|
||||||
|
@ -117,9 +119,7 @@ def test_private_site_unauthorized_access():
|
||||||
indexhtml(user2)
|
indexhtml(user2)
|
||||||
|
|
||||||
|
|
||||||
def test_private_site_semi_authorized_access():
|
def test_private_site_semi_authorized_access(pub, formdef1, formdef2, user1):
|
||||||
FormDef.wipe()
|
|
||||||
create_formdef()
|
|
||||||
formdef1.roles = ['role-1']
|
formdef1.roles = ['role-1']
|
||||||
formdef2.roles = ['role-2']
|
formdef2.roles = ['role-2']
|
||||||
formdef1.store()
|
formdef1.store()
|
||||||
|
@ -129,9 +129,7 @@ def test_private_site_semi_authorized_access():
|
||||||
assert 'href="category1/test-formdef-2/"' not in output
|
assert 'href="category1/test-formdef-2/"' not in output
|
||||||
|
|
||||||
|
|
||||||
def test_advertized_site_anonymous_access():
|
def test_advertized_site_anonymous_access(pub, formdef1, formdef2):
|
||||||
FormDef.wipe()
|
|
||||||
create_formdef()
|
|
||||||
formdef1.roles = formdef2.roles = ['role-1']
|
formdef1.roles = formdef2.roles = ['role-1']
|
||||||
formdef1.always_advertise = True
|
formdef1.always_advertise = True
|
||||||
formdef1.store()
|
formdef1.store()
|
||||||
|
@ -142,9 +140,7 @@ def test_advertized_site_anonymous_access():
|
||||||
assert 'authentication required' in output # locales ?
|
assert 'authentication required' in output # locales ?
|
||||||
|
|
||||||
|
|
||||||
def test_advertized_site_user_access():
|
def test_advertized_site_user_access(pub, formdef1, formdef2, user1):
|
||||||
FormDef.wipe()
|
|
||||||
create_formdef()
|
|
||||||
formdef1.roles = formdef2.roles = ['role-2']
|
formdef1.roles = formdef2.roles = ['role-2']
|
||||||
formdef1.always_advertise = True
|
formdef1.always_advertise = True
|
||||||
formdef1.store()
|
formdef1.store()
|
||||||
|
@ -155,9 +151,7 @@ def test_advertized_site_user_access():
|
||||||
assert 'authentication required' in output # locales ?
|
assert 'authentication required' in output # locales ?
|
||||||
|
|
||||||
|
|
||||||
def test_categories_page():
|
def test_categories_page(pub, category, formdef1):
|
||||||
FormDef.wipe()
|
|
||||||
create_formdef()
|
|
||||||
resp = get_app(pub).get('/categories')
|
resp = get_app(pub).get('/categories')
|
||||||
assert 'href="category1/"' in resp
|
assert 'href="category1/"' in resp
|
||||||
FormDef.wipe()
|
FormDef.wipe()
|
||||||
|
@ -165,7 +159,7 @@ def test_categories_page():
|
||||||
assert 'href="category1/"' not in resp
|
assert 'href="category1/"' not in resp
|
||||||
|
|
||||||
|
|
||||||
def test_static_directories():
|
def test_static_directories(pub):
|
||||||
assert get_app(pub).get('/static/images/feed-icon-10x10.png')
|
assert get_app(pub).get('/static/images/feed-icon-10x10.png')
|
||||||
assert get_app(pub).get('/static/css/gadjo.css')
|
assert get_app(pub).get('/static/css/gadjo.css')
|
||||||
assert get_app(pub).get('/static/xstatic/jquery.js')
|
assert get_app(pub).get('/static/xstatic/jquery.js')
|
||||||
|
@ -175,9 +169,7 @@ def test_static_directories():
|
||||||
assert get_app(pub).get('/static/xxx', status=404)
|
assert get_app(pub).get('/static/xxx', status=404)
|
||||||
|
|
||||||
|
|
||||||
def test_jquery_debug_mode():
|
def test_jquery_debug_mode(pub, formdef1):
|
||||||
FormDef.wipe()
|
|
||||||
create_formdef()
|
|
||||||
resp = get_app(pub).get('/category1/test-formdef-1/')
|
resp = get_app(pub).get('/category1/test-formdef-1/')
|
||||||
assert 'jquery.min.js' in resp.text
|
assert 'jquery.min.js' in resp.text
|
||||||
pub.cfg['debug'] = {'debug_mode': True}
|
pub.cfg['debug'] = {'debug_mode': True}
|
||||||
|
@ -186,5 +178,5 @@ def test_jquery_debug_mode():
|
||||||
assert 'jquery.js' in resp.text
|
assert 'jquery.js' in resp.text
|
||||||
|
|
||||||
|
|
||||||
def test_i18n_js():
|
def test_i18n_js(pub):
|
||||||
get_app(pub).get('/i18n.js')
|
get_app(pub).get('/i18n.js')
|
||||||
|
|
Loading…
Reference in New Issue