Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/news/462.tests
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Upgrade `pytest-plone` to version 1.1.0 and re-parent the acceptance remote-library bundle onto the kitconcept fixture, avoiding a duplicate Plone site under the new `keep_session` default. @ericof
4 changes: 2 additions & 2 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test = [
"plone.restapi[test]",
"pytest",
"pytest-cov",
"pytest-plone>=1.0.0",
"pytest-plone>=1.1.0",
]

[dependency-groups]
Expand All @@ -59,7 +59,7 @@ test = [
"plone.restapi[test]",
"pytest",
"pytest-cov",
"pytest-plone>=1.0.0",
"pytest-plone>=1.1.0",
]

[project.urls]
Expand Down
8 changes: 7 additions & 1 deletion backend/src/kitconcept/core/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from kitconcept.core.testing import layers
from plone.app.robotframework.testing import REMOTE_LIBRARY_BUNDLE_FIXTURE
from kitconcept.core.testing import robot
from plone.app.robotframework.remote import RemoteLibraryLayer
from plone.app.testing import FunctionalTesting
from plone.app.testing import IntegrationTesting
from plone.app.testing import PloneSandboxLayer
Expand All @@ -26,6 +27,11 @@ class Layer(PloneSandboxLayer):
name="kitconcept.coreLayer:FunctionalTesting",
)

REMOTE_LIBRARY_BUNDLE_FIXTURE = RemoteLibraryLayer(
bases=(kitconcept_FIXTURE,),
libraries=robot.RF_LIBRARIES,
name="RemoteLibraryBundle:RobotRemote",
)

ACCEPTANCE_TESTING = FunctionalTesting(
bases=(
Expand Down
2 changes: 1 addition & 1 deletion backend/src/kitconcept/core/testing/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def setUpDefaultContent(self, app):
sites = self.sites
if not sites:
raise RuntimeError("No sites defined in this fixture")

for distribution_name, answers in sites:
site_id = answers["site_id"]
# Create Plone site
Expand All @@ -67,7 +68,6 @@ def setUpDefaultContent(self, app):
distribution=distribution_name,
**answers,
)

# Create the test user. (Plone)PAS does not have an API to create a
# user with different userid and login name, so we call the plugin
# directly.
Expand Down
20 changes: 20 additions & 0 deletions backend/src/kitconcept/core/testing/robot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from plone.app.robotframework.autologin import AutoLogin
from plone.app.robotframework.content import Content
from plone.app.robotframework.genericsetup import GenericSetup
from plone.app.robotframework.i18n import I18N
from plone.app.robotframework.mailhost import MockMailHost
from plone.app.robotframework.quickinstaller import QuickInstaller
from plone.app.robotframework.server import Zope2ServerRemote
from plone.app.robotframework.users import Users


RF_LIBRARIES = (
AutoLogin,
QuickInstaller,
GenericSetup,
Content,
Users,
I18N,
MockMailHost,
Zope2ServerRemote,
)
22 changes: 14 additions & 8 deletions backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@


globals().update(
fixtures_factory((
(ACCEPTANCE_TESTING, "acceptance"),
(FUNCTIONAL_TESTING, "functional"),
(INTEGRATION_TESTING, "integration"),
))
fixtures_factory(
(
(ACCEPTANCE_TESTING, "acceptance"),
(FUNCTIONAL_TESTING, "functional"),
(INTEGRATION_TESTING, "integration"),
),
keep_session=True,
)
)


Expand Down Expand Up @@ -74,7 +77,7 @@ def current_versions() -> CurrentVersions:


@pytest.fixture(scope="session")
def distribution() -> str:
def distribution_name() -> str:
return "testing"


Expand All @@ -101,10 +104,13 @@ def answers(prepare_answers) -> dict:


@pytest.fixture(scope="session")
def create_site(distribution):
def create_site(distribution_name):
def func(app, answers: dict) -> PloneSite:
with api.env.adopt_user(SITE_OWNER_NAME):
site = add_site(app, distribution=distribution, **answers)
site_id = answers.get("site_id")
if site_id and (site_id in app.objectIds()):
app.manage_delObjects(site_id)
site = add_site(app, distribution=distribution_name, **answers)
return site

return func
6 changes: 2 additions & 4 deletions backend/tests/creation/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from Acquisition import aq_parent
from collections.abc import Generator
from Products.CMFPlone.Portal import PloneSite

import pytest


@pytest.fixture(scope="class")
def portal(portal_class, create_site, answers) -> Generator[PloneSite, None, None]:
app = aq_parent(portal_class)
site = create_site(app=app, answers=answers)
def portal(app_class, create_site, answers) -> Generator[PloneSite, None, None]:
site = create_site(app=app_class, answers=answers)
yield site
13 changes: 9 additions & 4 deletions backend/tests/services/sites/test_sites.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from copy import deepcopy
from random import randint

import pytest


class TestSitesEndpoint:
@pytest.fixture(autouse=True)
def _setup(self, api_manager_request, distribution):
def _setup(self, api_manager_request, distribution_name):
self.api_session = api_manager_request
self.url = f"@sites/{distribution}"
self.url = f"@sites/{distribution_name}"

def test_get(self):
response = self.api_session.get(self.url)
Expand Down Expand Up @@ -34,9 +37,11 @@ def test_get_add_definitions(self, key: str):
assert key in definitions

def test_post(self, answers):
response = self.api_session.post(self.url, json=answers)
_answers = deepcopy(answers)
_answers["site_id"] = f"plone{randint(5, 10):02d}" # noqa: S311
response = self.api_session.post(self.url, json=_answers)
data = response.json()
assert response.status_code == 200
assert isinstance(data, dict)
assert data["id"] == answers["site_id"]
assert data["id"] == _answers["site_id"]
assert data["_profile_id"] == "kitconcept.core:base"
12 changes: 7 additions & 5 deletions backend/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading