Skip to content

Commit

Permalink
Better db session in theme test
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Oct 11, 2024
1 parent 66443ed commit 45236b4
Show file tree
Hide file tree
Showing 2 changed files with 355 additions and 364 deletions.
23 changes: 23 additions & 0 deletions admin/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
from typing import Any

import pyramid.registry
import pyramid.request
import pytest
import sqlalchemy.exc
import tests
import transaction
import webob.acceptparse
from c2c.template.config import config as configuration
from pyramid import testing
from pyramid.paster import bootstrap
from pyramid.router import Router
from pyramid.scripting import AppEnvironment
from sqlalchemy.exc import DBAPIError
from sqlalchemy.orm import Session, SessionTransaction
from sqlalchemy.orm.session import Session
from tests.functional import mapserv_url
from webtest import TestApp as WebTestApp # Avoid warning with pytest

import c2cgeoportal_geoportal
import c2cgeoportal_geoportal.lib
from c2cgeoportal_commons import models
from c2cgeoportal_commons.testing import generate_mappers, get_engine, get_session_factory, get_tm_session
from c2cgeoportal_commons.testing.initializedb import truncate_tables
from c2cgeoportal_geoportal.lib import caching


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -83,3 +93,16 @@ def settings(app_env: AppEnvironment) -> Any:
def test_app(request: pyramid.request.Request, app: Router) -> WebTestApp:
testapp = WebTestApp(app)
yield testapp


@pytest.fixture()
@pytest.mark.usefixtures("dbsession")
def default_ogcserver(dbsession: Session) -> models.main.OGCServer:
from c2cgeoportal_commons.models.main import OGCServer

ogcserver = OGCServer(name="__test_ogc_server")
ogcserver.url = mapserv_url
dbsession.add(ogcserver)
caching.invalidate_region()

return ogcserver
Loading

0 comments on commit 45236b4

Please sign in to comment.