1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2026-07-05 07:10:48 +02:00

Fixing datasources and migration handlers name + the way datasource's __init__ args

This commit is contained in:
Yann 2016-02-25 14:31:27 +01:00
commit 9939152c9f
7 changed files with 20 additions and 29 deletions

View file

@ -13,7 +13,7 @@ from mosql.query import select, insert, update, delete, join, left_join
from mosql.util import raw, or_
import mosql.mysql
from DataSource.dummy.leapidatasource import DummyDatasource
import DataSource.dummy.leapidatasource
from DataSource.MySQL import utils
from EditorialModel.classtypes import EmNature
from EditorialModel.fieldtypes.generic import MultiValueFieldType
@ -22,18 +22,14 @@ from Lodel.settings import Settings
from .fieldtypes import fieldtype_cast
## MySQL DataSource for LeObject
class LeDataSourceSQL(DummyDatasource):
class LeapiDataSource(DataSource.dummy.leapidatasource.LeapiDataSource):
RELATIONS_POSITIONS_FIELDS = {REL_SUP: 'superior_id', REL_SUB: 'subordinate_id'}
def __init__(self, module=pymysql, conn_args=None):
super(LeDataSourceSQL, self).__init__()
def __init__(self, module = pymysql, **kwargs):
super().__init__()
self.module = module
if conn_args is None:
conn_args = copy.copy(Settings.get('datasource')['default'])
self.module = conn_args['module']
del conn_args['module']
self.connection = Database(self.module, **conn_args)
self.connection = Database(self.module, **kwargs)
## @brief select lodel editorial components using given filters
# @param target_cls LeCrud(class): The component class concerned by the select (a LeCrud child class (not instance !) )

View file

@ -13,7 +13,7 @@ from EditorialModel.fieldtypes.generic import MultiValueFieldType
from DataSource.MySQL import fieldtypes as fieldtypes_utils
from DataSource.MySQL import utils
from DataSource.dummy.migrationhandler import DummyMigrationHandler
import DataSource.dummy
# The global MH algorithm is as follow :
# A create_table(table_name, pk_name, pk_opt) method that create a table
@ -41,7 +41,7 @@ from DataSource.dummy.migrationhandler import DummyMigrationHandler
## @brief Modify a MySQL database given editorial model changes
class MysqlMigrationHandler(DummyMigrationHandler):
class MigrationHandler(DataSource.dummy.MigrationHandler):
## @brief Construct a MysqlMigrationHandler
# @param module : sql module

View file

@ -19,7 +19,7 @@ import leapi.test.utils #Code generation functions
from Lodel.settings import Settings
import DataSource.MySQL
from DataSource.MySQL.leapidatasource import LeDataSourceSQL as DataSource
from DataSource.MySQL.leapidatasource import LeapiDataSource as DataSource
import DataSource.MySQL.utils as db_utils
from EditorialModel.classtypes import common_fields, relations_common_fields
from EditorialModel.fieldtypes.generic import MultiValueFieldType
@ -38,23 +38,12 @@ class DataSourceTestCase(TestCase):
def test_init(self):
""" Test __init__ for datasource """
with patch.object(mosql.db.Database, '__init__', return_value=None) as mock_db:
#Test __init__ without arguments
DataSource()
conn_args = Settings.get('datasource')['default']
db_module = conn_args['module']
del(conn_args['module'])
mock_db.assert_called_once_with(db_module, **conn_args)
mock_db.reset_mock()
#test with arguments
conn_args = { 'hello': 'world', 'answer': 42 }
DataSource(mosql, conn_args)
DataSource(mosql, **conn_args)
mock_db.assert_called_once_with(mosql, **conn_args)
mock_db.reset_mock()
DataSource(conn_args = conn_args)
mock_db.assert_called_once_with(pymysql, **conn_args)
def test_insert_leobject(self):
""" Test the insert method on LeObjects """

View file

@ -4,8 +4,11 @@
#
# This class has to be extended to apply to a real datasource
# But it can be used as an empty and debug datasource
class DummyDatasource(object):
#
# @todo Settings fetch/pass generalisation for datasources.
class LeapiDataSource(object):
## @todo Settings fetch/pass generalisation for datasources.
def __init__(self, module=None, *conn_args, **conn_kargs):
self.module = module
self.conn_args = conn_args

View file

@ -8,7 +8,7 @@
## Manage Model changes
class DummyMigrationHandler(object):
class MigrationHandler(object):
def __init__(self, debug=False):
self.debug = debug

View file

@ -10,8 +10,7 @@ MANDATORY = [
'em_file',
'dynamic_code_file',
'ds_package',
'datasource',
'mh_classname',
'datasource_options',
'migration_options',
'base_path',
'plugins',

View file

@ -12,6 +12,9 @@ debug_sql = False
plugins = ['dummy', 'dummy_auth']
ds_package = 'dummy'
datasource_options = {}
""" #example
datasource = {
'default': {
'module':pymysql,
@ -21,6 +24,7 @@ datasource = {
'db': None,
}
}
"""
migration_options = {
'dryrun': False,