[Checkins] SVN: Sandbox/adamg/ocql/branches/dbprovider/s
progressing towards dbprovider, added catalog test setup
Adam Groszer
agroszer at gmail.com
Mon Jun 16 04:48:28 EDT 2008
Log message for revision 87421:
progressing towards dbprovider, added catalog test setup
Changed:
U Sandbox/adamg/ocql/branches/dbprovider/setup.py
A Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/
A Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/__init__.py
A Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/gsoc.py
A Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/interfaces.py
A Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/mentor.py
A Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/organization.py
A Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/project.py
A Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/student.py
A Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/vocabulary.py
A Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/utils.py
A Sandbox/adamg/ocql/branches/dbprovider/src/ocql/tests/test_utils.py
-=-
Modified: Sandbox/adamg/ocql/branches/dbprovider/setup.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/setup.py 2008-06-16 08:47:37 UTC (rev 87420)
+++ Sandbox/adamg/ocql/branches/dbprovider/setup.py 2008-06-16 08:48:28 UTC (rev 87421)
@@ -32,6 +32,9 @@
test = [
'zope.testing',
'zope.schema',
+
+ 'zope.app.catalog',
+ 'zope.index',
],
),
install_requires = [
Added: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/__init__.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/__init__.py (rev 0)
+++ Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/__init__.py 2008-06-16 08:48:28 UTC (rev 87421)
@@ -0,0 +1 @@
+#
\ No newline at end of file
Property changes on: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Date Author Id Revision
Name: svn:eol-style
+ native
Added: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/gsoc.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/gsoc.py (rev 0)
+++ Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/gsoc.py 2008-06-16 08:48:28 UTC (rev 87421)
@@ -0,0 +1,27 @@
+# -*- coding: UTF-8 -*-
+from zope.interface import implements
+from zope.app.container.btree import BTreeContainer
+
+from ocql.testing.sample.interfaces import IGsoc
+
+class Gsoc(BTreeContainer):
+ """A simple implementation of the gsoc competetion using B-Tree Containers
+ Make sure that the ââGsocââ implements the ââIGsocââ interface:
+
+ >>> from zope.interface.verify import verifyClass
+ >>> verifyClass(IGsoc, Gsoc)
+ True
+
+ Here is an example of changing the description of the gsoc object:
+ >>> gsoc = Gsoc()
+ >>> gsoc.description
+ u''
+
+ >>> gsoc.description = u'Gsoc Description'
+ >>> gsoc.description
+ u'Gsoc Description'
+ """
+
+ implements(IGsoc)
+
+ description = u''
Property changes on: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/gsoc.py
___________________________________________________________________
Name: svn:keywords
+ Date Author Id Revision
Name: svn:eol-style
+ native
Added: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/interfaces.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/interfaces.py (rev 0)
+++ Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/interfaces.py 2008-06-16 08:48:28 UTC (rev 87421)
@@ -0,0 +1,60 @@
+from zope.interface import Interface
+from zope.schema import Text, TextLine, Field, Choice
+from zope.app.container.constraints import ContainerTypesConstraint, ItemTypePrecondition
+from zope.app.container.constraints import contains, containers
+from zope.app.container.interfaces import IContainer, IContained
+
+class IOrganization(Interface):
+ """An Organization object. This contains projects, mentors and students"""
+
+ name=TextLine(
+ title=u"Organization Name",
+ description=u"Name of the organization",
+ default=u"",
+ required=True)
+
+class IGsoc(IContainer):
+ """This is the root object of this project. It can only contain IOrganization objects"""
+
+ contains(".IOrganization")
+
+ description = Text(
+ title=u"Description",
+ description=u"A detailed description about the content on the Gsoc",
+ default=u"",
+ required=False)
+
+class IProject(Interface):
+ """A Project object."""
+
+ name = TextLine(title=u"Project Name")
+
+ description = TextLine(title=u"Project Description")
+
+
+class IStudent(Interface):
+ """A Student object"""
+
+ name = TextLine(title=u"Student Name")
+
+
+class IMentor(Interface):
+ """A Mentor object"""
+
+ name = TextLine(title=u"Mentor Name")
+
+ #project=Choice(
+ # title=u"Prefered project",
+ # vocabulary=u"vocab_of_IProject",
+ # required=False)
+
+class IOrganizationContained(IContained):
+ """Interface that specifies type of objects that can contain in an organization"""
+
+ containers(".IGsoc")
+
+
+class IOrganizationContainer(IContainer):
+ """Organization is also a container for projects, students and mentors"""
+
+ contains(".IProject", ".IStudent", ".IMentor")
\ No newline at end of file
Property changes on: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/interfaces.py
___________________________________________________________________
Name: svn:keywords
+ Date Author Id Revision
Name: svn:eol-style
+ native
Added: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/mentor.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/mentor.py (rev 0)
+++ Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/mentor.py 2008-06-16 08:48:28 UTC (rev 87421)
@@ -0,0 +1,29 @@
+# -*- coding: UTF-8 -*-
+from zope.interface import implements
+import persistent
+
+from ocql.testing.sample.interfaces import IMentor
+
+class Mentor(persistent.Persistent):
+ """A simple implementation of the gsoc mentor
+ Make sure that the ââMentorââ implements the ââIMentorââ interface:
+
+ >>> from zope.interface.verify import verifyClass
+ >>> verifyClass(IMentor, Mentor)
+ True
+
+ Here is an example of changing the name of the gsoc mentor:
+ >>> mentor = Mentor()
+ >>> mentor.name
+ u''
+
+ >>> mentor.name = u'Mentor Name'
+ >>> mentor.name
+ u'Mentor Name'
+ """
+
+ implements(IMentor)
+
+ name = u''
+
+ project=None
Property changes on: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/mentor.py
___________________________________________________________________
Name: svn:keywords
+ Date Author Id Revision
Name: svn:eol-style
+ native
Added: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/organization.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/organization.py (rev 0)
+++ Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/organization.py 2008-06-16 08:48:28 UTC (rev 87421)
@@ -0,0 +1,30 @@
+from zope.interface import implements
+from zope.app.container.btree import BTreeContainer
+
+from ocql.testing.sample.interfaces import IOrganization
+from ocql.testing.sample.interfaces import IOrganizationContained, IOrganizationContainer
+
+class Organization(BTreeContainer):
+ """A simple implementation of an organization .
+
+ Make sure that the ``Organization`` implements the ``IOrganization`` interface:
+
+
+ >>> from zope.interface.verify import verifyClass
+ >>> verifyClass(IOrganization, Organization)
+ True
+
+ Here is an example of changing the name of the organization:
+
+ >>> organization = Organization()
+ >>> organization.name
+ u''
+
+ >>> organization.name = u'Organization Name'
+ >>> organization.name
+ u'Organization Name'
+ """
+ implements(IOrganization, IOrganizationContained, IOrganizationContainer)
+
+ # See google.interfaces.IOrganization
+ name = u''
Property changes on: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/organization.py
___________________________________________________________________
Name: svn:keywords
+ Date Author Id Revision
Name: svn:eol-style
+ native
Added: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/project.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/project.py (rev 0)
+++ Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/project.py 2008-06-16 08:48:28 UTC (rev 87421)
@@ -0,0 +1,31 @@
+# -*- coding: UTF-8 -*-
+from zope.interface import implements
+from zope.interface import Interface
+import persistent
+
+from ocql.testing.sample.interfaces import IProject
+
+class Project(persistent.Persistent):
+ """A simple implementation of a Project .
+
+ Make sure that the ``Project`` implements the ``IProject`` interface:
+
+
+ >>> from zope.interface.verify import verifyClass
+ >>> verifyClass(IProject, Project)
+ True
+
+ Here is an example of changing the name of the project:
+
+ >>> project = Project()
+ >>> project.name
+ u''
+
+ >>> project.name = u'Project Name'
+ >>> project.name
+ u'Project Name'
+ """
+ implements(IProject)
+
+ # See google.interfaces.IProject
+ name = u''
Property changes on: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/project.py
___________________________________________________________________
Name: svn:keywords
+ Date Author Id Revision
Name: svn:eol-style
+ native
Added: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/student.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/student.py (rev 0)
+++ Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/student.py 2008-06-16 08:48:28 UTC (rev 87421)
@@ -0,0 +1,28 @@
+# -*- coding: UTF-8 -*-
+from zope.interface import implements
+from zope.interface import Interface
+import persistent
+
+from ocql.testing.sample.interfaces import IStudent
+
+class Student(persistent.Persistent):
+ """A simple implementation of the gsoc student
+ Make sure that the ââStudentââ implements the ââIStudentââ interface:
+
+ >>> from zope.interface.verify import verifyClass
+ >>> verifyClass(IStudent, Student)
+ True
+
+ Here is an example of changing the name of the student:
+ >>> student = Student()
+ >>> student.name
+ u''
+
+ >>> student.name = u'Student Name'
+ >>> student.name
+ u'Student Name'
+ """
+
+ implements(IStudent)
+
+ name = u''
Property changes on: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/student.py
___________________________________________________________________
Name: svn:keywords
+ Date Author Id Revision
Name: svn:eol-style
+ native
Added: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/vocabulary.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/vocabulary.py (rev 0)
+++ Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/vocabulary.py 2008-06-16 08:48:28 UTC (rev 87421)
@@ -0,0 +1,38 @@
+from zope import interface
+from zope.security.proxy import removeSecurityProxy
+from zope.schema.interfaces import IVocabularyFactory
+from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
+from google.interfaces import IOrganization
+
+class ContainerVocabulary(SimpleVocabulary):
+ interface.classProvides(IVocabularyFactory)
+
+ #specify here an item IF, like IMentor
+ filter = None
+
+ def __init__(self, context):
+ terms = [self.objToTerm(objekt)
+ for name, objekt
+ in self.getContainer(context).items()
+ if self.filter.providedBy(objekt)]
+
+ SimpleVocabulary.__init__(self, terms)
+
+ def objToTerm(self, objekt):
+ return SimpleTerm(removeSecurityProxy(objekt),
+ token=objekt.__name__,
+ title=objekt.__name__)
+
+ def getContainer(self, context):
+ while True:
+ #walk up until we reach IOrganization
+ if context is None:
+ raise ValueError("something is wrong")
+ if IOrganization.providedBy(context):
+ return context
+ context=context.__parent__
+
+from google.interfaces import IProject
+
+class ConcreteVocabulary(ContainerVocabulary):
+ filter = IProject
Property changes on: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/vocabulary.py
___________________________________________________________________
Name: svn:keywords
+ Date Author Id Revision
Name: svn:eol-style
+ native
Added: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/utils.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/utils.py (rev 0)
+++ Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/utils.py 2008-06-16 08:48:28 UTC (rev 87421)
@@ -0,0 +1,93 @@
+# -*- coding: UTF-8 -*-
+
+"""Utilities for testing support
+
+$Id$
+"""
+
+from zope import interface, component
+from zope.component.interface import provideInterface
+
+from zope.app.catalog.catalog import Catalog
+from zope.app.catalog.interfaces import ICatalog
+from zope.app.catalog.field import FieldIndex
+
+from zope.app.intid import IntIds
+from zope.app.intid.interfaces import IIntIds
+
+from zope.app.keyreference.testing import SimpleKeyReference
+
+from ocql.testing.sample.interfaces import IOrganization
+from ocql.testing.sample.interfaces import IProject
+from ocql.testing.sample.interfaces import IStudent
+from ocql.testing.sample.interfaces import IMentor
+
+from ocql.testing.sample.mentor import Mentor
+from ocql.testing.sample.project import Project
+from ocql.testing.sample.student import Student
+from ocql.testing.sample.organization import Organization
+
+def setupInterfaces(test):
+ provideInterface('', IOrganization)
+ provideInterface('', IProject)
+ provideInterface('', IStudent)
+ provideInterface('', IMentor)
+
+def setupCatalog(test):
+ intids = IntIds()
+ component.provideUtility(intids, IIntIds)
+ component.provideAdapter(SimpleKeyReference)
+
+ cat = Catalog()
+
+ cat['org_name'] = FieldIndex('name', IOrganization)
+
+ cat['proj_name'] = FieldIndex('name', IProject)
+ cat['proj_descr'] = FieldIndex('description', IProject)
+
+ cat['student_name'] = FieldIndex('name', IStudent)
+
+ cat['mentor_name'] = FieldIndex('name', IMentor)
+
+ m1 = Mentor()
+ m1.name = u"John Doe"
+ id = intids.register(m1)
+ cat.index_doc(id, m1)
+
+ p1 = Project()
+ p1.name = u"Save the world"
+ p1.description = u""
+ id = intids.register(p1)
+ cat.index_doc(id, p1)
+
+ s1 = Student()
+ s1.name = u"Charith"
+ id = intids.register(s1)
+ cat.index_doc(id, s1)
+
+ s2 = Student()
+ s2.name = u"Jane"
+ id = intids.register(s2)
+ cat.index_doc(id, s2)
+
+ s3 = Student()
+ s3.name = u"Ann"
+ id = intids.register(s3)
+ cat.index_doc(id, s3)
+
+ o1 = Organization()
+ o1.name = u"Zope.org"
+ id = intids.register(o1)
+ cat.index_doc(id, o1)
+
+ component.provideUtility(cat, ICatalog, name='foo-catalog')
+
+def queryCatalog():
+ cat = component.getUtility(ICatalog, name='foo-catalog')
+ intids = component.getUtility(IIntIds)
+
+ results = cat.apply({'student_name':('Charith','Charith')})
+
+ for r in results:
+ obj = intids.getObject(r)
+ print obj
\ No newline at end of file
Property changes on: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/utils.py
___________________________________________________________________
Name: svn:keywords
+ Date Author Id Revision
Name: svn:eol-style
+ native
Added: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/tests/test_utils.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/src/ocql/tests/test_utils.py (rev 0)
+++ Sandbox/adamg/ocql/branches/dbprovider/src/ocql/tests/test_utils.py 2008-06-16 08:48:28 UTC (rev 87421)
@@ -0,0 +1,28 @@
+# -*- coding: UTF-8 -*-
+
+"""Main
+
+$Id$
+"""
+
+import unittest
+import doctest
+from zope.testing.doctestunit import DocTestSuite,DocFileSuite
+
+from ocql.testing.utils import *
+
+class testUtils(unittest.TestCase):
+ def testCatalog(self):
+ setupInterfaces(None)
+ setupCatalog(None)
+ queryCatalog()
+
+
+def test_suite():
+ flags = doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS
+ return unittest.TestSuite((
+ unittest.makeSuite(testUtils),
+ ))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
\ No newline at end of file
Property changes on: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/tests/test_utils.py
___________________________________________________________________
Name: svn:keywords
+ Date Author Id Revision
Name: svn:eol-style
+ native
More information about the Checkins
mailing list