tests: move WebTestCase
to wuttaweb.testing
module
This commit is contained in:
parent
5cec585fdf
commit
7895ce4676
84
src/wuttaweb/testing.py
Normal file
84
src/wuttaweb/testing.py
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
# -*- coding: utf-8; -*-
|
||||||
|
################################################################################
|
||||||
|
#
|
||||||
|
# wuttaweb -- Web App for Wutta Framework
|
||||||
|
# Copyright © 2024 Lance Edgar
|
||||||
|
#
|
||||||
|
# This file is part of Wutta Framework.
|
||||||
|
#
|
||||||
|
# Wutta Framework is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the Free
|
||||||
|
# Software Foundation, either version 3 of the License, or (at your option) any
|
||||||
|
# later version.
|
||||||
|
#
|
||||||
|
# Wutta Framework 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 General Public License for
|
||||||
|
# more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along with
|
||||||
|
# Wutta Framework. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
"""
|
||||||
|
WuttaWeb - test utilities
|
||||||
|
"""
|
||||||
|
|
||||||
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
import fanstatic
|
||||||
|
from pyramid import testing
|
||||||
|
|
||||||
|
from wuttjamaican.testing import DataTestCase
|
||||||
|
|
||||||
|
from wuttaweb import subscribers
|
||||||
|
|
||||||
|
|
||||||
|
class WebTestCase(DataTestCase):
|
||||||
|
"""
|
||||||
|
Base class for test suites requiring a full (typical) web app.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.setup_web()
|
||||||
|
|
||||||
|
def setup_web(self):
|
||||||
|
self.setup_db()
|
||||||
|
self.request = self.make_request()
|
||||||
|
self.pyramid_config = testing.setUp(request=self.request, settings={
|
||||||
|
'wutta_config': self.config,
|
||||||
|
'mako.directories': ['wuttaweb:templates'],
|
||||||
|
'pyramid_deform.template_search_path': 'wuttaweb:templates/deform',
|
||||||
|
})
|
||||||
|
|
||||||
|
# init web
|
||||||
|
self.pyramid_config.include('pyramid_deform')
|
||||||
|
self.pyramid_config.include('pyramid_mako')
|
||||||
|
self.pyramid_config.add_directive('add_wutta_permission_group',
|
||||||
|
'wuttaweb.auth.add_permission_group')
|
||||||
|
self.pyramid_config.add_directive('add_wutta_permission',
|
||||||
|
'wuttaweb.auth.add_permission')
|
||||||
|
self.pyramid_config.add_subscriber('wuttaweb.subscribers.before_render',
|
||||||
|
'pyramid.events.BeforeRender')
|
||||||
|
self.pyramid_config.include('wuttaweb.static')
|
||||||
|
|
||||||
|
# nb. mock out fanstatic env..good enough for now to avoid errors..
|
||||||
|
needed = fanstatic.init_needed()
|
||||||
|
self.request.environ[fanstatic.NEEDED] = needed
|
||||||
|
|
||||||
|
# setup new request w/ anonymous user
|
||||||
|
event = MagicMock(request=self.request)
|
||||||
|
subscribers.new_request(event)
|
||||||
|
def user_getter(request, **kwargs): pass
|
||||||
|
subscribers.new_request_set_user(event, db_session=self.session,
|
||||||
|
user_getter=user_getter)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.teardown_web()
|
||||||
|
|
||||||
|
def teardown_web(self):
|
||||||
|
testing.tearDown()
|
||||||
|
self.teardown_db()
|
||||||
|
|
||||||
|
def make_request(self):
|
||||||
|
return testing.DummyRequest()
|
|
@ -4,9 +4,8 @@ from unittest.mock import patch, MagicMock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from tests.util import WebTestCase
|
|
||||||
|
|
||||||
from wuttaweb.db import continuum as mod
|
from wuttaweb.db import continuum as mod
|
||||||
|
from wuttaweb.testing import WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestWuttaWebContinuumPlugin(WebTestCase):
|
class TestWuttaWebContinuumPlugin(WebTestCase):
|
||||||
|
|
|
@ -12,7 +12,7 @@ from sqlalchemy import orm
|
||||||
from wuttjamaican.conf import WuttaConfig
|
from wuttjamaican.conf import WuttaConfig
|
||||||
from wuttaweb.forms import schema as mod
|
from wuttaweb.forms import schema as mod
|
||||||
from wuttaweb.forms import widgets
|
from wuttaweb.forms import widgets
|
||||||
from tests.util import DataTestCase, WebTestCase
|
from wuttaweb.testing import DataTestCase, WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestWutaDateTime(TestCase):
|
class TestWutaDateTime(TestCase):
|
||||||
|
|
|
@ -13,7 +13,7 @@ from wuttaweb.forms import widgets as mod
|
||||||
from wuttaweb.forms import schema
|
from wuttaweb.forms import schema
|
||||||
from wuttaweb.forms.schema import (FileDownload, PersonRef, RoleRefs, UserRefs, Permissions,
|
from wuttaweb.forms.schema import (FileDownload, PersonRef, RoleRefs, UserRefs, Permissions,
|
||||||
WuttaDateTime, EmailRecipients)
|
WuttaDateTime, EmailRecipients)
|
||||||
from tests.util import WebTestCase
|
from wuttaweb.testing import WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestObjectRefWidget(WebTestCase):
|
class TestObjectRefWidget(WebTestCase):
|
||||||
|
|
|
@ -16,7 +16,7 @@ from wuttaweb.grids import base as mod
|
||||||
from wuttaweb.grids.filters import GridFilter, StringAlchemyFilter, default_sqlalchemy_filters
|
from wuttaweb.grids.filters import GridFilter, StringAlchemyFilter, default_sqlalchemy_filters
|
||||||
from wuttaweb.util import FieldList
|
from wuttaweb.util import FieldList
|
||||||
from wuttaweb.forms import Form
|
from wuttaweb.forms import Form
|
||||||
from tests.util import WebTestCase
|
from wuttaweb.testing import WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestGrid(WebTestCase):
|
class TestGrid(WebTestCase):
|
||||||
|
|
|
@ -9,7 +9,7 @@ import sqlalchemy as sa
|
||||||
from wuttjamaican.db.model import Base
|
from wuttjamaican.db.model import Base
|
||||||
|
|
||||||
from wuttaweb.grids import filters as mod
|
from wuttaweb.grids import filters as mod
|
||||||
from tests.util import WebTestCase
|
from wuttaweb.testing import WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestGridFilter(WebTestCase):
|
class TestGridFilter(WebTestCase):
|
||||||
|
|
|
@ -8,7 +8,7 @@ from pyramid import testing
|
||||||
|
|
||||||
from wuttjamaican.conf import WuttaConfig
|
from wuttjamaican.conf import WuttaConfig
|
||||||
from wuttaweb import auth as mod
|
from wuttaweb import auth as mod
|
||||||
from tests.util import WebTestCase
|
from wuttaweb.testing import WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestLoginUser(TestCase):
|
class TestLoginUser(TestCase):
|
||||||
|
|
|
@ -4,7 +4,7 @@ from wuttaweb import handler as mod, static
|
||||||
from wuttaweb.forms import Form
|
from wuttaweb.forms import Form
|
||||||
from wuttaweb.grids import Grid
|
from wuttaweb.grids import Grid
|
||||||
from wuttaweb.menus import MenuHandler
|
from wuttaweb.menus import MenuHandler
|
||||||
from tests.util import WebTestCase
|
from wuttaweb.testing import WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestWebHandler(WebTestCase):
|
class TestWebHandler(WebTestCase):
|
||||||
|
|
|
@ -4,7 +4,7 @@ from unittest import TestCase
|
||||||
from unittest.mock import patch, MagicMock
|
from unittest.mock import patch, MagicMock
|
||||||
|
|
||||||
from wuttaweb import menus as mod
|
from wuttaweb import menus as mod
|
||||||
from tests.util import WebTestCase
|
from wuttaweb.testing import WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestMenuHandler(WebTestCase):
|
class TestMenuHandler(WebTestCase):
|
||||||
|
|
|
@ -1,14 +1,7 @@
|
||||||
# -*- coding: utf-8; -*-
|
# -*- coding: utf-8; -*-
|
||||||
|
|
||||||
from unittest import TestCase
|
|
||||||
from unittest.mock import MagicMock
|
|
||||||
|
|
||||||
import fanstatic
|
|
||||||
from pyramid import testing
|
|
||||||
|
|
||||||
from wuttjamaican.conf import WuttaConfig
|
from wuttjamaican.conf import WuttaConfig
|
||||||
from wuttjamaican.testing import FileConfigTestCase
|
from wuttjamaican.testing import FileConfigTestCase
|
||||||
from wuttaweb import subscribers
|
|
||||||
from wuttaweb.menus import MenuHandler
|
from wuttaweb.menus import MenuHandler
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,56 +32,6 @@ class DataTestCase(FileConfigTestCase):
|
||||||
self.teardown_files()
|
self.teardown_files()
|
||||||
|
|
||||||
|
|
||||||
class WebTestCase(DataTestCase):
|
|
||||||
"""
|
|
||||||
Base class for test suites requiring a full (typical) web app.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.setup_web()
|
|
||||||
|
|
||||||
def setup_web(self):
|
|
||||||
self.setup_db()
|
|
||||||
self.request = self.make_request()
|
|
||||||
self.pyramid_config = testing.setUp(request=self.request, settings={
|
|
||||||
'wutta_config': self.config,
|
|
||||||
'mako.directories': ['wuttaweb:templates'],
|
|
||||||
'pyramid_deform.template_search_path': 'wuttaweb:templates/deform',
|
|
||||||
})
|
|
||||||
|
|
||||||
# init web
|
|
||||||
self.pyramid_config.include('pyramid_deform')
|
|
||||||
self.pyramid_config.include('pyramid_mako')
|
|
||||||
self.pyramid_config.add_directive('add_wutta_permission_group',
|
|
||||||
'wuttaweb.auth.add_permission_group')
|
|
||||||
self.pyramid_config.add_directive('add_wutta_permission',
|
|
||||||
'wuttaweb.auth.add_permission')
|
|
||||||
self.pyramid_config.add_subscriber('wuttaweb.subscribers.before_render',
|
|
||||||
'pyramid.events.BeforeRender')
|
|
||||||
self.pyramid_config.include('wuttaweb.static')
|
|
||||||
|
|
||||||
# nb. mock out fanstatic env..good enough for now to avoid errors..
|
|
||||||
needed = fanstatic.init_needed()
|
|
||||||
self.request.environ[fanstatic.NEEDED] = needed
|
|
||||||
|
|
||||||
# setup new request w/ anonymous user
|
|
||||||
event = MagicMock(request=self.request)
|
|
||||||
subscribers.new_request(event)
|
|
||||||
def user_getter(request, **kwargs): pass
|
|
||||||
subscribers.new_request_set_user(event, db_session=self.session,
|
|
||||||
user_getter=user_getter)
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
self.teardown_web()
|
|
||||||
|
|
||||||
def teardown_web(self):
|
|
||||||
testing.tearDown()
|
|
||||||
self.teardown_db()
|
|
||||||
|
|
||||||
def make_request(self):
|
|
||||||
return testing.DummyRequest()
|
|
||||||
|
|
||||||
|
|
||||||
class NullMenuHandler(MenuHandler):
|
class NullMenuHandler(MenuHandler):
|
||||||
"""
|
"""
|
||||||
Dummy menu handler for testing.
|
Dummy menu handler for testing.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8; -*-
|
# -*- coding: utf-8; -*-
|
||||||
|
|
||||||
from tests.util import WebTestCase
|
from wuttaweb.testing import WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestIncludeMe(WebTestCase):
|
class TestIncludeMe(WebTestCase):
|
||||||
|
|
|
@ -5,7 +5,7 @@ from unittest.mock import MagicMock, patch
|
||||||
from pyramid.httpexceptions import HTTPFound, HTTPForbidden
|
from pyramid.httpexceptions import HTTPFound, HTTPForbidden
|
||||||
|
|
||||||
from wuttaweb.views import auth as mod
|
from wuttaweb.views import auth as mod
|
||||||
from tests.util import WebTestCase
|
from wuttaweb.testing import WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestAuthView(WebTestCase):
|
class TestAuthView(WebTestCase):
|
||||||
|
|
|
@ -5,7 +5,7 @@ from pyramid.httpexceptions import HTTPFound, HTTPForbidden, HTTPNotFound
|
||||||
from wuttaweb.views import base as mod
|
from wuttaweb.views import base as mod
|
||||||
from wuttaweb.forms import Form
|
from wuttaweb.forms import Form
|
||||||
from wuttaweb.grids import Grid, GridAction
|
from wuttaweb.grids import Grid, GridAction
|
||||||
from tests.util import WebTestCase
|
from wuttaweb.testing import WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestView(WebTestCase):
|
class TestView(WebTestCase):
|
||||||
|
|
|
@ -10,7 +10,7 @@ from wuttjamaican.db import model
|
||||||
from wuttjamaican.batch import BatchHandler
|
from wuttjamaican.batch import BatchHandler
|
||||||
from wuttaweb.views import MasterView, batch as mod
|
from wuttaweb.views import MasterView, batch as mod
|
||||||
from wuttaweb.progress import SessionProgress
|
from wuttaweb.progress import SessionProgress
|
||||||
from tests.util import WebTestCase
|
from wuttaweb.testing import WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class MockBatch(model.BatchMixin, model.Base):
|
class MockBatch(model.BatchMixin, model.Base):
|
||||||
|
|
|
@ -5,7 +5,7 @@ from unittest.mock import patch
|
||||||
import colander
|
import colander
|
||||||
|
|
||||||
from wuttaweb.views import common as mod
|
from wuttaweb.views import common as mod
|
||||||
from tests.util import WebTestCase
|
from wuttaweb.testing import WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestCommonView(WebTestCase):
|
class TestCommonView(WebTestCase):
|
||||||
|
|
|
@ -9,7 +9,7 @@ from pyramid.httpexceptions import HTTPNotFound
|
||||||
from pyramid.response import Response
|
from pyramid.response import Response
|
||||||
|
|
||||||
from wuttaweb.views import email as mod
|
from wuttaweb.views import email as mod
|
||||||
from tests.util import WebTestCase
|
from wuttaweb.testing import WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestEmailSettingViews(WebTestCase):
|
class TestEmailSettingViews(WebTestCase):
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8; -*-
|
# -*- coding: utf-8; -*-
|
||||||
|
|
||||||
from wuttaweb.views import essential as mod
|
from wuttaweb.views import essential as mod
|
||||||
from tests.util import WebTestCase
|
from wuttaweb.testing import WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestEssentialViews(WebTestCase):
|
class TestEssentialViews(WebTestCase):
|
||||||
|
|
|
@ -16,7 +16,7 @@ from wuttaweb.views import master as mod
|
||||||
from wuttaweb.views import View
|
from wuttaweb.views import View
|
||||||
from wuttaweb.progress import SessionProgress
|
from wuttaweb.progress import SessionProgress
|
||||||
from wuttaweb.subscribers import new_request_set_user
|
from wuttaweb.subscribers import new_request_set_user
|
||||||
from tests.util import WebTestCase
|
from wuttaweb.testing import WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestMasterView(WebTestCase):
|
class TestMasterView(WebTestCase):
|
||||||
|
|
|
@ -7,7 +7,7 @@ from sqlalchemy import orm
|
||||||
from pyramid.httpexceptions import HTTPNotFound
|
from pyramid.httpexceptions import HTTPNotFound
|
||||||
|
|
||||||
from wuttaweb.views import people
|
from wuttaweb.views import people
|
||||||
from tests.util import WebTestCase
|
from wuttaweb.testing import WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestPersonView(WebTestCase):
|
class TestPersonView(WebTestCase):
|
||||||
|
|
|
@ -4,7 +4,7 @@ from pyramid import testing
|
||||||
|
|
||||||
from wuttaweb.views import progress as mod
|
from wuttaweb.views import progress as mod
|
||||||
from wuttaweb.progress import get_progress_session
|
from wuttaweb.progress import get_progress_session
|
||||||
from tests.util import WebTestCase
|
from wuttaweb.testing import WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestProgressView(WebTestCase):
|
class TestProgressView(WebTestCase):
|
||||||
|
|
|
@ -8,7 +8,7 @@ import colander
|
||||||
|
|
||||||
from wuttaweb.views import roles as mod
|
from wuttaweb.views import roles as mod
|
||||||
from wuttaweb.forms.schema import RoleRef
|
from wuttaweb.forms.schema import RoleRef
|
||||||
from tests.util import WebTestCase
|
from wuttaweb.testing import WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestRoleView(WebTestCase):
|
class TestRoleView(WebTestCase):
|
||||||
|
|
|
@ -6,7 +6,7 @@ import colander
|
||||||
from pyramid.httpexceptions import HTTPNotFound
|
from pyramid.httpexceptions import HTTPNotFound
|
||||||
|
|
||||||
from wuttaweb.views import settings as mod
|
from wuttaweb.views import settings as mod
|
||||||
from tests.util import WebTestCase
|
from wuttaweb.testing import WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestAppInfoView(WebTestCase):
|
class TestAppInfoView(WebTestCase):
|
||||||
|
|
|
@ -8,7 +8,7 @@ from unittest.mock import patch, MagicMock
|
||||||
from wuttaweb.views import upgrades as mod
|
from wuttaweb.views import upgrades as mod
|
||||||
from wuttjamaican.exc import ConfigurationError
|
from wuttjamaican.exc import ConfigurationError
|
||||||
from wuttaweb.progress import get_progress_session
|
from wuttaweb.progress import get_progress_session
|
||||||
from tests.util import WebTestCase
|
from wuttaweb.testing import WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestUpgradeView(WebTestCase):
|
class TestUpgradeView(WebTestCase):
|
||||||
|
|
|
@ -7,7 +7,7 @@ from sqlalchemy import orm
|
||||||
import colander
|
import colander
|
||||||
|
|
||||||
from wuttaweb.views import users as mod
|
from wuttaweb.views import users as mod
|
||||||
from tests.util import WebTestCase
|
from wuttaweb.testing import WebTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestUserView(WebTestCase):
|
class TestUserView(WebTestCase):
|
||||||
|
|
Loading…
Reference in a new issue