diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..f66a2b6 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,6 @@ +[report] +include = + src/collective/* +omit = + */test* + */upgrades/* diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index be4d3c2..957fc9d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,6 +1,8 @@ -# This is a basic workflow to help you get started with Actions +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions -name: CI +name: Push tests +# run-name: ${{ github.actor }} push tests on: push: @@ -8,85 +10,82 @@ on: jobs: test: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: include: - - python: 2.7.18 - plone: 4.3 +# - python: 2.7.18 +# plone: 4.3 +# - python: 3.7.14 +# plone: 5.2 +# - python: 3.10.11 +# plone: "6.0" + - python: 3.13.1 + plone: "6.1" steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up pyenv and Python - uses: "gabrielfalcao/pyenv-action@v14" + uses: "gabrielfalcao/pyenv-action@v18" with: default: "${{ matrix.python }}" - command: pyenv -v - name: Setup Env run: | - pip install -r requirements.txt coverage==5.3.1 + pip install --upgrade pip + pip install -r requirements-${{ matrix.plone }}.txt - name: Cache eggs - uses: actions/cache@v3 + uses: actions/cache@v4 env: cache-name: cache-eggs with: path: ~/buildout-cache/eggs - key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ matrix.plone }} - restore-keys: ${{ runner.os }}-test-${{ env.cache-name }}-${{ matrix.plone }} + key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ matrix.python }}-${{ matrix.plone }} - name: buildout run: | - sed -ie "s#test-4.3#test-${{matrix.plone}}#" buildout.cfg - buildout -c ci.cfg annotate - buildout -c ci.cfg + sed -ie "s#test.cfg#test-${{matrix.plone}}.cfg#" gha.cfg + buildout -c gha.cfg annotate + buildout -c gha.cfg - name: test run: | bin/test -t !robot coverage: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: include: - - python: 2.7.18 - PLONE_VERSION: 4 - continue-on-error: false + - python: 3.10.11 + plone: "6.0" steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up pyenv and Python - uses: "gabrielfalcao/pyenv-action@v14" + uses: "gabrielfalcao/pyenv-action@v18" with: default: "${{ matrix.python }}" - command: pyenv -v - name: Setup Env run: | - pip install -r requirements.txt coverage==5.3.1 + pip install --upgrade pip + pip install -r requirements-${{matrix.plone}}.txt + pip install -U coveralls coverage - name: Cache eggs - uses: actions/cache@v3 + uses: actions/cache@v4 env: cache-name: cache-eggs with: path: ~/buildout-cache/eggs - key: ${{ runner.os }}-coverage-${{ env.cache-name }} - restore-keys: ${{ runner.os }}-coverage-${{ env.cache-name }} + key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ matrix.python }}-${{ matrix.plone }} - name: buildout run: | - buildout -c ci.cfg + sed -ie "s#test.cfg#test-${{matrix.plone}}.cfg#" gha.cfg + buildout -c gha.cfg - name: code-analysis run: | bin/code-analysis - name: test coverage run: | - bin/coverage run bin/test -t !robot - - name: Set up Python 3.8 - uses: actions/setup-python@v2 - with: - python-version: 3.8 - - name: Install Coveralls - run: | - pip3 install -U pip setuptools --no-cache-dir - pip3 install -U "coveralls>=3.0.0" coverage==5.3.1 --no-cache-dir + coverage run bin/test -t !robot - name: Publish to Coveralls env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 0c830e4..663eb06 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ *.pyc .installed.cfg .mr.developer.cfg +.plone.versioncheck.tracked.json .project .pydevproject pyvenv.cfg diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..21bdaa1 --- /dev/null +++ b/Makefile @@ -0,0 +1,97 @@ +#!/usr/bin/make +# pyenv is a requirement, with 3.10, 3.13 python versions, and virtualenv installed in each version +# plone parameter must be passed to create environment 'make setup plone=6.0' or after a make cleanall +# The original Makefile can be found on https://github.com/IMIO/scripts-buildout + +SHELL=/bin/bash +plones=6.0 6.1 +b_o= +old_plone=$(shell [ -e .plone-version ] && cat .plone-version) + +ifeq (, $(shell which pyenv)) + $(error "pyenv command not found! Aborting") +endif + +ifndef plone +ifeq (,$(filter setup,$(MAKECMDGOALS))) + plone=$(old_plone) +endif +endif + +ifneq ($(wildcard bin/instance),) + b_o=-N +endif + +ifndef python +ifeq ($(plone),6.0) + python=3.10 +endif +ifeq ($(plone),6.1) + python=3.13 +endif +endif + +all: buildout + +.PHONY: help +help: + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n\nTargets:\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-10s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST) + +.python-version: ## Setups pyenv version + @pyenv local `pyenv versions |grep " $(python)" |tail -1 |xargs` + @echo "Local pyenv version is `cat .python-version`" + @ if [[ `pyenv which virtualenv` != `pyenv prefix`* ]] ; then echo "You need to install virtualenv in `cat .python-version` pyenv python (pip install virtualenv)"; exit 1; fi + +bin/buildout: .python-version ## Setups environment + virtualenv . + ./bin/pip install --upgrade pip + ./bin/pip install -r requirements-$(plone).txt + @echo "$(plone)" > .plone-version + +.PHONY: setup +setup: oneof-plone backup cleanall bin/buildout restore ## Setups environment + +.PHONY: buildout +buildout: oneof-plone bin/buildout ## Runs setup and buildout + rm -f .installed.cfg .mr.developer.cfg + bin/buildout -t 5 -c test-$(plone).cfg ${b_o} + +.PHONY: test +test: oneof-plone bin/buildout ## run bin/test without robot + # can be run by example with: make test opt='-t "settings"' + bin/test -t \!robot ${opt} + +.PHONY: cleanall +cleanall: ## Cleans all installed buildout files + rm -fr bin include lib local share develop-eggs downloads eggs parts .installed.cfg .mr.developer.cfg .python-version pyvenv.cfg + +.PHONY: backup +backup: ## Backups db files + @if [ '$(old_plone)' != '' ] && [ -f var/filestorage/Data.fs ]; then mv var/filestorage/Data.fs var/filestorage/Data.fs.$(old_plone); mv var/blobstorage var/blobstorage.$(old_plone); fi + +.PHONY: restore +restore: ## Restores db files + @if [ '$(plone)' != '' ] && [ -f var/filestorage/Data.fs.$(plone) ]; then mv var/filestorage/Data.fs.$(plone) var/filestorage/Data.fs; mv var/blobstorage.$(plone) var/blobstorage; fi + +.PHONY: which-python +which-python: oneof-plone ## Displays versions information + @echo "current plone = $(old_plone)" + @echo "current python = `cat .python-version`" + @echo "plone var = $(plone)" + @echo "python var = $(python)" + +.PHONY: vcr +vcr: ## Shows requirements in checkversion-r.html + @bin/versioncheck -rbo checkversion-r-$(plone).html test-$(plone).cfg + +.PHONY: vcn +vcn: ## Shows newer packages in checkversion-n.html + @bin/versioncheck -npbo checkversion-n-$(plone).html test-$(plone).cfg + +.PHONY: guard-% +guard-%: + @ if [ "${${*}}" = "" ]; then echo "You must give a value for variable '$*' : like $*=xxx"; exit 1; fi + +.PHONY: oneof-% +oneof-%: + @ if ! echo "${${*}s}" | tr " " '\n' |grep -Fqx "${${*}}"; then echo "Invalid '$*' parameter ('${${*}}') : must be one of '${${*}s}'"; exit 1; fi diff --git a/README.rst b/README.rst index cfd7e3b..e6b9696 100644 --- a/README.rst +++ b/README.rst @@ -6,12 +6,13 @@ Features -------- This behavior adds some metadata related to scanning: -* scan_id : scan identification as a barcode -* version : version number -* pages_number : pages number -* scan_date : scan date -* scan_user : scan user -* scanner : scanner or pc information + +- scan_id : scan identification as a barcode +- version : version number +- pages_number : pages number +- scan_date : scan date +- scan_user : scan user +- scanner : scanner or pc information Translations ------------ @@ -36,6 +37,12 @@ Install collective.dms.scanbehavior by adding it to your buildout:: and then running "bin/buildout" +Versions +-------- + +- Version 2.x is for Plone 6+ only +- Version 1.x is for Plone 4 + Contribute ---------- diff --git a/base.cfg b/base.cfg new file mode 100644 index 0000000..238335a --- /dev/null +++ b/base.cfg @@ -0,0 +1,103 @@ +[buildout] +package-name = collective.dms.scanbehavior +package-extras = [test] + +extends = + https://raw.githubusercontent.com/collective/buildout.plonetest/master/qa.cfg + checkouts.cfg + +extensions = + mr.developer + plone.versioncheck + +parts += + instance + omelette + ploneversioncheck + createcoverage + robot +# coverage +# test-coverage +# plone-helper-scripts + +develop = . + +eggs += + Plone + Pillow +# Products.PDBDebugMode +# collective.profiler +# ipdb + pdbp +# plone.reload + +package-extras += + pdbp + +always-checkout = force + +[instance] +environment-vars += + PYTHONBREAKPOINT pdbp.set_trace +eggs += + ${buildout:eggs} +zcml += + +[test] +environment = testenv +initialization += + os.environ['PYTHONBREAKPOINT'] = 'pdbp.set_trace' + +[testenv] +zope_i18n_compile_mo_files = true + +[omelette] +recipe = collective.recipe.omelette +eggs = ${test:eggs} + +[ploneversioncheck] +recipe = zc.recipe.egg +eggs = plone.versioncheck + +[code-analysis] +recipe = plone.recipe.codeanalysis +pre-commit-hook = True +return-status-codes = True +directory = ${buildout:directory}/src/collective/dms/scanbehavior +flake8-ignore = E123,E124,E501,E126,E127,E128,W391,C901,W503,W504 +flake8-extensions = + flake8-isort + +[robot] +recipe = zc.recipe.egg +eggs = + Pillow + ${test:eggs} + plone.app.robotframework[reload, debug] + +[coverage] +recipe = zc.recipe.egg +eggs = coverage + +[test-coverage] +recipe = collective.recipe.template +input = inline: + #!/bin/bash + export TZ=UTC + ${buildout:directory}/bin/coverage run bin/test $* + ${buildout:directory}/bin/coverage html + ${buildout:directory}/bin/coverage report -m --fail-under=90 + # Fail (exit status 1) if coverage returns exit status 2 (this happens + # when test coverage is below 100%. +output = ${buildout:directory}/bin/test-coverage +mode = 755 + +[plone-helper-scripts] +recipe = zc.recipe.egg +eggs = + Products.CMFPlone + ${instance:eggs} +interpreter = zopepy +scripts = + zopepy + plone-compile-resources diff --git a/buildout.cfg b/buildout.cfg deleted file mode 100644 index 3def417..0000000 --- a/buildout.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[buildout] -extends = buildout.d/development.cfg diff --git a/buildout.d/base.cfg b/buildout.d/base.cfg deleted file mode 100644 index c59f887..0000000 --- a/buildout.d/base.cfg +++ /dev/null @@ -1,15 +0,0 @@ -[buildout] -package-name = collective.dms.scanbehavior -package-extras = [test] - -extends = - https://raw.github.com/collective/buildout.plonetest/master/plone-4.3.x.cfg - checkouts.cfg - sources.cfg - versions.cfg - -develop = . - -eggs += - Pillow - ipdb diff --git a/buildout.d/checkouts.cfg b/buildout.d/checkouts.cfg deleted file mode 100644 index d5798b1..0000000 --- a/buildout.d/checkouts.cfg +++ /dev/null @@ -1,3 +0,0 @@ -[buildout] -always-checkout = force -auto-checkout += diff --git a/buildout.d/development.cfg b/buildout.d/development.cfg deleted file mode 100644 index 15fdc12..0000000 --- a/buildout.d/development.cfg +++ /dev/null @@ -1,49 +0,0 @@ -[buildout] -extends = - base.cfg - -eggs += - plone.reload - Products.PDBDebugMode - Products.DocFinderTab - aws.zope2zcmldoc - collective.profiler - -extensions += - mr.developer - -parts += - omelette - code-analysis - test - robot - -show-picked-versions = true - -[omelette] -recipe = collective.recipe.omelette -eggs = ${test:eggs} - -[test] -recipe = zc.recipe.testrunner -eggs = - ${buildout:eggs} - ${buildout:package-name} ${buildout:package-extras} -defaults = ['-s', '${buildout:package-name}', '--auto-color', '--auto-progress'] - -[code-analysis] -recipe = plone.recipe.codeanalysis -pre-commit-hook = True -return-status-codes = True -directory = - ${buildout:directory}/src/collective/dms/scanbehavior -flake8-ignore = E123,E124,E501,E126,E127,E128,W391,W504,C901 -flake8-extensions = - flake8-isort - -[robot] -recipe = zc.recipe.egg -eggs = - Pillow - ${test:eggs} - plone.app.robotframework[ride,reload] diff --git a/buildout.d/jenkins.cfg b/buildout.d/jenkins.cfg deleted file mode 100644 index 42484d2..0000000 --- a/buildout.d/jenkins.cfg +++ /dev/null @@ -1,24 +0,0 @@ -[buildout] -extends = - base.cfg - https://raw.github.com/plone/buildout.jenkins/master/jenkins.cfg - https://raw.github.com/plone/buildout.jenkins/master/jenkins-code-analysis.cfg - -jenkins-test-eggs = ${buildout:package-name} ${buildout:package-extras} -jenkins-test-directories = src/collective/dms/scanbehavior - -parts += pylint - -[pylint] -recipe = zc.recipe.egg -eggs = pylint - ${buildout:eggs} -scripts = pylint -entry-points = pylint=pylint.lint:Run -arguments = [ - '--output-format=parseable', - '--zope=y', - '--reports=y', - '--disable=E0611,F0401,W0232,E1101,C0103,C0111,R0201,W0201,R0911,R0904,F0220,E1103,R0901,E0211,E0213,E1002,W0622,C0301,W0212,R0903', - '--generated-members=objects', - ] + (sys.argv[1:] or ["${buildout:jenkins-test-directories}"]) diff --git a/buildout.d/sources.cfg b/buildout.d/sources.cfg deleted file mode 100644 index 80da679..0000000 --- a/buildout.d/sources.cfg +++ /dev/null @@ -1,17 +0,0 @@ -[remotes] -collective = git://github.com/collective -collective_push = git@github.com:collective -plone = git://github.com/plone -plone_push = git@github.com:plone - -# ================== -# Ecreall developers -# ================== -tdesvenain = git://github.com/tdesvenain -tdesvenain_push = git@github.com:tdesvenain -vincentfretin = git://github.com/vincentfretin -vincentfretin_push = git@github.com:vincentfretin -cedricmessiant = git://github.com/cedricmessiant -cedricmessiant_push = git@github.com:cedricmessiant - -[sources] diff --git a/buildout.d/versions.cfg b/buildout.d/versions.cfg deleted file mode 100644 index 8316aab..0000000 --- a/buildout.d/versions.cfg +++ /dev/null @@ -1,35 +0,0 @@ -[versions] -setuptools = 44.1.1 -zc.buildout = 2.13.3 -zc.recipe.egg = 2.0.0 - -backports.functools-lru-cache = 1.5 -robotframework = 2.8.4 -#robotframework-ride = 1.1 -#robotframework-selenium2library = 1.2.0 -robotsuite = 1.4.3 -robotframework-debuglibrary = 0.3 - -selenium = 2.41.0 -Babel = 1.3 -Products.DocFinderTab = 1.0.5 -Products.PDBDebugMode = 1.3.1 -PyYAML = 3.10 -argh = 0.24.1 -aws.zope2zcmldoc = 1.1.0 -collective.profiler = 0.3 -ecreall.helpers.testing = 1.6 -ipdb = 0.8 -ipython = 1.1.0 -pathtools = 0.1.2 -plone.app.robotframework = 0.8.5 -watchdog = 0.7.0 - -# Required by: -# collective.profiler==0.3 -profilehooks = 1.7 - -pep517 = 0.12.0 -flake8-isort = 4.0.0 -isort = 4.3.21 -flake8 = 3.8.3 diff --git a/checkouts.cfg b/checkouts.cfg new file mode 100644 index 0000000..3ace1f3 --- /dev/null +++ b/checkouts.cfg @@ -0,0 +1,19 @@ +[buildout] +always-checkout = force +auto-checkout += + +[remotes] +imio = https://github.com/imio +imio_push = git@github.com:imio +plone = https://github.com/plone +plone_push = git@github.com:plone +ftw = https://github.com/4teamwork +ftw_push = git@github.com:4teamwork +zopefoundation = https://github.com/zopefoundation +zopefoundation_push = git@github.com:zopefoundation +zopesvn = svn://svn.zope.org/repos/main/ +collective = https://github.com/collective +collective_push = git@github.com:collective + +[sources] +imio.helpers = git ${remotes:imio}/imio.helpers.git pushurl=${remotes:imio_push}/imio.helpers.git diff --git a/ci.cfg b/ci.cfg deleted file mode 100644 index c3781f9..0000000 --- a/ci.cfg +++ /dev/null @@ -1,14 +0,0 @@ -[buildout] -extends = - buildout.cfg -eggs-directory = ~/buildout-cache/eggs - -parts += - createcoverage - -[createcoverage] -recipe = zc.recipe.egg -eggs = createcoverage - -[versions] -coverage = 5.3.1 \ No newline at end of file diff --git a/gha.cfg b/gha.cfg new file mode 100644 index 0000000..ef2e218 --- /dev/null +++ b/gha.cfg @@ -0,0 +1,5 @@ +[buildout] +extends = + test.cfg +eggs-directory = ~/buildout-cache/eggs +download-cache = ~/buildout-cache/downloads diff --git a/requirements-6.0.txt b/requirements-6.0.txt new file mode 100644 index 0000000..75ae54c --- /dev/null +++ b/requirements-6.0.txt @@ -0,0 +1,3 @@ +-c https://dist.plone.org/release/6.0-latest/requirements.txt +setuptools +zc.buildout diff --git a/requirements-6.1.txt b/requirements-6.1.txt new file mode 100644 index 0000000..aaf0495 --- /dev/null +++ b/requirements-6.1.txt @@ -0,0 +1,3 @@ +-c https://dist.plone.org/release/6.1-latest/requirements.txt +setuptools +zc.buildout diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index edde950..0000000 --- a/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -pip==20.3.4 -setuptools==44.1.1 -zc.buildout==2.13.3 -wheel \ No newline at end of file diff --git a/setup.py b/setup.py index 470f76e..728cf3b 100644 --- a/setup.py +++ b/setup.py @@ -25,16 +25,26 @@ classifiers=[ "Environment :: Web Environment", "Framework :: Plone", - "Framework :: Plone :: 4.3", + "Framework :: Plone :: Addon", + "Framework :: Plone :: 6.0", + "Framework :: Plone :: 6.1", + "Intended Audience :: Developers", + "License :: OSI Approved :: GNU General Public License v2 (GPLv2)", + "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Topic :: Software Development :: Libraries :: Python Modules", ], keywords="Python Zope Plone", author="Franck NGAHA, Stephan Geulette", author_email="franck.o.ngaha@gmail.com, sgeulette@imio.be", url="http://pypi.python.org/pypi/collective.dms.scanbehavior", license="GPL", - packages=find_packages("src", exclude=["ez_setup"]), + packages=find_packages("src"), namespace_packages=["collective", "collective.dms"], package_dir={"": "src"}, include_package_data=True, @@ -44,7 +54,6 @@ "setuptools", "plone.app.dexterity", "plone.behavior", - "plone.directives.form", "zope.schema", "zope.interface", "zope.component", diff --git a/src/collective/dms/scanbehavior/behaviors/behaviors.py b/src/collective/dms/scanbehavior/behaviors/behaviors.py index 2224a8f..9608298 100755 --- a/src/collective/dms/scanbehavior/behaviors/behaviors.py +++ b/src/collective/dms/scanbehavior/behaviors/behaviors.py @@ -2,10 +2,10 @@ from collective.dms.scanbehavior import _ from plone.autoform.interfaces import IFormFieldProvider +from plone.base.utils import base_hasattr from plone.indexer import indexer from plone.supermodel import model -from Products.CMFPlone.utils import base_hasattr -from Products.PluginIndexes.common.UnIndex import _marker +from Products.ZCatalog.ZCatalogIndexes import _marker from zope import schema from zope.interface import alsoProvides @@ -16,7 +16,7 @@ class IScanFields(model.Schema): model.fieldset( "scan", - label=_(u"Scan"), + label=_("Scan"), fields=( "scan_id", "version", @@ -31,26 +31,26 @@ class IScanFields(model.Schema): scan_id = schema.TextLine( title=_( - u"scan_id", - default=u"Scan id", + "scan_id", + default="Scan id", ), required=False, ) - version = schema.Int(title=_(u"Version"), required=False, default=0) + version = schema.Int(title=_("Version"), required=False, default=0) pages_number = schema.Int( title=_( - u"pages_number", - default=u"Pages numbers", + "pages_number", + default="Pages numbers", ), required=False, ) scan_date = schema.Datetime( title=_( - u"scan_date", - default=u"Scan date", + "scan_date", + default="Scan date", ), required=False, min=datetime.datetime(1990, 1, 1), @@ -59,28 +59,30 @@ class IScanFields(model.Schema): scan_user = schema.TextLine( title=_( - u"scan_user", - default=u"Scan user", + "scan_user", + default="Scan user", ), required=False, ) scanner = schema.TextLine( title=_( - u"scanner", - default=u"scanner", + "scanner", + default="scanner", ), required=False, ) to_sign = schema.Bool( - title=_(u"To sign?"), + title=_("To sign?"), default=False, + required=False, ) signed = schema.Bool( - title=_(u"Signed version"), + title=_("Signed version"), default=False, + required=False, ) diff --git a/src/collective/dms/scanbehavior/behaviors/configure.zcml b/src/collective/dms/scanbehavior/behaviors/configure.zcml index 6b881dd..2b6687e 100644 --- a/src/collective/dms/scanbehavior/behaviors/configure.zcml +++ b/src/collective/dms/scanbehavior/behaviors/configure.zcml @@ -6,9 +6,6 @@ - - - - + diff --git a/src/collective/dms/scanbehavior/profiles/uninstall/browserlayer.xml b/src/collective/dms/scanbehavior/profiles/uninstall/browserlayer.xml new file mode 100644 index 0000000..593a0d1 --- /dev/null +++ b/src/collective/dms/scanbehavior/profiles/uninstall/browserlayer.xml @@ -0,0 +1,8 @@ + + + + diff --git a/src/collective/dms/scanbehavior/profiles/uninstall/catalog.xml b/src/collective/dms/scanbehavior/profiles/uninstall/catalog.xml new file mode 100644 index 0000000..1fc5126 --- /dev/null +++ b/src/collective/dms/scanbehavior/profiles/uninstall/catalog.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/collective/dms/scanbehavior/testing.py b/src/collective/dms/scanbehavior/testing.py index f42a5e0..7501724 100644 --- a/src/collective/dms/scanbehavior/testing.py +++ b/src/collective/dms/scanbehavior/testing.py @@ -19,156 +19,6 @@ class CollectiveDmsScanbehaviorLayer(PloneSandboxLayer): - PLONE_FIXTURE.products = ( - ( - "Products.GenericSetup", - {"loadZCML": True}, - ), - ( - "Products.DCWorkflow", - {"loadZCML": True}, - ), - ( - "Products.ZCTextIndex", - {"loadZCML": True}, - ), - ( - "Products.CMFActionIcons", - {"loadZCML": True}, - ), - ( - "Products.CMFUid", - {"loadZCML": True}, - ), - ( - "Products.CMFCalendar", - {"loadZCML": True}, - ), - ( - "Products.CMFCore", - {"loadZCML": True}, - ), - ( - "Products.CMFDefault", - {"loadZCML": True}, - ), - ( - "Products.PluggableAuthService", - {"loadZCML": True}, - ), - ( - "Products.PluginRegistry", - {"loadZCML": True}, - ), - ( - "Products.PlonePAS", - {"loadZCML": True}, - ), - ( - "Products.CMFQuickInstallerTool", - {"loadZCML": True}, - ), - ( - "Products.CMFFormController", - {"loadZCML": True}, - ), - ( - "Products.CMFDynamicViewFTI", - {"loadZCML": True}, - ), - ( - "Products.Archetypes", - {"loadZCML": True}, - ), - ( - "Products.MimetypesRegistry", - {"loadZCML": True}, - ), - ( - "Products.PortalTransforms", - {"loadZCML": True}, - ), - ( - "Products.ATContentTypes", - {"loadZCML": True}, - ), - ( - "Products.ATReferenceBrowserWidget", - {"loadZCML": True}, - ), - ( - "Products.ExternalEditor", - {"loadZCML": True}, - ), - ( - "Products.ExtendedPathIndex", - {"loadZCML": True}, - ), - ( - "Products.ResourceRegistries", - {"loadZCML": True}, - ), - ( - "Products.SecureMailHost", - {"loadZCML": True}, - ), - ( - "Products.PasswordResetTool", - {"loadZCML": True}, - ), - ( - "Products.TinyMCE", - {"loadZCML": True}, - ), - ( - "Products.CMFEditions", - {"loadZCML": True}, - ), - ( - "Products.CMFDiffTool", - {"loadZCML": True}, - ), - ( - "Products.PlacelessTranslationService", - {"loadZCML": True}, - ), - ( - "Products.PloneLanguageTool", - {"loadZCML": True}, - ), - ( - "plonetheme.classic", - {"loadZCML": True}, - ), - ( - "plonetheme.sunburst", - {"loadZCML": True}, - ), - ( - "plone.app.blob", - {"loadZCML": True}, - ), - ( - "plone.app.imaging", - {"loadZCML": True}, - ), - ( - "plone.app.collection", - {"loadZCML": True}, - ), - ( - "plone.app.dexterity", - {"loadZCML": True}, - ), - ( - "Products.CMFPlone", - {"loadZCML": True}, - ), - ( - "Products.PythonScripts", - {"loadZCML": False}, - ), - ) defaultBases = (PLONE_FIXTURE,) def setUpZope(self, app, configurationContext): diff --git a/src/collective/dms/scanbehavior/tests/robot/test_scanbehavior.robot b/src/collective/dms/scanbehavior/tests/robot/test_scanbehavior.robot deleted file mode 100644 index 30f874f..0000000 --- a/src/collective/dms/scanbehavior/tests/robot/test_scanbehavior.robot +++ /dev/null @@ -1,46 +0,0 @@ -*** Settings *** - -Resource plone/app/robotframework/keywords.robot -Resource plone/app/robotframework/selenium.robot - -Library Selenium2Library timeout=10 implicit_wait=0.5 -Library plone.app.robotframework.keywords.Debugging -Library Remote ${PLONE_URL}/RobotRemote - -Suite Setup Start browser -Suite Teardown Close All Browsers - -*** Variables *** - -${BROWSER} = firefox -${MANAGER} = Manager - -*** Test Cases *** - -Plone site - [Tags] start - Go to http://localhost:55001/plone/ - Page should contain Plone site - Enable autologin as ${MANAGER} - Maximize Browser Window - Reload Page - CLick Link user-name - Click Link ${PLONE_URL}/@@overview-controlpanel - Click Link ${PLONE_URL}/@@dexterity-types - Click Element add-type - Input Text form-widgets-title dms document - Input Text form-widgets-description document management system - Click Element form-buttons-add - Go to ${PLONE_URL}/dexterity-types/dms_document/@@behaviors - Select Checkbox form-widgets-collective-dms-scanbehavior-behaviors-behaviors-IScan-0 - Click Element form-buttons-apply - CLick Link folder - Click link ${PLONE_URL}/folder/folder_factories - CLick Link dms_document - Page Should Contain Link fieldsetlegend-3 - Click Link fieldsetlegend-3 - -*** Keywords *** - -Start browser - Open browser http://localhost:55001/plone/ browser=${BROWSER} diff --git a/src/collective/dms/scanbehavior/tests/test_behavior.py b/src/collective/dms/scanbehavior/tests/test_behavior.py new file mode 100644 index 0000000..9e9fe4f --- /dev/null +++ b/src/collective/dms/scanbehavior/tests/test_behavior.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +from collective.dms.scanbehavior.behaviors.behaviors import IScanFields +from collective.dms.scanbehavior.behaviors.behaviors import scan_id_indexer +from collective.dms.scanbehavior.testing import INTEGRATION +from Products.ZCatalog.ZCatalogIndexes import _marker +from zope.interface import alsoProvides +from zope.schema import getFieldsInOrder + +import datetime +import unittest + + +class Dummy(object): + pass + + +class TestBehaviorSchema(unittest.TestCase): + layer = INTEGRATION + + def test_scan_date(self): + fields = dict(getFieldsInOrder(IScanFields)) + scan_date = fields["scan_date"] + self.assertEqual(scan_date.min, datetime.datetime(1990, 1, 1)) + today = datetime.datetime.today() + self.assertGreaterEqual(scan_date.max, today) + self.assertLessEqual(scan_date.max, today + datetime.timedelta(days=8)) + + +class TestIndexer(unittest.TestCase): + layer = INTEGRATION + + def make_obj(self, **attrs): + obj = Dummy() + for k, v in list(attrs.items()): + setattr(obj, k, v) + alsoProvides(obj, IScanFields) + return obj + + def test_scan_id(self): + obj = self.make_obj(scan_id="ABC-123") + self.assertEqual(scan_id_indexer(obj)(), "ABC-123") + obj = self.make_obj() + self.assertIs(scan_id_indexer(obj)(), _marker) + obj = self.make_obj(scan_id="") + self.assertIs(scan_id_indexer(obj)(), _marker) + obj = self.make_obj(scan_id=None) + self.assertIs(scan_id_indexer(obj)(), _marker) diff --git a/src/collective/dms/scanbehavior/tests/test_setup.py b/src/collective/dms/scanbehavior/tests/test_setup.py index e3e6dd0..90811b0 100644 --- a/src/collective/dms/scanbehavior/tests/test_setup.py +++ b/src/collective/dms/scanbehavior/tests/test_setup.py @@ -2,7 +2,7 @@ """Setup/installation tests for this package.""" from collective.dms.scanbehavior.testing import IntegrationTestCase -from plone import api +from plone.base.utils import get_installer class TestInstall(IntegrationTestCase): @@ -11,19 +11,20 @@ class TestInstall(IntegrationTestCase): def setUp(self): """Custom shared utility setup for tests.""" self.portal = self.layer["portal"] - self.installer = api.portal.get_tool("portal_quickinstaller") + self.request = self.layer["request"] + self.installer = get_installer(self.portal, self.request) def test_product_installed(self): - """Test if collective.dms.scanbehavior is installed with portal_quickinstaller.""" + """Test if collective.dms.scanbehavior is installed.""" self.assertTrue( - self.installer.isProductInstalled("collective.dms.scanbehavior") + self.installer.is_product_installed("collective.dms.scanbehavior") ) def test_uninstall(self): """Test if collective.dms.scanbehavior is cleanly uninstalled.""" - self.installer.uninstallProducts(["collective.dms.scanbehavior"]) + self.installer.uninstall_product("collective.dms.scanbehavior") self.assertFalse( - self.installer.isProductInstalled("collective.dms.scanbehavior") + self.installer.is_product_installed("collective.dms.scanbehavior") ) # browserlayer.xml diff --git a/src/collective/dms/scanbehavior/upgrades.py b/src/collective/dms/scanbehavior/upgrades.py index b8e0086..f8b9a4b 100644 --- a/src/collective/dms/scanbehavior/upgrades.py +++ b/src/collective/dms/scanbehavior/upgrades.py @@ -1,32 +1,6 @@ # -*- coding: utf-8 -*- -from plone import api -from plone.dexterity.interfaces import IDexterityFTI import logging logger = logging.getLogger("collective.dms.scanbehavior: upgrade. ") - - -def v2(context): - setup = api.portal.get_tool("portal_setup") - setup.runImportStepFromProfile( - "profile-collective.dms.scanbehavior:default", "catalog" - ) - catalog = api.portal.get_tool("portal_catalog") - ftis = api.portal.get_tool("portal_types") - types = [] - for fti in ftis.listTypeInfo(): - if ( - IDexterityFTI.providedBy(fti) - and "collective.dms.scanbehavior.behaviors.behaviors.IScanFields" - in fti.behaviors - ): - types.append(fti.getId()) - - nb = 0 - for brain in catalog.searchResults(portal_type=types): - nb += 1 - obj = brain.getObject() - obj.reindexObject(idxs=["signed"]) - logger.info("%d objects were migrated" % nb) diff --git a/test-6.0.cfg b/test-6.0.cfg new file mode 100644 index 0000000..fbdb8a1 --- /dev/null +++ b/test-6.0.cfg @@ -0,0 +1,30 @@ +[buildout] + +extends = + https://raw.githubusercontent.com/collective/buildout.plonetest/master/test-6.0.x.cfg + base.cfg + +update-versions-file = test-6.0.cfg + +[versions] +# to keep prompt-toolkit < 3 +ipython = 8.3.0 + +ipdb = 0.13.9 +iw.debug = 0.3 +jedi = 0.18.1 +parso = 0.8.3 +pdbp = 1.7.0 + +# Required by: +# ipdb +asttokens = 2.0.8 +backcall = 0.2.0 +executing = 1.1.1 +matplotlib-inline = 0.1.6 +pexpect = 4.8.0 +pickleshare = 0.7.5 +ptyprocess = 0.7.0 +pure-eval = 0.2.2 +stack-data = 0.5.1 +traitlets = 5.4.0 diff --git a/test-6.1.cfg b/test-6.1.cfg new file mode 100644 index 0000000..d708207 --- /dev/null +++ b/test-6.1.cfg @@ -0,0 +1,30 @@ +[buildout] + +extends = + https://raw.githubusercontent.com/collective/buildout.plonetest/master/test-6.1.x.cfg + base.cfg + +#update-versions-file = test-6.1.cfg + +[versions] +# to keep prompt-toolkit < 3 +ipython = 8.3.0 + +ipdb = 0.13.9 +iw.debug = 0.3 +jedi = 0.18.1 +parso = 0.8.3 +pdbp = 1.7.0 + +# Required by: +# ipdb +asttokens = 2.0.8 +backcall = 0.2.0 +executing = 1.1.1 +matplotlib-inline = 0.1.6 +pexpect = 4.8.0 +pickleshare = 0.7.5 +ptyprocess = 0.7.0 +pure-eval = 0.2.2 +stack-data = 0.5.1 +traitlets = 5.4.0