Back to index

plone3  3.1.7
Classes | Functions | Variables
Archetypes.tests.test_sqlstorage Namespace Reference

Classes

class  GadflyMagic
class  SQLStorageTestBase
class  SQLStorageTest
class  StorageTest

Functions

def pretty_exc
def cleanupMySQL
def gen_dummy
def commonAfterSetUp
 Xiru: SQLStorage does not support the field types below.
def test_booleanfield
 Xiru: This test is done, but it is not testing the storage "in practice" because reference field is not SQLStorage aware.
def test_rename
def test_suite

Variables

string connection_id = 'sql_connection'
dictionary connectors = {}
dictionary cleanup = {}
int transactional = 1
tuple storage = storage_class()
 Xiru: The new reference engine is not SQLStorage aware!
list tests = []
 Xiru: These 3 tests below need some refactory!
 db_name
 _storage_class
 _dummy

Function Documentation

Definition at line 108 of file test_sqlstorage.py.

00108 
00109         def cleanupMySQL(self):
00110             instance = self._dummy
00111             args = {}
00112             args['table'] = 'Dummy'
00113             storage = self._storage_class
00114             method = SQLMethod(instance)
00115             method.edit(connection_id, ' '.join(args.keys()),
00116                         storage.query_drop)
            query, result = method(test__=1, **args)

Xiru: SQLStorage does not support the field types below.

For FileField, use ObjectManagedStorage or AttributeStorage and for ImageField and PhotoField use AttributeStorage. They are complex object and persist their content in a RDBMS is not a trivial task (at lest, not without break a lot of things). FileField( 'afilefield', storage = storage_class() ), ImageField( 'aimagefield', storage = storage_class() ), PhotoField( 'aphotofield', storage = storage_class() ),

Definition at line 204 of file test_sqlstorage.py.

00204 
00205 def commonAfterSetUp(self):
00206 
00207     portal = self.portal
00208 
00209     # create the Database Adaptor (DA)
00210     if self.db_name == 'Postgre':
00211         portal.manage_addProduct['ZPsycopgDA'].manage_addZPsycopgConnection(
00212             id = connection_id, title = 'PostgreSQL Archetypes Storage',
00213             connection_string = connectors[self.db_name], zdatetime = 1, check = 1)
00214     elif self.db_name == 'MySQL':
00215         portal.manage_addProduct['ZMySQLDA'].manage_addZMySQLConnection(
00216             id = connection_id, title = 'MySQL Archetypes Storage',
00217             connection_string = connectors[self.db_name], check = 1)
00218     elif self.db_name == 'Gadfly':
00219         portal.manage_addProduct['ZGadflyDA'].manage_addZGadflyConnection(
00220             id = connection_id, title = 'Gadfly Archetypes Storage',
00221             connection = connectors[self.db_name], check = 1)
00222 
00223     # add type information for Dummy
00224     tt = portal.portal_types
00225     tt.manage_addTypeInformation(
00226         FactoryTypeInformation.meta_type,
00227         id = 'Dummy',
00228         typeinfo_name = 'CMFDefault: Document')
00229 
00230     # set archetype_tool default connection
00231     at = getToolByName(portal, TOOL_NAME)
00232     at.setDefaultConn(connection_id)
00233 
00234     # create storage instance and schema
00235     storage_class = getattr(SQLStorage, self.db_name + 'SQLStorage')
00236     gen_dummy(storage_class)
00237     self._storage_class = storage_class
00238 
00239     # create a object instance
00240     obj = Dummy(oid = 'dummy')
00241     portal._setObject('dummy', obj)
00242     obj = getattr(portal, 'dummy')
00243     self._dummy = obj
00244 
00245     # set meta_type for renaming
00246     obj.__factory_meta_type__ = 'Archetypes Content'   # Is It really needed?
00247     obj.meta_type = 'Archetypes Content'
00248 

Here is the caller graph for this function:

Definition at line 120 of file test_sqlstorage.py.

00120 
00121 def gen_dummy(storage_class):
00122 
00123     Dummy.schema = BaseSchema + Schema((
00124 
00125         ObjectField(
00126         'aobjectfield',
00127         storage = storage_class()
00128         ),
00129 
00130         StringField(
00131         'astringfield',
00132         storage = storage_class()
00133         ),
00134 
00135         TextField(
00136         'atextfield',
00137         storage = storage_class()
00138         ),
00139 
00140         DateTimeField(
00141         'adatetimefield',
00142         storage = storage_class()
00143         ),
00144 
00145         LinesField(
00146         'alinesfield',
00147         storage = storage_class()
00148         ),
00149 
00150         IntegerField(
00151         'aintegerfield',
00152         storage = storage_class()
00153         ),
00154 
00155         FloatField(
00156         'afloatfield',
00157         storage = storage_class()
00158         ),
00159 
00160         FixedPointField(
00161         'afixedpointfield',
00162         storage = storage_class()
00163         ),

def Archetypes.tests.test_sqlstorage.pretty_exc (   self,
  exc,
  args,
  kw 
)

Definition at line 38 of file test_sqlstorage.py.

00038 
00039 def pretty_exc(self, exc, *args, **kw):
00040     t, e, tb = exc
00041     try:
00042         return ''.join(format_exception(t, e, tb, format_src=1))
00043     except:
00044         return ''.join(format_exception(t, e, tb))

Xiru: This test is done, but it is not testing the storage "in practice" because reference field is not SQLStorage aware.

  def test_referencefield(self):
     dummy = self._dummy
     value = dummy.getAreferencefield()
     <strong>traceback_info</strong> = (self.db_name, repr(value), [])
     self.failUnless(value == [])          portal = self.portal          # create another object instance (dummy2) and test the

reference creation from dummy to dummy2

obj = Dummy(oid = 'dummy2') portal._setObject('dummy2', obj) obj = getattr(portal, 'dummy2') dummy2 = obj dummy.setAreferencefield([dummy2]) value = dummy.getAreferencefield() traceback_info = (self.db_name, repr(value), [dummy2]) self.failUnless(value == [dummy2]) # one more object instance (dummy3) and test the reference

creation from dummy3 to dummy and dummy2

obj = Dummy(oid = 'dummy3') portal._setObject('dummy3', obj) obj = getattr(portal, 'dummy3') dummy3 = obj dummy3.setAreferencefield([dummy, dummy2]) value = dummy3.getAreferencefield() traceback_info = (self.db_name, repr(value), [dummy, dummy2]) self.failUnless(value == [dummy, dummy2])

Definition at line 438 of file test_sqlstorage.py.

00438 
00439     def test_booleanfield(self):
00440         dummy = self._dummy
00441         value = dummy.getAbooleanfield()
00442         __traceback_info__ = (self.db_name, repr(value), None)
00443         self.failUnless(not value)
00444 
00445         dummy.setAbooleanfield(1)
00446         value = dummy.getAbooleanfield()
00447         __traceback_info__ = (self.db_name, repr(value), 1)
00448         self.failUnless(value == 1)
00449 
00450         dummy.setAbooleanfield(0)
00451         value = dummy.getAbooleanfield()
00452         __traceback_info__ = (self.db_name, repr(value), 0)
00453         self.failUnless(value == 0)

Definition at line 454 of file test_sqlstorage.py.

00454 
00455     def test_rename(self):
00456         self.loginAsPortalOwner()
00457         dummy = self._dummy
00458         content = 'The book is on the table!'
00459         dummy.setAtextfield(content)
00460         got = dummy.getAtextfield()
00461         self.failUnless(str(got) == content, (got, content))
00462         portal = self.portal
00463         obj_id = 'dummy'
00464         new_id = 'new_dummy'
00465         # make sure we have _p_jar
00466         transaction.savepoint(optimistic=True)
00467         portal.manage_renameObject(obj_id, new_id)
00468         dummy = getattr(portal, new_id)
00469         got = dummy.getAtextfield()
00470         self.failUnless(str(got) == content, (got, content))

Definition at line 551 of file test_sqlstorage.py.

00551 
00552 def test_suite():
00553     from unittest import TestSuite, makeSuite
00554     suite = TestSuite()
00555     for test in tests:
00556         suite.addTest(makeSuite(test))
00557     return suite

Variable Documentation

Definition at line 242 of file test_sqlstorage.py.

Definition at line 236 of file test_sqlstorage.py.

Definition at line 67 of file test_sqlstorage.py.

Definition at line 61 of file test_sqlstorage.py.

Definition at line 64 of file test_sqlstorage.py.

Definition at line 209 of file test_sqlstorage.py.

Xiru: The new reference engine is not SQLStorage aware!

ReferenceField( 'areferencefield', storage = storage_class() ),

Definition at line 173 of file test_sqlstorage.py.

Xiru: These 3 tests below need some refactory!

     def test_parentUID(self):
         portal = self.portal
         makeContent(portal, portal_type='SimpleFolder', id='folder1')
         folder1 = getattr(portal, 'folder1')
         makeContent(portal, portal_type='SimpleFolder', id='folder2')
         folder2 = getattr(portal, 'folder2')
         obj_id = 'dummy'

make sure we have _p_jar

transaction.savepoint(optimistic=True) cb = portal.manage_cutObjects([obj_id]) folder1.manage_pasteObjects(cb)

shit, why this does not work anymore?

doc = getattr(folder1, obj_id) PUID1 = folder1.UID() f = StringField('PARENTUID', storage=doc.Schema()['atextfield'].storage) PUID = f.get(doc) traceback_info = (self.db_name, str(PUID), str(PUID1)) self.failUnless(PUID == PUID1)

make sure we have _p_jar

transaction.savepoint(optimistic=True) cb = folder1.manage_cutObjects([obj_id]) folder2.manage_pasteObjects(cb) PUID2 = folder2.UID() doc = getattr(folder2, obj_id) PUID = f.get(doc) traceback_info = (self.db_name, str(PUID2), str(PUID)) self.failUnless(str(PUID2) == str(PUID)) def test_emptyPUID(self): portal = self.portal obj_id = 'dummy' portal._setObject(obj_id, self._nwdummy) doc = getattr(portal, obj_id) doc.initializeArchetype() f = StringField('PARENTUID', storage=doc.Schema()['atextfield'].storage) PUID = f.get(doc) traceback_info = (self.db_name, str(PUID), 'None') self.failUnless(PUID == 'None') def test_nomoreparentUID(self): portal = self.portal makeContent(portal, portal_type='SimpleFolder', id='folder1') folder1 = getattr(portal, 'folder1') obj_id = 'dummy' folder1._setObject(obj_id, self._nwdummy) doc = getattr(folder1, obj_id) doc.initializeArchetype() PUID1 = folder1.UID() f = StringField('PARENTUID', storage=doc.Schema()['atextfield'].storage) PUID = f.get(doc) traceback_info = (self.db_name, str(PUID), str(PUID1)) self.failUnless(str(PUID) == str(PUID1))

make sure we have _p_jar

transaction.savepoint(optimistic=True) cb = folder1.manage_cutObjects(ids=(obj_id,)) portal.manage_pasteObjects(cb) doc = getattr(portal, obj_id) PUID = f.get(doc) traceback_info = (self.db_name, str(PUID), 'None') self.failUnless(PUID == 'None')

Definition at line 539 of file test_sqlstorage.py.

Definition at line 103 of file test_sqlstorage.py.