# HG changeset patch # User Philippe Pepiot # Date 1553763863 -3600 # Node ID be36811f0d08bf27dc8175fa2bfdcf46afdfd1cb # Parent 56e1132f19c3903403f6a5061dfa8107a61bb3eb [server/test] make unittest_migractions.py use new style cubes MigrationTC used old cube layout in cubicweb/server/test/data-migractions/cubes, move them to new style cubes as "cubicweb_" in "apphome" (cubicweb/server/test/data-migractions/) which is added to PYTHONPATH by CubicWebTC. diff -r 56e1132f19c3 -r be36811f0d08 cubicweb/server/test/data-migractions/cubes/__init__.py --- a/cubicweb/server/test/data-migractions/cubes/__init__.py Wed Mar 27 16:25:06 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) diff -r 56e1132f19c3 -r be36811f0d08 cubicweb/server/test/data-migractions/cubes/fakecustomtype/__init__.py diff -r 56e1132f19c3 -r be36811f0d08 cubicweb/server/test/data-migractions/cubes/fakecustomtype/__pkginfo__.py --- a/cubicweb/server/test/data-migractions/cubes/fakecustomtype/__pkginfo__.py Wed Mar 27 16:25:06 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -# pylint: disable-msg=W0622 -"""cubicweb-fakeemail packaging information""" - -modname = 'fakecustomtype' -distname = "cubicweb-%s" % modname - -numversion = (1, 0, 0) -version = '.'.join(str(num) for num in numversion) - -license = 'LGPL' -author = "Logilab" -author_email = "contact@logilab.fr" -web = 'http://www.cubicweb.org/project/%s' % distname -description = "whatever" -classifiers = [ - 'Environment :: Web Environment', - 'Framework :: CubicWeb', - 'Programming Language :: Python', - 'Programming Language :: JavaScript', -] - -# used packages -__depends__ = {'cubicweb': '>= 3.19.0', - } - - -# packaging ### - -from os import listdir as _listdir -from os.path import join, isdir -from glob import glob - -THIS_CUBE_DIR = join('share', 'cubicweb', 'cubes', modname) - -def listdir(dirpath): - return [join(dirpath, fname) for fname in _listdir(dirpath) - if fname[0] != '.' and not fname.endswith('.pyc') - and not fname.endswith('~') - and not isdir(join(dirpath, fname))] - -data_files = [ - # common files - [THIS_CUBE_DIR, [fname for fname in glob('*.py') if fname != 'setup.py']], - ] -# check for possible extended cube layout -for dirname in ('entities', 'views', 'sobjects', 'hooks', 'schema', 'data', 'i18n', 'migration', 'wdoc'): - if isdir(dirname): - data_files.append([join(THIS_CUBE_DIR, dirname), listdir(dirname)]) -# Note: here, you'll need to add subdirectories if you want -# them to be included in the debian package diff -r 56e1132f19c3 -r be36811f0d08 cubicweb/server/test/data-migractions/cubes/fakecustomtype/schema.py --- a/cubicweb/server/test/data-migractions/cubes/fakecustomtype/schema.py Wed Mar 27 16:25:06 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ - -from yams.buildobjs import EntityType, make_type - -Numeric = make_type('Numeric') - -class Location(EntityType): - num = Numeric(scale=10, precision=18) diff -r 56e1132f19c3 -r be36811f0d08 cubicweb/server/test/data-migractions/cubes/fakecustomtype/site_cubicweb.py --- a/cubicweb/server/test/data-migractions/cubes/fakecustomtype/site_cubicweb.py Wed Mar 27 16:25:06 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -from yams import register_base_type -from logilab.database import get_db_helper -from logilab.database.sqlgen import SQLExpression - -_NUMERIC_PARAMETERS = {'scale': 0, 'precision': None} -register_base_type('Numeric', _NUMERIC_PARAMETERS) - -# Add the datatype to the helper mapping -pghelper = get_db_helper('postgres') - - -def pg_numeric_sqltype(rdef): - """Return a PostgreSQL column type corresponding to rdef - """ - return 'numeric(%s, %s)' % (rdef.precision, rdef.scale) - -pghelper.TYPE_MAPPING['Numeric'] = pg_numeric_sqltype diff -r 56e1132f19c3 -r be36811f0d08 cubicweb/server/test/data-migractions/cubes/fakeemail/__init__.py diff -r 56e1132f19c3 -r be36811f0d08 cubicweb/server/test/data-migractions/cubes/fakeemail/__pkginfo__.py --- a/cubicweb/server/test/data-migractions/cubes/fakeemail/__pkginfo__.py Wed Mar 27 16:25:06 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -# pylint: disable-msg=W0622 -"""cubicweb-fakeemail packaging information""" - -modname = 'fakeemail' -distname = "cubicweb-%s" % modname - -numversion = (1, 10, 0) -version = '.'.join(str(num) for num in numversion) - -license = 'LGPL' -author = "Logilab" -author_email = "contact@logilab.fr" -web = 'http://www.cubicweb.org/project/%s' % distname -description = "email component for the CubicWeb framework" -classifiers = [ - 'Environment :: Web Environment', - 'Framework :: CubicWeb', - 'Programming Language :: Python', - 'Programming Language :: JavaScript', -] - -# used packages -__depends__ = {'cubicweb': '>= 3.19.0', - 'cubicweb-file': '>= 1.9.0', - 'logilab-common': '>= 0.58.3', - } -__recommends__ = {'cubicweb-comment': None} - - -# packaging ### - -from os import listdir as _listdir -from os.path import join, isdir -from glob import glob - -THIS_CUBE_DIR = join('share', 'cubicweb', 'cubes', modname) - -def listdir(dirpath): - return [join(dirpath, fname) for fname in _listdir(dirpath) - if fname[0] != '.' and not fname.endswith('.pyc') - and not fname.endswith('~') - and not isdir(join(dirpath, fname))] - -data_files = [ - # common files - [THIS_CUBE_DIR, [fname for fname in glob('*.py') if fname != 'setup.py']], - ] -# check for possible extended cube layout -for dirname in ('entities', 'views', 'sobjects', 'hooks', 'schema', 'data', 'i18n', 'migration', 'wdoc'): - if isdir(dirname): - data_files.append([join(THIS_CUBE_DIR, dirname), listdir(dirname)]) -# Note: here, you'll need to add subdirectories if you want -# them to be included in the debian package diff -r 56e1132f19c3 -r be36811f0d08 cubicweb/server/test/data-migractions/cubes/fakeemail/schema.py --- a/cubicweb/server/test/data-migractions/cubes/fakeemail/schema.py Wed Mar 27 16:25:06 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -"""entity/relation schemas to store email in an cubicweb instance - -:organization: Logilab -:copyright: 2006-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. -:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr -""" - -from cubicweb import _ - -# pylint: disable-msg=E0611,F0401 -from yams.buildobjs import (SubjectRelation, RelationType, EntityType, - String, Datetime, Int, RelationDefinition) -from yams.reader import context - -from cubicweb.schema import ERQLExpression - - -class Email(EntityType): - """electronic mail""" - subject = String(fulltextindexed=True) - date = Datetime(description=_('UTC time on which the mail was sent')) - messageid = String(required=True, indexed=True) - headers = String(description=_('raw headers')) - - sender = SubjectRelation('EmailAddress', cardinality='?*') - # an email with only Bcc is acceptable, don't require any recipients - recipients = SubjectRelation('EmailAddress') - cc = SubjectRelation('EmailAddress') - - parts = SubjectRelation('EmailPart', cardinality='*1', composite='subject') - attachment = SubjectRelation('File') - - reply_to = SubjectRelation('Email', cardinality='?*') - cites = SubjectRelation('Email') - in_thread = SubjectRelation('EmailThread', cardinality='?*') - - -class EmailPart(EntityType): - """an email attachment""" - __permissions__ = { - 'read': ('managers', 'users', 'guests',), # XXX if E parts X, U has_read_permission E - 'add': ('managers', ERQLExpression('E parts X, U has_update_permission E'),), - 'delete': ('managers', ERQLExpression('E parts X, U has_update_permission E')), - 'update': ('managers', 'owners',), - } - - content = String(fulltextindexed=True) - content_format = String(required=True, maxsize=50) - ordernum = Int(required=True) - alternative = SubjectRelation('EmailPart', symmetric=True) - - -class EmailThread(EntityType): - """discussion thread""" - title = String(required=True, indexed=True, fulltextindexed=True) - see_also = SubjectRelation('EmailThread') - forked_from = SubjectRelation('EmailThread', cardinality='?*') - -class parts(RelationType): - """ """ - fulltext_container = 'subject' - -class sender(RelationType): - """ """ - inlined = True - -class in_thread(RelationType): - """ """ - inlined = True - -class reply_to(RelationType): - """ """ - inlined = True - -class generated_by(RelationType): - """mark an entity as generated from an email""" - cardinality = '?*' - subject = ('TrInfo',) - object = 'Email' - -# if comment is installed -if 'Comment' in context.defined: - class comment_generated_by(RelationDefinition): - subject = 'Comment' - name = 'generated_by' - object = 'Email' diff -r 56e1132f19c3 -r be36811f0d08 cubicweb/server/test/data-migractions/cubicweb_fakecustomtype/__init__.py diff -r 56e1132f19c3 -r be36811f0d08 cubicweb/server/test/data-migractions/cubicweb_fakecustomtype/__pkginfo__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cubicweb/server/test/data-migractions/cubicweb_fakecustomtype/__pkginfo__.py Thu Mar 28 10:04:23 2019 +0100 @@ -0,0 +1,50 @@ +# pylint: disable-msg=W0622 +"""cubicweb-fakeemail packaging information""" + +modname = 'fakecustomtype' +distname = "cubicweb-%s" % modname + +numversion = (1, 0, 0) +version = '.'.join(str(num) for num in numversion) + +license = 'LGPL' +author = "Logilab" +author_email = "contact@logilab.fr" +web = 'http://www.cubicweb.org/project/%s' % distname +description = "whatever" +classifiers = [ + 'Environment :: Web Environment', + 'Framework :: CubicWeb', + 'Programming Language :: Python', + 'Programming Language :: JavaScript', +] + +# used packages +__depends__ = {'cubicweb': '>= 3.19.0', + } + + +# packaging ### + +from os import listdir as _listdir +from os.path import join, isdir +from glob import glob + +THIS_CUBE_DIR = join('share', 'cubicweb', 'cubes', modname) + +def listdir(dirpath): + return [join(dirpath, fname) for fname in _listdir(dirpath) + if fname[0] != '.' and not fname.endswith('.pyc') + and not fname.endswith('~') + and not isdir(join(dirpath, fname))] + +data_files = [ + # common files + [THIS_CUBE_DIR, [fname for fname in glob('*.py') if fname != 'setup.py']], + ] +# check for possible extended cube layout +for dirname in ('entities', 'views', 'sobjects', 'hooks', 'schema', 'data', 'i18n', 'migration', 'wdoc'): + if isdir(dirname): + data_files.append([join(THIS_CUBE_DIR, dirname), listdir(dirname)]) +# Note: here, you'll need to add subdirectories if you want +# them to be included in the debian package diff -r 56e1132f19c3 -r be36811f0d08 cubicweb/server/test/data-migractions/cubicweb_fakecustomtype/schema.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cubicweb/server/test/data-migractions/cubicweb_fakecustomtype/schema.py Thu Mar 28 10:04:23 2019 +0100 @@ -0,0 +1,7 @@ + +from yams.buildobjs import EntityType, make_type + +Numeric = make_type('Numeric') + +class Location(EntityType): + num = Numeric(scale=10, precision=18) diff -r 56e1132f19c3 -r be36811f0d08 cubicweb/server/test/data-migractions/cubicweb_fakecustomtype/site_cubicweb.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cubicweb/server/test/data-migractions/cubicweb_fakecustomtype/site_cubicweb.py Thu Mar 28 10:04:23 2019 +0100 @@ -0,0 +1,17 @@ +from yams import register_base_type +from logilab.database import get_db_helper +from logilab.database.sqlgen import SQLExpression + +_NUMERIC_PARAMETERS = {'scale': 0, 'precision': None} +register_base_type('Numeric', _NUMERIC_PARAMETERS) + +# Add the datatype to the helper mapping +pghelper = get_db_helper('postgres') + + +def pg_numeric_sqltype(rdef): + """Return a PostgreSQL column type corresponding to rdef + """ + return 'numeric(%s, %s)' % (rdef.precision, rdef.scale) + +pghelper.TYPE_MAPPING['Numeric'] = pg_numeric_sqltype diff -r 56e1132f19c3 -r be36811f0d08 cubicweb/server/test/data-migractions/cubicweb_fakeemail/__init__.py diff -r 56e1132f19c3 -r be36811f0d08 cubicweb/server/test/data-migractions/cubicweb_fakeemail/__pkginfo__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cubicweb/server/test/data-migractions/cubicweb_fakeemail/__pkginfo__.py Thu Mar 28 10:04:23 2019 +0100 @@ -0,0 +1,53 @@ +# pylint: disable-msg=W0622 +"""cubicweb-fakeemail packaging information""" + +modname = 'fakeemail' +distname = "cubicweb-%s" % modname + +numversion = (1, 10, 0) +version = '.'.join(str(num) for num in numversion) + +license = 'LGPL' +author = "Logilab" +author_email = "contact@logilab.fr" +web = 'http://www.cubicweb.org/project/%s' % distname +description = "email component for the CubicWeb framework" +classifiers = [ + 'Environment :: Web Environment', + 'Framework :: CubicWeb', + 'Programming Language :: Python', + 'Programming Language :: JavaScript', +] + +# used packages +__depends__ = {'cubicweb': '>= 3.19.0', + 'cubicweb-file': '>= 1.9.0', + 'logilab-common': '>= 0.58.3', + } +__recommends__ = {'cubicweb-comment': None} + + +# packaging ### + +from os import listdir as _listdir +from os.path import join, isdir +from glob import glob + +THIS_CUBE_DIR = join('share', 'cubicweb', 'cubes', modname) + +def listdir(dirpath): + return [join(dirpath, fname) for fname in _listdir(dirpath) + if fname[0] != '.' and not fname.endswith('.pyc') + and not fname.endswith('~') + and not isdir(join(dirpath, fname))] + +data_files = [ + # common files + [THIS_CUBE_DIR, [fname for fname in glob('*.py') if fname != 'setup.py']], + ] +# check for possible extended cube layout +for dirname in ('entities', 'views', 'sobjects', 'hooks', 'schema', 'data', 'i18n', 'migration', 'wdoc'): + if isdir(dirname): + data_files.append([join(THIS_CUBE_DIR, dirname), listdir(dirname)]) +# Note: here, you'll need to add subdirectories if you want +# them to be included in the debian package diff -r 56e1132f19c3 -r be36811f0d08 cubicweb/server/test/data-migractions/cubicweb_fakeemail/schema.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cubicweb/server/test/data-migractions/cubicweb_fakeemail/schema.py Thu Mar 28 10:04:23 2019 +0100 @@ -0,0 +1,86 @@ +"""entity/relation schemas to store email in an cubicweb instance + +:organization: Logilab +:copyright: 2006-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr +""" + +from cubicweb import _ + +# pylint: disable-msg=E0611,F0401 +from yams.buildobjs import (SubjectRelation, RelationType, EntityType, + String, Datetime, Int, RelationDefinition) +from yams.reader import context + +from cubicweb.schema import ERQLExpression + + +class Email(EntityType): + """electronic mail""" + subject = String(fulltextindexed=True) + date = Datetime(description=_('UTC time on which the mail was sent')) + messageid = String(required=True, indexed=True) + headers = String(description=_('raw headers')) + + sender = SubjectRelation('EmailAddress', cardinality='?*') + # an email with only Bcc is acceptable, don't require any recipients + recipients = SubjectRelation('EmailAddress') + cc = SubjectRelation('EmailAddress') + + parts = SubjectRelation('EmailPart', cardinality='*1', composite='subject') + attachment = SubjectRelation('File') + + reply_to = SubjectRelation('Email', cardinality='?*') + cites = SubjectRelation('Email') + in_thread = SubjectRelation('EmailThread', cardinality='?*') + + +class EmailPart(EntityType): + """an email attachment""" + __permissions__ = { + 'read': ('managers', 'users', 'guests',), # XXX if E parts X, U has_read_permission E + 'add': ('managers', ERQLExpression('E parts X, U has_update_permission E'),), + 'delete': ('managers', ERQLExpression('E parts X, U has_update_permission E')), + 'update': ('managers', 'owners',), + } + + content = String(fulltextindexed=True) + content_format = String(required=True, maxsize=50) + ordernum = Int(required=True) + alternative = SubjectRelation('EmailPart', symmetric=True) + + +class EmailThread(EntityType): + """discussion thread""" + title = String(required=True, indexed=True, fulltextindexed=True) + see_also = SubjectRelation('EmailThread') + forked_from = SubjectRelation('EmailThread', cardinality='?*') + +class parts(RelationType): + """ """ + fulltext_container = 'subject' + +class sender(RelationType): + """ """ + inlined = True + +class in_thread(RelationType): + """ """ + inlined = True + +class reply_to(RelationType): + """ """ + inlined = True + +class generated_by(RelationType): + """mark an entity as generated from an email""" + cardinality = '?*' + subject = ('TrInfo',) + object = 'Email' + +# if comment is installed +if 'Comment' in context.defined: + class comment_generated_by(RelationDefinition): + subject = 'Comment' + name = 'generated_by' + object = 'Email' diff -r 56e1132f19c3 -r be36811f0d08 cubicweb/server/test/unittest_migractions.py --- a/cubicweb/server/test/unittest_migractions.py Wed Mar 27 16:25:06 2019 +0100 +++ b/cubicweb/server/test/unittest_migractions.py Thu Mar 28 10:04:23 2019 +0100 @@ -60,8 +60,6 @@ class MigrationConfig(cubicweb.devtools.TestServerConfiguration): default_sources = cubicweb.devtools.DEFAULT_PSQL_SOURCES - CUBES_PATH = cubicweb.devtools.TestServerConfiguration.CUBES_PATH + [ - osp.join(HERE, 'data-migractions', 'cubes')] class MigrationTC(CubicWebTC): @@ -95,10 +93,6 @@ global migrschema migrschema = config.load_schema() - def setUp(self): - self.configcls.cls_adjust_sys_path() - super(MigrationTC, self).setUp() - def tearDown(self): super(MigrationTC, self).tearDown() self.repo.vreg['etypes'].clear_caches() @@ -703,8 +697,8 @@ ['Bookmark', 'EmailThread', 'Folder', 'Note']) self.assertEqual(sorted(schema['see_also'].objects()), ['Bookmark', 'EmailThread', 'Folder', 'Note']) - from cubes.fakeemail.__pkginfo__ import version as email_version - from cubes.file.__pkginfo__ import version as file_version + from cubicweb_fakeemail.__pkginfo__ import version as email_version + from cubicweb_file.__pkginfo__ import version as file_version self.assertEqual( cnx.execute('Any V WHERE X value V, X pkey "system.version.fakeemail"')[0][0], email_version)