Skip to content

Commit

Permalink
Merge c2fac0f into 2a9603d
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Jul 11, 2018
2 parents 2a9603d + c2fac0f commit 04bfcbc
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
language: python
sudo: false
dist: trusty
python:
- "2.7"
- "3.5"
- "3.6"
install:
- pip install zc.buildout coverage coveralls
- buildout bootstrap
Expand Down
8 changes: 7 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ History
2.0 (unreleased)
----------------

- some code cleanup [jensens, 2016-06-14]
- Add support for ``Products.ZCatalog >= 4`` while dropping support for older
versions. [icemac, 2018-07-11]

- Add support for Python 3.5 and Python 3.6 on Zope 4. While dropping support
for older Zope versions. [icemac, 2018-07-11]

- Remove dependency from `Globals` for Zope 4 compat. [sallner, 2017-08-21]

- some code cleanup [jensens, 2016-06-14]

1.3
---

Expand Down
5 changes: 2 additions & 3 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ parts =
test
omelette

extends = http://dist.plone.org/release/5-latest/versions.cfg
extends = https://zopefoundation.github.io/Zope/releases/master/versions-prod.cfg

[test]
recipe = zc.recipe.testrunner
eggs =
Products.DateRangeInRangeIndex[test,gs]

defaults = ['-v', '--auto-progress']
defaults = ['-v']

[omelette]
recipe = collective.recipe.omelette
Expand Down
14 changes: 11 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


version = '2.0.dev0'
shortdesc = 'zope index to query a daterange on objects with a daterange'
shortdesc = 'Zope index to query a daterange on objects with a daterange'
longdesc = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
longdesc += open(os.path.join(os.path.dirname(__file__), 'CHANGES.rst')).read()
longdesc += open(os.path.join(os.path.dirname(__file__), 'LICENSE.rst')).read()
Expand All @@ -20,7 +20,14 @@
classifiers=[
'Development Status :: 5 - Production/Stable',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Framework :: Zope :: 2',
'Framework :: Zope :: 3',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Software Development',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'License :: OSI Approved :: BSD License',
Expand All @@ -37,7 +44,8 @@
install_requires=[
'AccessControl',
'setuptools',
'Zope2',
'Zope',
'Products.ZCatalog >= 4.0a2',
'zope.catalog',
],
tests_require=tests_require,
Expand Down
2 changes: 1 addition & 1 deletion src/Products/DateRangeInRangeIndex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def initialize(context):
import index
from . import index
context.registerClass(
index.DateRangeInRangeIndex,
permission='Add Pluggable Index',
Expand Down
23 changes: 11 additions & 12 deletions src/Products/DateRangeInRangeIndex/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from BTrees.IIBTree import intersection
from BTrees.IIBTree import multiunion
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Products.PluginIndexes.common.UnIndex import UnIndex
from Products.PluginIndexes.common.util import parseIndexRequest
from OFS.SimpleItem import SimpleItem
from Products.ZCatalog.Catalog import Catalog
from zope.interface import implementer

Expand All @@ -35,7 +34,7 @@ def manage_addDRIRIndex(self, id, extra=None, REQUEST=None, RESPONSE=None,


@implementer(IDateRangeInRangeIndex)
class DateRangeInRangeIndex(UnIndex):
class DateRangeInRangeIndex(SimpleItem):
"""
"""
meta_type = "DateRangeInRangeIndex"
Expand All @@ -48,13 +47,14 @@ class DateRangeInRangeIndex(UnIndex):
)
manage_main = PageTemplateFile('www/manageDRIRIndex', globals())
query_options = ['start', 'end']
operators = ('',)
useOperator = ''

startindex = endindex = None

def __init__(self, id, ignore_ex=None, call_methods=None,
extra=None, caller=None):
UnIndex.__init__(self, id, ignore_ex=None, call_methods=None,
extra=None, caller=None)
self.id = id
self.caller = caller
if extra is None:
return
Expand All @@ -67,7 +67,7 @@ def __init__(self, id, ignore_ex=None, call_methods=None,
# from code)
self.startindex = extra['startindex']
self.endindex = extra['endindex']
except AttributeError:
except KeyError:
raise ValueError(
'DateRangeInRangeIndex needs \'extra\' kwarg with keys or '
'attributes \'startindex\' and \'endindex\' '
Expand All @@ -85,7 +85,7 @@ def _getCatalog(self):
'DateRangeInRangeIndex cant work w/o knowing about its catalog'
)

def _apply_index(self, request, cid='', type=type):
def query_index(self, record, resultset=None):
"""Apply the index to query parameters given in the request arg.
The request argument should be a mapping object.
Expand All @@ -106,10 +106,6 @@ def _apply_index(self, request, cid='', type=type):
- if the value is a sequence, return a union search.
"""
record = parseIndexRequest(request, self.id, self.query_options)
if record.keys is None:
return None

q_start = record.get('start', None)
q_end = record.get('end', None)

Expand Down Expand Up @@ -207,7 +203,7 @@ def _apply_index(self, request, cid='', type=type):
result = multiunion([res1, res2, res3])

# last: return the result
return result, (self.id,)
return result

def index_object(self, documentId, obj, threshold=None):
"""not used, we're just a kind of proxy without own storage"""
Expand All @@ -226,5 +222,8 @@ def getStartIndexField(self):
def getEndIndexField(self):
return self.endindex

def clear(self):
pass


InitializeClass(DateRangeInRangeIndex)
5 changes: 2 additions & 3 deletions src/Products/DateRangeInRangeIndex/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from zope.interface import Interface
import Products.PluginIndexes.interfaces


class IDateRangeInRangeIndex(Interface):
class IDateRangeInRangeIndex(Products.PluginIndexes.interfaces.IQueryIndex):
pass
44 changes: 41 additions & 3 deletions src/Products/DateRangeInRangeIndex/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class DRIRITestcase(ztc.ZopeTestCase):
dtfactory = None

def afterSetUp(self):
"""set up a base scenario"""

"""Set up a base scenario."""
# Zope 2 Index bootstrap
self.app.catalog = z2Catalog()
idxstart = DateIndex('start')
Expand Down Expand Up @@ -104,6 +103,43 @@ def str2datetime(self, dtstr):
def str2DateTime(self, dtstr):
return DateTime(dtstr)


class IndexTests(DRIRITestcase):
"""Tests of .index.DateRangeInRangeIndex. to increase test coverage."""

def test_index__DateRangeInRangeIndex____init____1(self):
"""It can be called without an `extra`."""
index = z2DateRangeInRangeIndex('driri')
self.assertIsNone(index.startindex)
self.assertIsNone(index.endindex)

def test_index__DateRangeInRangeIndex____init____2(self):
"""The `extra` can have the configuration on attributes."""
class extra:
startindex = 'start'
endindex = 'end'
index = z2DateRangeInRangeIndex('driri', extra=extra)
self.assertEqual('start', index.startindex)
self.assertEqual('end', index.endindex)

def test_index__DateRangeInRangeIndex____init____3(self):
"""It raises a ValueError if `extra` has not the needed keys."""
with self.assertRaises(ValueError) as err:
z2DateRangeInRangeIndex('driri', extra={})
self.assertTrue(str(err.exception).startswith(
"DateRangeInRangeIndex needs 'extra' kwarg with keys or "))

def test_index__DateRangeInRangeIndex__query_index__1(self):
"""It requires a `caller` to be set."""
index = z2DateRangeInRangeIndex(
'driri', extra={'startindex': 'start', 'endindex': 'end'})
with self.assertRaises(ValueError) as err:
index.query_index({'start': 1, 'end': 2})
self.assertEqual(
'DateRangeInRangeIndex cant work w/o knowing about its catalog',
str(err.exception))


TESTFILES = [
'index.rst',
'zopeindex.rst'
Expand All @@ -112,10 +148,12 @@ def str2DateTime(self, dtstr):

def test_suite():

return unittest.TestSuite([
suite = unittest.TestSuite([
ztc.ZopeDocFileSuite(
filename,
optionflags=optionflags,
globs={'interact': interact},
test_class=DRIRITestcase
) for filename in TESTFILES])
suite.addTests(unittest.makeSuite(IndexTests))
return suite
42 changes: 42 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[tox]
envlist =
py27,
py35,
py36,
flake8,
coverage

[testenv]
commands =
{envbindir}/buildout -c {toxinidir}/buildout.cfg buildout:directory={envdir} buildout:develop={toxinidir} bootstrap
{envbindir}/buildout -c {toxinidir}/buildout.cfg buildout:directory={envdir} buildout:develop={toxinidir} install test
coverage run {envbindir}/test {posargs:-cv}
skip_install = true
deps =
setuptools==33.1.1
zc.buildout
coverage
setenv =
COVERAGE_FILE=.coverage.{envname}

[testenv:coverage]
basepython = python3.6
skip_install = true
deps = coverage
setenv =
COVERAGE_FILE=.coverage
commands =
coverage erase
coverage combine
coverage html
coverage xml
coverage report --fail-under=85

[testenv:flake8]
basepython = python3.6
deps =
flake8
flake8-html
flake8-debugger
commands =
flake8 --format=html --htmldir={toxinidir}/flake8 --doctests src tests setup.py {posargs}

0 comments on commit 04bfcbc

Please sign in to comment.