[Checkins] SVN: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/ live zope simulation test class with two running tests. Metadata class is changed such that it is not application specific.

Charith Paranaliyanage paranaliyanage at gmail.com
Tue Jun 24 02:26:27 EDT 2008


Log message for revision 87697:
  live zope simulation test class with two running tests. Metadata class is changed such that it is not application specific.

Changed:
  U   Sandbox/adamg/ocql/branches/dbprovider/src/ocql/database/metadata.py
  U   Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/database.py
  U   Sandbox/adamg/ocql/branches/dbprovider/src/ocql/tests/test_zope.py

-=-
Modified: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/database/metadata.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/src/ocql/database/metadata.py	2008-06-23 23:31:28 UTC (rev 87696)
+++ Sandbox/adamg/ocql/branches/dbprovider/src/ocql/database/metadata.py	2008-06-24 06:26:25 UTC (rev 87697)
@@ -8,8 +8,9 @@
 from zope.app.intid import IIntIds
 
 from ocql.interfaces import IDB
-from ocql.database.index import IAllIndex
- 
+from ocql.database.index import AllIndex
+#from ocql.testing.database import MClass
+
 class MetaType:
     def get_property(self, name):
         """
@@ -32,39 +33,64 @@
     def get_size(self):
         """Returns the size of the collection or class if known"""
 
+
+class MClass(MetaType):
+    #interface suspect thing
+    def __init__(self, klass):
+        self.klass = klass
+
+    def is_collection(self):
+        return True
+
+    def get_collection_type(self):
+        return set
+
+    def get_contained(self):
+        return self.klass
+
+    def __getitem__(self, name):
+        x = self.klass[name]._type
+        try:
+            return x[-1]
+        except TypeError:
+            return x
+
+
 class Metadata:
     implements(IDB)
     adapts(None)
     
-    db={}
+    db= {}
+
     classes = {}
     
-    def __init__(self):
-        items = list(searchInterfaceUtilities(self))
+    def __init__(self,context=None):
+        #all the interfaces are retrieved from the catalog
+        #items = list(searchInterfaceUtilities(self))
         catalogs = getUtilitiesFor(ICatalog)
         intids = getUtility(IIntIds)
-        #import pydevd;pydevd.settrace()
         for i in catalogs:
-            catalog = getUtility(ICatalog,name=i[0].__str__())
+            catalog = i[1]
             for index in catalog:
-                #is this the correct way to filter?
-                if index.split("_")[0] == 'all':
+                if isinstance(catalog[index], AllIndex):
+                    interface =  catalog[index].interface
                     results = catalog.apply({index:(1,1)})
                     obj_list = []
                     for result in results:
                         obj = intids.getObject(result)
                         obj_list.append(obj)
-                    self.db.__setitem__(index,obj_list)
+                    self.db.__setitem__(interface.__name__,obj_list)
+                    self.classes.__setitem__(interface.__name__,MClass(interface))
         
-        #seems the db is correct
-        print self.db
+        #seems db and classes are correctly filled
+        #print self.db
+        #print self.classes
         
-        #still this need to be corrected. I was unable to get index.interface property
-        for item in items:
-            class_name = item[0].rsplit('.',1)[1].__str__()
-            self.classes.__setitem__(class_name,class_name)
-        print self.classes
-           
 
+    def getAll(self, klass):
+        return self.db[klass]
+    
     def get_class(self, classname):
-        """Returns a MetaType instance for the class."""
\ No newline at end of file
+        """Returns a MetaType instance for the class."""
+        return self.classes[classname]
+    
\ No newline at end of file

Modified: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/database.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/database.py	2008-06-23 23:31:28 UTC (rev 87696)
+++ Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/database.py	2008-06-24 06:26:25 UTC (rev 87697)
@@ -6,7 +6,7 @@
 from zope.schema import TextLine, Set, Choice, Int, List
 
 from ocql.interfaces import IDB
-from ocql.database import metadata
+from ocql.database.metadata import MClass,Metadata,MetaType
 
 # schema
 class ICourse(Interface):
@@ -36,28 +36,30 @@
         required=True
         )
 
-class MClass(metadata.MetaType):
+#I moved these classes to metadata, is it ok?
+
+#class MClass(metadata.MetaType):
     #interface suspect thing
-    def __init__(self, klass):
-        self.klass = klass
+#    def __init__(self, klass):
+#        self.klass = klass
 
-    def is_collection(self):
-        return True
+    #def is_collection(self):
+     #   return True
 
-    def get_collection_type(self):
-        return set
+#    def get_collection_type(self):
+#        return set
 
-    def get_contained(self):
-        return self.klass
+#    def get_contained(self):
+#        return self.klass
 
-    def __getitem__(self, name):
-        x = self.klass[name]._type
-        try:
-            return x[-1]
-        except TypeError:
-            return x
+#    def __getitem__(self, name):
+#        x = self.klass[name]._type
+#        try:
+#            return x[-1]
+#        except TypeError:
+#            return x
 
-class MType(metadata.MetaType):
+class MType(MetaType):
     def __init__(self, klass, collection_type=None):
         self.klass = klass
         self.collection_type = collection_type
@@ -107,7 +109,7 @@
 
 
 # metadata
-class TestMetadata(metadata.Metadata):
+class TestMetadata(Metadata):
     implements(IDB)
     adapts(None)
 

Modified: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/tests/test_zope.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/src/ocql/tests/test_zope.py	2008-06-23 23:31:28 UTC (rev 87696)
+++ Sandbox/adamg/ocql/branches/dbprovider/src/ocql/tests/test_zope.py	2008-06-24 06:26:25 UTC (rev 87697)
@@ -18,8 +18,11 @@
 from ocql.testing.utils import setupInterfaces, setupCatalog
 from ocql.tests.test_old import QueryNullParser
 from ocql.testing.sample.student import Student
+#REMOVE THIS LATER
+from ocql.testing.sample.interfaces import IOrganization, IStudent, IMentor, IProject
 
 
+
 db = {}
 
 classes = {}
@@ -65,15 +68,30 @@
 
        
     def test_gsoc(self):
-        metadata = Metadata()
+        metadata = IDB(None)
         symbols = SymbolContainer()
 
-        print "retrieve gsoc objects"
-        import pydevd;pydevd.settrace()
-        student_list = metadata.db['all_students'] 
-        a = set(student_list)
+        #
+        # Simple empty query
+        #
+        # set [ ]
+        #
+        query = "set [ ]"
+        qo=Query(metadata, symbols,
+                 set,
+                 [] ,
+                 Identifier(metadata, symbols,
+                            '') )
+
+        self.doit(query, qo, set([]))
         
-        print "only a single query for testing"           
+        
+        symbols = SymbolContainer()
+        #
+        # Simple SELECT ALL
+        #
+        # set [ c in ICourse | c ]
+        #           
         query = "[c in IStudent | c]"
         qo = Query(
                 metadata, symbols,
@@ -85,8 +103,7 @@
                        Identifier(metadata,symbols,'IStudent'))
                 ], Identifier(metadata,symbols,'c'))
         
-        #is not sure how to get s1, s2 and s3 here
-        self.doit(query, qo, set(student_list))
+        self.doit(query, qo, set(metadata.db['IStudent']))
         
         
         



More information about the Checkins mailing list