From 160f01930d7fe1cd9b66d26439e4f1a014eb1995 Mon Sep 17 00:00:00 2001 From: David Glick Date: Tue, 21 May 2024 10:38:21 -0700 Subject: [PATCH] add test for behavior schema --- setup.py | 4 ++++ src/kitconcept/seo/testing.py | 4 ++++ tests/conftest.py | 12 ++++++++++++ tests/test_behavior.py | 23 +++++++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 tests/test_behavior.py diff --git a/setup.py b/setup.py index d3b2ef7..d942d82 100644 --- a/setup.py +++ b/setup.py @@ -64,6 +64,10 @@ "zestreleaser.towncrier", "plone.app.contenttypes[test]", "plone.app.testing", + "plone.restapi[test]", + # Undeclared dependency of plone.restapi, + # can be removed after next release + "plone.app.iterate", "pytest", "pytest-cov", "pytest-plone>=0.2.0", diff --git a/src/kitconcept/seo/testing.py b/src/kitconcept/seo/testing.py index 6979f3a..1754799 100644 --- a/src/kitconcept/seo/testing.py +++ b/src/kitconcept/seo/testing.py @@ -15,10 +15,14 @@ def setUpZope(self, app, configurationContext): # Load any other ZCML that is required for your tests. # The z3c.autoinclude feature is disabled in the Plone fixture base # layer. + import plone.restapi + self.loadZCML(package=kitconcept.seo) + self.loadZCML(package=plone.restapi) def setUpPloneSite(self, portal): applyProfile(portal, "kitconcept.seo:default") + applyProfile(portal, "plone.restapi:default") FIXTURE = Layer() diff --git a/tests/conftest.py b/tests/conftest.py index 055df11..da5fe46 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,10 @@ from kitconcept.seo.testing import FUNCTIONAL_TESTING from kitconcept.seo.testing import INTEGRATION_TESTING +from plone.app.testing import SITE_OWNER_NAME +from plone.app.testing import SITE_OWNER_PASSWORD +from plone.restapi.testing import RelativeSession from pytest_plone import fixtures_factory +import pytest pytest_plugins = ["pytest_plone"] @@ -14,3 +18,11 @@ ) ) ) + + +@pytest.fixture +def manager_plone_client(functional): + portal = functional["portal"] + api_session = RelativeSession(f"{portal.absolute_url()}/++api++") + api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) + return api_session diff --git a/tests/test_behavior.py b/tests/test_behavior.py new file mode 100644 index 0000000..f3a2d6b --- /dev/null +++ b/tests/test_behavior.py @@ -0,0 +1,23 @@ +def test_seo_behavior_fields(manager_plone_client): + # Enable behavior for pages + resp = manager_plone_client.patch( + "/@controlpanels/dexterity-types/Document", json={"kitconcept.seo": True} + ) + + # Check schema + schema = manager_plone_client.get("/@types/Document").json() + assert schema["fieldsets"][-1] == { + "behavior": "plone", + "description": "", + "fields": [ + "seo_title", + "seo_description", + "seo_noindex", + "seo_canonical_url", + "opengraph_title", + "opengraph_description", + "opengraph_image", + ], + "id": "seo", + "title": "SEO", + }