Package: pytest-plone
pytest-plonepytest-ploneis apytestplugin providing fixtures and helpers to testPloneadd-ons.This package is built on top ofgocept.pytestlayer.ReasoningDespite the fact Plone, and Zope, have their codebases tested withunittest, over the yearspytestbecame the most popular choice for testing in Python.pytestis more flexible and easier to use thanunittestand has a rich ecosystem of plugins that you can use to extend its functionality.WarningTHIS PACKAGE IS NOT CONSIDERED TO BE STABLE AND FIXTURES COULD CHANGE BEFORE A FINAL RELEASEUsageIn your top-levelconftest.pyimport your testing layers, and also importfixtures_factory-- which will accept a iterator of tuples containing the testing layer and a prefix to be used to generate the needed pytest fixtures.fromProducts.CMFPlone.testingimportPRODUCTS_CMFPLONE_FUNCTIONAL_TESTINGfromProducts.CMFPlone.testingimportPRODUCTS_CMFPLONE_INTEGRATION_TESTINGfrompytest_ploneimportfixtures_factorypytest_plugins=["pytest_plone"]globals().update(fixtures_factory(((PRODUCTS_CMFPLONE_FUNCTIONAL_TESTING,"functional"),(PRODUCTS_CMFPLONE_INTEGRATION_TESTING,"integration"),)))In the code above, the following pytest fixtures will be available to your tests:FixtureScopefunctional_sessionSessionfunctional_classClassfunctionalFunctionintegration_sessionSessionintegration_classClassintegrationFunctionFixturesappDescriptionZope rootRequired FixtureintegrationScopeFunctiondeftest_app(app):"""Test portal title."""assertapp.getPhysicalPath()==("",)portalDescriptionPortal objectRequired FixtureintegrationScopeFunctiondeftest_portal_title(portal):"""Test portal title."""assertportal.title=="Plone Site"http_requestDescriptionHTTP RequestRequired FixtureintegrationScopeFunctionfromploneimportapideftest_myproduct_controlpanel_view(portal,http_request):"""Test myproduct_controlpanel browser view is available."""view=api.content.get_view("myproduct-controlpanel",portal,http_request)assertviewisnotNoneinstallerDescriptionInstaller browser view. Used to install/uninstall/check for an add-on.Required FixtureintegrationScopeFunctionimportpytestPACKAGE_NAME="myproduct"@pytest.fixturedefuninstall(installer):"""Fixture to uninstall a package."""installer.uninstall_product(PACKAGE_NAME)deftest_product_installed(installer):"""Test if myproduct is installed."""assertinstaller.is_product_installed(PACKAGE_NAME)isTrue@pytest.mark.parametrize("package",["collective.casestudy","pytest-plone",])deftest_dependency_installed(installer,package):"""Test if dependency is installed."""assertinstaller.is_product_installed(package)isTruebrowser_layersDescriptionList of available browser layers. Used to test if a specific browser layer is registered.Required FixtureintegrationScopeFunctiondeftest_browserlayer(browser_layers):"""Test that IMyProductLayer is registered."""frommyproduct.interfacesimportIMyProductLayerassertIMyProductLayerinbrowser_layerscontrolpanel_actionsDescriptionList of control panel actions ids. Used to test if a specific control panel is installed or not.Required FixtureintegrationScopeFunctiondeftest_configlet_install(controlpanel_actions):"""Test if control panel is installed."""assert"myproductcontrolpanel"incontrolpanel_actionsget_ftiDescriptionFunction to get the Factory Type Info (FTI) for a content type.Required FixtureintegrationScopeFunctiondeftest_get_fti(get_fti):"""Test if Document fti is installed."""assertget_fti("Document")isnotNoneget_behaviorsDescriptionFunction to list behaviors for a content type.Required FixtureintegrationScopeFunctionimportpytestdeftest_block_in_document(get_behaviors):"""Test if blocks behavior is installed for Document."""assert"volto.blocks"inget_behaviors("Document")@pytest.mark.parametrize("behavior",["plone.dublincore","plone.namefromtitle","plone.shortname","plone.excludefromnavigation","plone.relateditems","plone.versioning","volto.blocks","volto.navtitle","volto.preview_image","volto.head_title",],)deftest_has_behavior(self,get_behaviors,behavior):assertbehavioringet_behaviors("Document")get_vocabularyDescriptionFunction to get a named vocabulary.Required FixtureintegrationScopeFunctionfromzope.schema.vocabularyimportSimpleVocabularyVOCAB="plone.app.vocabularies.AvailableContentLanguages"deftest_get_vocabulary(get_vocabulary):"""Test plone.app.vocabularies.AvailableContentLanguages."""vocab=get_vocabulary(VOCAB)assertvocabisnotNoneassertisinstance(vocab,SimpleVocabulary)setup_toolDescriptionPortal Setup tool.Required FixtureintegrationScopeFunctiondeftest_setup_tool(setup_tool):"""Test setup_tool."""assertsetup_toolisnotNoneprofile_last_versionDescriptionFunction to get the last version of a profile.Required FixtureintegrationScopeFunctionPACKAGE_NAME="collective.case_study"deftest_last_version(profile_last_version):"""Test setup_tool."""profile=f"{PACKAGE_NAME}:default"version=profile_last_version(profile)assertversion=="1000"Plugin DevelopmentYou need a workingpythonenvironment (system, virtualenv, pyenv, etc) version 3.8 or superior.Then install the dependencies and a development instance using:makebuildTo run tests for this package:maketestBy default we use the latest Plone version in the 6.x series.LicenseThe project is licensed under the GPLv2.Changelog0.2.0 (2023-01-05)Addappfixture.
[ericof]Addsetup_toolandprofile_last_versionfixtures.
[ericof]Addget_ftiandget_behaviorsfixtures.
[ericof]Addget_vocabularyfixture.
[ericof]0.1.0 (2023-01-04)Fixturesportal,http_request,installer,browser_layers,controlpanel_actions[ericof]Initial release
[ericof]