For my project, I have been working on an add-on package and for this first we have to setup that add-on package to start working on it. So we created an add-on package named experimental.safe_html_transform.
We have to set the testing enviornment, Generic setup of profiles, setup for default and uninstall profiles, setting up browser layer, setting up filter control panel for the browser layer, generic setup for the filter control panel. So these are the few of the essential things that have to be configured for setting up add-on and are part of the project. We will discuss each and everything in the blog,how we setup these things and what are the things I have referred for setting up these things. So lets start...
For setting up testing environment we have to add plone.app.testing in the setting files so that we have create automated tests also robot tests for the add-on. Here is the code to be added in the setup.py
extras_require={
'test': [
'plone.app.testing',
'plone.app.contenttypes',
'plone.app.robotframework[debug]',
],
},
This will help in adding all the three packages that are required for setting up testing environment.
After that we have to setup base module for unit testing, we will set up the base module in testing.py
After that we will have our test module and we will write robot test as well as unit test in that module only. Robot test will test the plone site on robot server and check if its working or not. On the other hand we can check the functionalities of our add-on using unit tests. We will also write some integration tests for the setup like test if product is installed correctly, browser layer is setup correctly etc.
After that we will be left with writing unit tests to test the transform script and checks its accuracy using as much as possible test cases. This is the basic overview of setting up the testing environment for the add-on. The documentation for the testing is too good. It really helps me a lot in understanding about the flow of setting up testing module and how it works.
For testing we just have to write "./bin/test --all" (for all tests including robot and unit tests) and "./bin/code-analysis" for checking the code using flake8 code analysis.
After setting up testing environment we will do the generic setup of profiles for our add-on.
What is Generic Setup ?
GenericSetup is an XML-based way to import and export Plone site configurations. It is mainly used to prepare the Plone site for add-on products, by: registering CSS files, registering Javascript files, etc.
So we will also configure generic setup for the profiles of our add-on.
We will write the generic setup in configuration.zcml file (zope configuration) for "default" and "unregister" profile. Here is the snippet for the xml code for generic setup.
<genericsetup:registerProfile
name="default"
title="experimental.safe_html_transform"
directory="profiles/default"
description="Installs the experimental.safe_html_transform add-on."
provides="Products.GenericSetup.interfaces.EXTENSION"
/>
<genericsetup:registerProfile
name="uninstall"
title="experimental.safe_html_transform uninstall"
directory="profiles/uninstall"
description="Uninstalls the experimental.safe_html_transform package"
provides="Products.GenericSetup.interfaces.EXTENSION"
/>
After that we have registered the profiles by the generic way, now we have to create two profiles, one is default and other is uninstall.
Default profile contains thing that have to be done when the add-on is installed and unisntall profile contains the things that have to be done post uninstallation of our add-on.
First lets create a default profile, in that profile we will have to set up the browser layer, control panel for browser, metadata and registry and also note that all these files will be .xml, so here also we will xml to setup these things for a particular profile. You can have a look at the profile setup of my add-on .
Similarly we will create an uninstall profile, for creating uninstall profiles in plone there is a great blog written by keul. That is a good way to understand how to uninstall profile and that helped me a lot. With the help of that blog I have created a unistall profile for the add-on.
After that we have created testing environment, generic setup for add-on, setting up profiles ( default and uninstall) . Still we are left with setup for browser layer and setting up filter control panel for the browser layer. So lets do it...
After that we will setup Browser layer by generic set up for the filter control panel. We will create a browser layer interface so that our add-on can run cross browser and this can be done in the interface.py where all the interface lives. Here is the snippet for the same
class IExperimentalSafeHtmlTransformLayer(IDefaultBrowserLayer):
"""Marker interface that defines a browser layer."""
This will create a browser layer for an add-on and we can run our add-on over the browsers. This is really a nice thing ;).
As now browser layer is setup now we will set up the filter control panel for the add-on through generic setup in the configuration.zcml file inside the browser module. Here is the snippet of the code
<!-- Filter Control Panel -->
<browser:page
name="filter-controlpanel"
for=".controlpanel.IPloneSiteRoot"
layer="..interfaces.IExperimentalSafeHtmlTransformLayer"
class=".controlpanel.FilterControlPanel"
permission="plone.app.controlpanel.Filtering"
/>
This will setup the filter control panel for the browser layer now we will configure the control panel that has been set up for the browser layer just above. This will be done in the controlpanel.py file under the browser module. You can check the code on github.The control panel will be set up through the API only and this way we have set up the control panel for the browser layer and we have also configure the control panel. This way we have set up the basic requirements of the add-on. This is just the start and we have set up the add-on. Now the main focus will be on writing the transform for filtering html using lxml. That thing will be included in the next blog.
Hope it helps you and you enjoyed reading it. It is just a start and lot more yet to come, lot more yet to learn and lot more yet to develop.
Cheers!!
Happy coding :)
We have to set the testing enviornment, Generic setup of profiles, setup for default and uninstall profiles, setting up browser layer, setting up filter control panel for the browser layer, generic setup for the filter control panel. So these are the few of the essential things that have to be configured for setting up add-on and are part of the project. We will discuss each and everything in the blog,how we setup these things and what are the things I have referred for setting up these things. So lets start...
For setting up testing environment we have to add plone.app.testing in the setting files so that we have create automated tests also robot tests for the add-on. Here is the code to be added in the setup.py
extras_require={
'test': [
'plone.app.testing',
'plone.app.contenttypes',
'plone.app.robotframework[debug]',
],
},
This will help in adding all the three packages that are required for setting up testing environment.
After that we have to setup base module for unit testing, we will set up the base module in testing.py
After that we will have our test module and we will write robot test as well as unit test in that module only. Robot test will test the plone site on robot server and check if its working or not. On the other hand we can check the functionalities of our add-on using unit tests. We will also write some integration tests for the setup like test if product is installed correctly, browser layer is setup correctly etc.
After that we will be left with writing unit tests to test the transform script and checks its accuracy using as much as possible test cases. This is the basic overview of setting up the testing environment for the add-on. The documentation for the testing is too good. It really helps me a lot in understanding about the flow of setting up testing module and how it works.
For testing we just have to write "./bin/test --all" (for all tests including robot and unit tests) and "./bin/code-analysis" for checking the code using flake8 code analysis.
After setting up testing environment we will do the generic setup of profiles for our add-on.
What is Generic Setup ?
GenericSetup is an XML-based way to import and export Plone site configurations. It is mainly used to prepare the Plone site for add-on products, by: registering CSS files, registering Javascript files, etc.
So we will also configure generic setup for the profiles of our add-on.
We will write the generic setup in configuration.zcml file (zope configuration) for "default" and "unregister" profile. Here is the snippet for the xml code for generic setup.
<genericsetup:registerProfile
name="default"
title="experimental.safe_html_transform"
directory="profiles/default"
description="Installs the experimental.safe_html_transform add-on."
provides="Products.GenericSetup.interfaces.EXTENSION"
/>
<genericsetup:registerProfile
name="uninstall"
title="experimental.safe_html_transform uninstall"
directory="profiles/uninstall"
description="Uninstalls the experimental.safe_html_transform package"
provides="Products.GenericSetup.interfaces.EXTENSION"
/>
After that we have registered the profiles by the generic way, now we have to create two profiles, one is default and other is uninstall.
Default profile contains thing that have to be done when the add-on is installed and unisntall profile contains the things that have to be done post uninstallation of our add-on.
First lets create a default profile, in that profile we will have to set up the browser layer, control panel for browser, metadata and registry and also note that all these files will be .xml, so here also we will xml to setup these things for a particular profile. You can have a look at the profile setup of my add-on .
Similarly we will create an uninstall profile, for creating uninstall profiles in plone there is a great blog written by keul. That is a good way to understand how to uninstall profile and that helped me a lot. With the help of that blog I have created a unistall profile for the add-on.
After that we have created testing environment, generic setup for add-on, setting up profiles ( default and uninstall) . Still we are left with setup for browser layer and setting up filter control panel for the browser layer. So lets do it...
After that we will setup Browser layer by generic set up for the filter control panel. We will create a browser layer interface so that our add-on can run cross browser and this can be done in the interface.py where all the interface lives. Here is the snippet for the same
class IExperimentalSafeHtmlTransformLayer(IDefaultBrowserLayer):
"""Marker interface that defines a browser layer."""
This will create a browser layer for an add-on and we can run our add-on over the browsers. This is really a nice thing ;).
As now browser layer is setup now we will set up the filter control panel for the add-on through generic setup in the configuration.zcml file inside the browser module. Here is the snippet of the code
<!-- Filter Control Panel -->
<browser:page
name="filter-controlpanel"
for=".controlpanel.IPloneSiteRoot"
layer="..interfaces.IExperimentalSafeHtmlTransformLayer"
class=".controlpanel.FilterControlPanel"
permission="plone.app.controlpanel.Filtering"
/>
This will setup the filter control panel for the browser layer now we will configure the control panel that has been set up for the browser layer just above. This will be done in the controlpanel.py file under the browser module. You can check the code on github.The control panel will be set up through the API only and this way we have set up the control panel for the browser layer and we have also configure the control panel. This way we have set up the basic requirements of the add-on. This is just the start and we have set up the add-on. Now the main focus will be on writing the transform for filtering html using lxml. That thing will be included in the next blog.
Hope it helps you and you enjoyed reading it. It is just a start and lot more yet to come, lot more yet to learn and lot more yet to develop.
Cheers!!
Happy coding :)
Comments
Post a Comment