Browse Source

Fixing the code because of DataSources changes

Yann Weber 9 years ago
parent
commit
14b5bd0fdb

+ 2
- 1
EditorialModel/fields.py View File

57
         self._fieldtype_args = kwargs
57
         self._fieldtype_args = kwargs
58
         self._fieldtype_args.update({'nullable': nullable, 'uniq': uniq, 'internal': self.internal})
58
         self._fieldtype_args.update({'nullable': nullable, 'uniq': uniq, 'internal': self.internal})
59
         self.set_fieldtype_options(**self._fieldtype_args)
59
         self.set_fieldtype_options(**self._fieldtype_args)
60
+        fieldtype_instance = self._fieldtype_cls(**self._fieldtype_args)
60
 
61
 
61
         if 'default' in kwargs:
62
         if 'default' in kwargs:
62
-            if not fieldtype_instance.check(default):
63
+            if not fieldtype_instance.check_data_value(kwargs['default']):
63
                 raise TypeError("Default value ('%s') is not valid given the fieldtype '%s'" % (default, fieldtype))
64
                 raise TypeError("Default value ('%s') is not valid given the fieldtype '%s'" % (default, fieldtype))
64
 
65
 
65
         super(EmField, self).__init__(model=model, uid=uid, name=name, string=string, help_text=help_text, date_update=date_update, date_create=date_create, rank=rank)
66
         super(EmField, self).__init__(model=model, uid=uid, name=name, string=string, help_text=help_text, date_update=date_update, date_create=date_create, rank=rank)

+ 3
- 3
EditorialModel/model.py View File

4
 # Contains the class managing and editorial model
4
 # Contains the class managing and editorial model
5
 
5
 
6
 import EditorialModel
6
 import EditorialModel
7
-from DataSource.dummy.migrationhandler import DummyMigrationHandler
7
+from DataSource.dummy.migrationhandler import MigrationHandler
8
 from EditorialModel.backend.dummy_backend import EmBackendDummy
8
 from EditorialModel.backend.dummy_backend import EmBackendDummy
9
 from EditorialModel.classes import EmClass
9
 from EditorialModel.classes import EmClass
10
 from EditorialModel.fields import EmField
10
 from EditorialModel.fields import EmField
24
     # @param migration_handler : A migration handler
24
     # @param migration_handler : A migration handler
25
     def __init__(self, backend, migration_handler=None):
25
     def __init__(self, backend, migration_handler=None):
26
         if migration_handler is None:
26
         if migration_handler is None:
27
-            self.migration_handler = DummyMigrationHandler()
28
-        elif issubclass(migration_handler.__class__, DummyMigrationHandler):
27
+            self.migration_handler = MigrationHandler()
28
+        elif issubclass(migration_handler.__class__, MigrationHandler):
29
             self.migration_handler = migration_handler
29
             self.migration_handler = migration_handler
30
         else:
30
         else:
31
             raise TypeError("migration_handler should be an instance from a subclass of DummyMigrationhandler")
31
             raise TypeError("migration_handler should be an instance from a subclass of DummyMigrationhandler")

+ 2
- 2
EditorialModel/test/test_classes.py View File

15
 from EditorialModel.fields import EmField
15
 from EditorialModel.fields import EmField
16
 from EditorialModel.model import Model
16
 from EditorialModel.model import Model
17
 from EditorialModel.backend.json_backend import EmBackendJson
17
 from EditorialModel.backend.json_backend import EmBackendJson
18
-from DataSource.dummy.migrationhandler import DummyMigrationHandler
18
+from DataSource.dummy.migrationhandler import MigrationHandler
19
 
19
 
20
 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Lodel.settings")
20
 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Lodel.settings")
21
 EM_TEST = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'me.json')
21
 EM_TEST = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'me.json')
26
 def setUpModule():
26
 def setUpModule():
27
     global EM_TEST_OBJECT
27
     global EM_TEST_OBJECT
28
     #EM_TEST_OBJECT = Model(EmBackendJson(EM_TEST), migration_handler=DjandoMigrationHandler('LodelTestInstance'))
28
     #EM_TEST_OBJECT = Model(EmBackendJson(EM_TEST), migration_handler=DjandoMigrationHandler('LodelTestInstance'))
29
-    EM_TEST_OBJECT = Model(EmBackendJson(EM_TEST), migration_handler=DummyMigrationHandler())
29
+    EM_TEST_OBJECT = Model(EmBackendJson(EM_TEST), migration_handler=MigrationHandler())
30
     logging.basicConfig(level=logging.CRITICAL)
30
     logging.basicConfig(level=logging.CRITICAL)
31
 
31
 
32
 
32
 

+ 2
- 2
EditorialModel/test/test_component.py View File

9
 from Lodel.utils.mlstring import MlString
9
 from Lodel.utils.mlstring import MlString
10
 
10
 
11
 from EditorialModel.backend.json_backend import EmBackendJson
11
 from EditorialModel.backend.json_backend import EmBackendJson
12
-from DataSource.dummy.migrationhandler import DummyMigrationHandler
12
+from DataSource.dummy.migrationhandler import MigrationHandler
13
 
13
 
14
 
14
 
15
 class TestEmComponent(unittest.TestCase):
15
 class TestEmComponent(unittest.TestCase):
19
     def test_hashes(self):
19
     def test_hashes(self):
20
         """ Testing __hash__ and __eq__ methods """
20
         """ Testing __hash__ and __eq__ methods """
21
         me1 = Model(EmBackendJson('EditorialModel/test/me.json'))
21
         me1 = Model(EmBackendJson('EditorialModel/test/me.json'))
22
-        me2 = Model(EmBackendJson('EditorialModel/test/me.json'), migration_handler=DummyMigrationHandler())
22
+        me2 = Model(EmBackendJson('EditorialModel/test/me.json'), migration_handler=MigrationHandler())
23
 
23
 
24
         for comp_class in [EmClass, EmType, EmField]:
24
         for comp_class in [EmClass, EmType, EmField]:
25
             comp_l1 = me1.components(comp_class)
25
             comp_l1 = me1.components(comp_class)

+ 2
- 0
EditorialModel/test/test_field.py View File

1
 import os
1
 import os
2
 
2
 
3
+import unittest
3
 from unittest import TestCase
4
 from unittest import TestCase
4
 from EditorialModel.fields import EmField
5
 from EditorialModel.fields import EmField
5
 from EditorialModel.model import Model
6
 from EditorialModel.model import Model
63
         with self.assertRaises(ValueError, msg="Only common_fields should be internal='object'"):
64
         with self.assertRaises(ValueError, msg="Only common_fields should be internal='object'"):
64
             field = EM_TEST_OBJECT.create_component(EmField.__name__, {'name': 'testbadinternal','internal': 'object', 'class_id': self.test_class.uid, 'fieldtype': self.test_fieldtype})
65
             field = EM_TEST_OBJECT.create_component(EmField.__name__, {'name': 'testbadinternal','internal': 'object', 'class_id': self.test_class.uid, 'fieldtype': self.test_fieldtype})
65
 
66
 
67
+    @unittest.skip("rel2type are not uniq like this anymore")
66
     def test_double_rel2type(self):
68
     def test_double_rel2type(self):
67
         """ Test the rel2type unicity """
69
         """ Test the rel2type unicity """
68
         em = EM_TEST_OBJECT
70
         em = EM_TEST_OBJECT

+ 9
- 9
EditorialModel/test/test_model.py View File

11
 
11
 
12
 from EditorialModel.backend.json_backend import EmBackendJson
12
 from EditorialModel.backend.json_backend import EmBackendJson
13
 from EditorialModel.backend.dummy_backend import EmBackendDummy
13
 from EditorialModel.backend.dummy_backend import EmBackendDummy
14
-from DataSource.dummy.migrationhandler import DummyMigrationHandler
14
+from DataSource.dummy.migrationhandler import MigrationHandler
15
 
15
 
16
 
16
 
17
 class TestModel(unittest.TestCase):
17
 class TestModel(unittest.TestCase):
24
         model = Model(EmBackendJson('EditorialModel/test/me.json'))
24
         model = Model(EmBackendJson('EditorialModel/test/me.json'))
25
         self.assertTrue(isinstance(model, Model))
25
         self.assertTrue(isinstance(model, Model))
26
 
26
 
27
-        model = Model(EmBackendJson('EditorialModel/test/me.json'), migration_handler=DummyMigrationHandler())
27
+        model = Model(EmBackendJson('EditorialModel/test/me.json'), migration_handler=MigrationHandler())
28
         self.assertTrue(isinstance(model, Model))
28
         self.assertTrue(isinstance(model, Model))
29
 
29
 
30
     def test_bad_init(self):
30
     def test_bad_init(self):
31
         """ Test initialisation with bad arguments """
31
         """ Test initialisation with bad arguments """
32
-        for bad in [None, int, EmBackendDummy, DummyMigrationHandler, 'foobar']:
32
+        for bad in [None, int, EmBackendDummy, MigrationHandler, 'foobar']:
33
             with self.assertRaises(TypeError, msg="Tried to instanciate a Model with a bad backend"):
33
             with self.assertRaises(TypeError, msg="Tried to instanciate a Model with a bad backend"):
34
                 Model(bad)
34
                 Model(bad)
35
-        for bad in [int, EmBackendDummy, DummyMigrationHandler, 'foobar']:
35
+        for bad in [int, EmBackendDummy, MigrationHandler, 'foobar']:
36
             with self.assertRaises(TypeError, msg="Tried to instanciate a Model with a migration_handler"):
36
             with self.assertRaises(TypeError, msg="Tried to instanciate a Model with a migration_handler"):
37
                 Model(EmBackendDummy(), bad)
37
                 Model(EmBackendDummy(), bad)
38
 
38
 
246
             for nat, sup_l in emtype.superiors().items():
246
             for nat, sup_l in emtype.superiors().items():
247
                 superiors_list_orig[nat] = [sup.uid for sup in sup_l]
247
                 superiors_list_orig[nat] = [sup.uid for sup in sup_l]
248
 
248
 
249
-        with patch.object(DummyMigrationHandler, 'register_change', return_value=None) as mh_mock:
250
-            self.ed_mod.migrate_handler(DummyMigrationHandler())
249
+        with patch.object(MigrationHandler, 'register_change', return_value=None) as mh_mock:
250
+            self.ed_mod.migrate_handler(MigrationHandler())
251
             #Getting cloned EM instance
251
             #Getting cloned EM instance
252
             new_me = mh_mock.mock_calls[-1][1][0]
252
             new_me = mh_mock.mock_calls[-1][1][0]
253
             for emtype in new_me.components(EmType):
253
             for emtype in new_me.components(EmType):
269
 
269
 
270
     def test_migrate_handler_hashes(self):
270
     def test_migrate_handler_hashes(self):
271
         """ Testing that the migrate_handler() method create an EM with the same hash as the original EM """
271
         """ Testing that the migrate_handler() method create an EM with the same hash as the original EM """
272
-        with patch.object(DummyMigrationHandler, 'register_change', return_value=None) as mh_mock:
273
-            self.ed_mod.migrate_handler(DummyMigrationHandler())
272
+        with patch.object(MigrationHandler, 'register_change', return_value=None) as mh_mock:
273
+            self.ed_mod.migrate_handler(MigrationHandler())
274
             #Getting the cloned EM instance
274
             #Getting the cloned EM instance
275
             last_call = mh_mock.mock_calls[-1]
275
             last_call = mh_mock.mock_calls[-1]
276
             self.assertEqual(hash(last_call[1][0]), hash(self.ed_mod))
276
             self.assertEqual(hash(last_call[1][0]), hash(self.ed_mod))
278
     def test_hash(self):
278
     def test_hash(self):
279
         """ Test that __hash__ and __eq__ work properly on models """
279
         """ Test that __hash__ and __eq__ work properly on models """
280
         me1 = Model(EmBackendJson('EditorialModel/test/me.json'))
280
         me1 = Model(EmBackendJson('EditorialModel/test/me.json'))
281
-        me2 = Model(EmBackendJson('EditorialModel/test/me.json'), migration_handler=DummyMigrationHandler())
281
+        me2 = Model(EmBackendJson('EditorialModel/test/me.json'), migration_handler=MigrationHandler())
282
 
282
 
283
         self.assertEqual(hash(me1), hash(me2), "When instanciate from the same backend & file but with another migration handler the hashes differs")
283
         self.assertEqual(hash(me1), hash(me2), "When instanciate from the same backend & file but with another migration handler the hashes differs")
284
         self.assertTrue(me1.__eq__(me2))
284
         self.assertTrue(me1.__eq__(me2))

+ 1
- 1
install/utils.py View File

88
             os.unlink(my_file_path)
88
             os.unlink(my_file_path)
89
         with open(my_file_path, 'w') as my_file:
89
         with open(my_file_path, 'w') as my_file:
90
             my_file.write(template['content'])
90
             my_file.write(template['content'])
91
-        print("Created %s" % my_file_path)
91
+        print("Created %s" % my_file_path)

+ 27
- 1
leapi/lecrud.py View File

10
 import re
10
 import re
11
 
11
 
12
 from Lodel import logger
12
 from Lodel import logger
13
+from Lodel.settings import Settings
13
 from EditorialModel.fieldtypes.generic import DatasConstructor
14
 from EditorialModel.fieldtypes.generic import DatasConstructor
14
 from Lodel.hooks import LodelHook
15
 from Lodel.hooks import LodelHook
15
 
16
 
44
 ## @brief When an error concerns a datas
45
 ## @brief When an error concerns a datas
45
 class LeApiDataCheckError(LeApiErrors): pass
46
 class LeApiDataCheckError(LeApiErrors): pass
46
     
47
     
48
+class _MetaLeCrud(type):
49
+     def __getattribute__(self, name):
50
+        if name == '_datasource':
51
+            if super().__getattribute__('_datasource') is None:
52
+                module = importlib.import_module("DataSource.{pkg_name}.leapidatasource".format(
53
+                    pkg_name = Settings.ds_package,
54
+                    mod_name = 'leapidatasource'
55
+                ))
56
+                ds_cls = getattr(module, 'LeapiDataSource')
57
+                super().__setattr__('_datasource', ds_cls(**Settings.datasource_options))
58
+        return super().__getattribute__(name)
59
+
60
+
61
+        if 'leapidatasource' in globals():
62
+            if name == '_datasource' and isinstance(self._datasource, DummyDatasource):
63
+                #if name == '_datasource' and self._datasource == None:
64
+                leapids = globals()['leapidatasource']
65
+                if not isinstance(leapids, DummyDatasource):
66
+                    self._datasource = leapids({})
67
+        return super().__getattribute__(name)
47
 
68
 
48
 ## @brief Main class to handler lodel editorial components (relations and objects)
69
 ## @brief Main class to handler lodel editorial components (relations and objects)
49
-class _LeCrud(object):
70
+class _LeCrud(object, metaclass = _MetaLeCrud):
50
     ## @brief The datasource
71
     ## @brief The datasource
51
     _datasource = None
72
     _datasource = None
52
 
73
 
102
         ## @brief A flag to indicate if the object was fully intanciated or not
123
         ## @brief A flag to indicate if the object was fully intanciated or not
103
         self._instanciation_complete = len(kwargs) + 1 == len(self.fieldlist())
124
         self._instanciation_complete = len(kwargs) + 1 == len(self.fieldlist())
104
 
125
 
126
+    def __getattribute__(self, name):
127
+        if name == '_datasource':
128
+            return _MetaLeCrud.__getattribute__(self.__class__, name)
129
+        return super().__getattribute__(name)
130
+
105
     ## @brief Convert an EmType or EmClass name in a python class name
131
     ## @brief Convert an EmType or EmClass name in a python class name
106
     # @param name str : The name
132
     # @param name str : The name
107
     # @return name.title()
133
     # @return name.title()

+ 3
- 11
leapi/lefactory.py View File

38
     
38
     
39
     ## @brief Write generated code to a file
39
     ## @brief Write generated code to a file
40
     # @todo better options/params for file creation
40
     # @todo better options/params for file creation
41
-    def create_pyfile(self, model, datasource_cls, datasource_args):
41
+    def create_pyfile(self, model):
42
         with open(self._code_filename, "w+") as dynfp:
42
         with open(self._code_filename, "w+") as dynfp:
43
-            dynfp.write(self.generate_python(model, datasource_cls, datasource_args))
43
+            dynfp.write(self.generate_python(model))
44
 
44
 
45
     ## @brief Generate fieldtypes for concret classes
45
     ## @brief Generate fieldtypes for concret classes
46
     # @param ft_dict dict : key = fieldname value = fieldtype __init__ args
46
     # @param ft_dict dict : key = fieldname value = fieldtype __init__ args
176
     # @param datasource_cls Datasource : A datasource class
176
     # @param datasource_cls Datasource : A datasource class
177
     # @param datasource_args dict : A dict representing arguments for datasource_cls instanciation
177
     # @param datasource_args dict : A dict representing arguments for datasource_cls instanciation
178
     # @return A string representing python code
178
     # @return A string representing python code
179
-    def generate_python(self, model, datasource_cls, datasource_args):
179
+    def generate_python(self, model):
180
         self.needed_fieldtypes = set() #Stores the list of fieldtypes that will be used by generated code
180
         self.needed_fieldtypes = set() #Stores the list of fieldtypes that will be used by generated code
181
 
181
 
182
         model = model
182
         model = model
199
 from leapi.letype import _LeType
199
 from leapi.letype import _LeType
200
 """
200
 """
201
 
201
 
202
-        result += """
203
-import %s
204
-
205
-""" % (datasource_cls.__module__)
206
-
207
         #Generating the code for LeObject class
202
         #Generating the code for LeObject class
208
         leobj_me_uid = dict()
203
         leobj_me_uid = dict()
209
         for comp in model.components('EmType') + model.components('EmClass'):
204
         for comp in model.components('EmType') + model.components('EmClass'):
224
 ## @brief _LeCrud concret class
219
 ## @brief _LeCrud concret class
225
 # @see leapi.lecrud._LeCrud
220
 # @see leapi.lecrud._LeCrud
226
 class LeCrud(leapi.lecrud._LeCrud):
221
 class LeCrud(leapi.lecrud._LeCrud):
227
-    _datasource = {ds_classname}(**{ds_kwargs})
228
     _uid_fieldtype = None
222
     _uid_fieldtype = None
229
 
223
 
230
 ## @brief _LeObject concret class
224
 ## @brief _LeObject concret class
257
 class LeType(LeClass, _LeType):
251
 class LeType(LeClass, _LeType):
258
     pass
252
     pass
259
 """.format(
253
 """.format(
260
-            ds_classname = datasource_cls.__module__ + '.' + datasource_cls.__name__,
261
-            ds_kwargs = repr(datasource_args),
262
             me_uid_l = repr(leobj_me_uid),
254
             me_uid_l = repr(leobj_me_uid),
263
             leo_uid_fieldtype = leobj_uid_fieldtype,
255
             leo_uid_fieldtype = leobj_uid_fieldtype,
264
             leo_fieldtypes = '{\n\t' + (',\n\t'.join(leobj_fieldtypes))+ '\n\t}',
256
             leo_fieldtypes = '{\n\t' + (',\n\t'.join(leobj_fieldtypes))+ '\n\t}',

+ 5
- 5
leapi/test/test_lecrud.py View File

179
     #   Tests mocking the datasource
179
     #   Tests mocking the datasource
180
180
181
 
181
 
182
-    @patch('DataSource.dummy.leapidatasource.DummyDatasource.insert')
182
+    @patch('DataSource.dummy.leapidatasource.LeapiDataSource.insert')
183
     def test_insert(self, dsmock):
183
     def test_insert(self, dsmock):
184
         from dyncode import Publication, Numero, LeObject, Personne, Article
184
         from dyncode import Publication, Numero, LeObject, Personne, Article
185
         ndatas = [
185
         ndatas = [
205
             dsmock.reset_mock()
205
             dsmock.reset_mock()
206
     
206
     
207
     ## @todo try failing on inserting from LeClass child or LeObject
207
     ## @todo try failing on inserting from LeClass child or LeObject
208
-    @patch('DataSource.dummy.leapidatasource.DummyDatasource.insert')
208
+    @patch('DataSource.dummy.leapidatasource.LeapiDataSource.insert')
209
     def test_insert_fails(self, dsmock):
209
     def test_insert_fails(self, dsmock):
210
         from dyncode import Publication, Numero, LeObject, Personne, Article
210
         from dyncode import Publication, Numero, LeObject, Personne, Article
211
         ndatas = [
211
         ndatas = [
221
                 assert not dsmock.called
221
                 assert not dsmock.called
222
         pass
222
         pass
223
     
223
     
224
-    @patch('DataSource.dummy.leapidatasource.DummyDatasource.update')
224
+    @patch('DataSource.dummy.leapidatasource.LeapiDataSource.update')
225
     def test_update(self, dsmock):
225
     def test_update(self, dsmock):
226
         from dyncode import Publication, Numero, LeObject
226
         from dyncode import Publication, Numero, LeObject
227
         
227
         
242
             dsmock.assert_called_once_with(ccls, eid, **qdatas)
242
             dsmock.assert_called_once_with(ccls, eid, **qdatas)
243
     
243
     
244
     ## @todo test invalid get
244
     ## @todo test invalid get
245
-    @patch('DataSource.dummy.leapidatasource.DummyDatasource.select')
245
+    @patch('DataSource.dummy.leapidatasource.LeapiDataSource.select')
246
     def test_get(self, dsmock):
246
     def test_get(self, dsmock):
247
         """ Test the select method without group, limit, sort or offset """
247
         """ Test the select method without group, limit, sort or offset """
248
         from dyncode import Publication, Numero, LeObject, Textes
248
         from dyncode import Publication, Numero, LeObject, Textes
321
                                     )
321
                                     )
322
             dsmock.reset_mock()
322
             dsmock.reset_mock()
323
     
323
     
324
-    @patch('DataSource.dummy.leapidatasource.DummyDatasource.select')
324
+    @patch('DataSource.dummy.leapidatasource.LeapiDataSource.select')
325
     def test_get_complete(self, dsmock):
325
     def test_get_complete(self, dsmock):
326
         """ Test the select method with group limit sort and offset arguments """
326
         """ Test the select method with group limit sort and offset arguments """
327
         from dyncode import Numero
327
         from dyncode import Numero

+ 3
- 3
leapi/test/test_leobject.py View File

58
         """ Remove the temporary directory created at class setup """
58
         """ Remove the temporary directory created at class setup """
59
         leapi.test.utils.cleanup(cls.tmpdir)
59
         leapi.test.utils.cleanup(cls.tmpdir)
60
     
60
     
61
-    @patch('DataSource.dummy.leapidatasource.DummyDatasource.insert')
61
+    @patch('DataSource.dummy.leapidatasource.LeapiDataSource.insert')
62
     def test_insert(self, dsmock):
62
     def test_insert(self, dsmock):
63
         from dyncode import Publication, Numero, LeObject
63
         from dyncode import Publication, Numero, LeObject
64
         ndatas = [
64
         ndatas = [
81
             dsmock.assert_called_once_with(Numero, **expt_dats)
81
             dsmock.assert_called_once_with(Numero, **expt_dats)
82
             dsmock.reset_mock()
82
             dsmock.reset_mock()
83
 
83
 
84
-    @patch('DataSource.dummy.leapidatasource.DummyDatasource.update')
84
+    @patch('DataSource.dummy.leapidatasource.LeapiDataSource.update')
85
     def test_update(self, dsmock):
85
     def test_update(self, dsmock):
86
         from dyncode import Publication, Numero, LeObject, Personne, Article, RelTextesPersonneAuteur
86
         from dyncode import Publication, Numero, LeObject, Personne, Article, RelTextesPersonneAuteur
87
 
87
 
98
                 dsmock.assert_called_once_with(instance.__class__, instance.uidget(), **datas)
98
                 dsmock.assert_called_once_with(instance.__class__, instance.uidget(), **datas)
99
                 dsmock.reset_mock()
99
                 dsmock.reset_mock()
100
     
100
     
101
-    @patch('DataSource.dummy.leapidatasource.DummyDatasource.delete')
101
+    @patch('DataSource.dummy.leapidatasource.LeapiDataSource.delete')
102
     def test_delete(self, dsmock):
102
     def test_delete(self, dsmock):
103
         from dyncode import Publication, Numero, LeObject, LeType, LeRelation
103
         from dyncode import Publication, Numero, LeObject, LeType, LeRelation
104
         
104
         

+ 7
- 7
leapi/test/test_lerelation.py View File

69
             for i in range(3):
69
             for i in range(3):
70
                 self.assertEqual(filter_res[i], res[i], "%s != %s"%(filter_res, res))
70
                 self.assertEqual(filter_res[i], res[i], "%s != %s"%(filter_res, res))
71
 
71
 
72
-    @patch('DataSource.dummy.leapidatasource.DummyDatasource.delete')
72
+    @patch('DataSource.dummy.leapidatasource.LeapiDataSource.delete')
73
     def test_delete(self, dsmock):
73
     def test_delete(self, dsmock):
74
         """ Testing LeHierarch insert method """
74
         """ Testing LeHierarch insert method """
75
         from dyncode import LeCrud, Publication, Numero, Personnes, LeObject, Rubrique, LeHierarch, LeRelation
75
         from dyncode import LeCrud, Publication, Numero, Personnes, LeObject, Rubrique, LeHierarch, LeRelation
81
 
81
 
82
 class LeHierarch(LeRelationTestCase):
82
 class LeHierarch(LeRelationTestCase):
83
     
83
     
84
-    @patch('DataSource.dummy.leapidatasource.DummyDatasource.select')
84
+    @patch('DataSource.dummy.leapidatasource.LeapiDataSource.select')
85
     def test_get(self, dsmock):
85
     def test_get(self, dsmock):
86
         """ Tests the LeHierarch.get() method without limit group order etc."""
86
         """ Tests the LeHierarch.get() method without limit group order etc."""
87
         from dyncode import LeCrud, Publication, Numero, Personnes, LeObject, Rubrique, LeHierarch, LeRelation
87
         from dyncode import LeCrud, Publication, Numero, Personnes, LeObject, Rubrique, LeHierarch, LeRelation
123
 
123
 
124
             dsmock.reset_mock()
124
             dsmock.reset_mock()
125
     
125
     
126
-    @patch('DataSource.dummy.leapidatasource.DummyDatasource.insert')
126
+    @patch('DataSource.dummy.leapidatasource.LeapiDataSource.insert')
127
     def test_insert(self, dsmock):
127
     def test_insert(self, dsmock):
128
         """ Testing LeHierarch insert method """
128
         """ Testing LeHierarch insert method """
129
         from dyncode import LeCrud, Publication, Numero, Personnes, LeObject, Rubrique, LeHierarch, LeRelation
129
         from dyncode import LeCrud, Publication, Numero, Personnes, LeObject, Rubrique, LeHierarch, LeRelation
194
             dsmock.reset_mock()
194
             dsmock.reset_mock()
195
     
195
     
196
 
196
 
197
-    @patch('DataSource.dummy.leapidatasource.DummyDatasource.delete')
197
+    @patch('DataSource.dummy.leapidatasource.LeapiDataSource.delete')
198
     def test_delete(self, dsmock):
198
     def test_delete(self, dsmock):
199
         """ Testing LeHierarch delete method """
199
         """ Testing LeHierarch delete method """
200
         from dyncode import LeCrud, Publication, Numero, Personnes, LeObject, Rubrique, LeHierarch, LeRelation
200
         from dyncode import LeCrud, Publication, Numero, Personnes, LeObject, Rubrique, LeHierarch, LeRelation
203
         dsmock.assert_called_once_with(LeHierarch, 10)
203
         dsmock.assert_called_once_with(LeHierarch, 10)
204
         
204
         
205
     
205
     
206
-    @patch('DataSource.dummy.leapidatasource.DummyDatasource.update')
206
+    @patch('DataSource.dummy.leapidatasource.LeapiDataSource.update')
207
     def test_update(self, dsmock):
207
     def test_update(self, dsmock):
208
         """ test LeHierach update method"""
208
         """ test LeHierach update method"""
209
         from dyncode import LeHierarch
209
         from dyncode import LeHierarch
214
 
214
 
215
 class LeRel2TypeTestCase(LeRelationTestCase):
215
 class LeRel2TypeTestCase(LeRelationTestCase):
216
     
216
     
217
-    @patch('DataSource.dummy.leapidatasource.DummyDatasource.insert')
217
+    @patch('DataSource.dummy.leapidatasource.LeapiDataSource.insert')
218
     def test_insert(self, dsmock):
218
     def test_insert(self, dsmock):
219
         """ test LeHierach update method"""
219
         """ test LeHierach update method"""
220
         from dyncode import LeObject, Article, Textes, Personne, Personnes, LeHierarch, LeRel2Type, RelTextesPersonneAuteur
220
         from dyncode import LeObject, Article, Textes, Personne, Personnes, LeHierarch, LeRel2Type, RelTextesPersonneAuteur
265
             dsmock.assert_called_once_with(RelTextesPersonneAuteur, **eres)
265
             dsmock.assert_called_once_with(RelTextesPersonneAuteur, **eres)
266
             dsmock.reset_mock()
266
             dsmock.reset_mock()
267
 
267
 
268
-    @patch('DataSource.dummy.leapidatasource.DummyDatasource.insert')
268
+    @patch('DataSource.dummy.leapidatasource.LeapiDataSource.insert')
269
     def test_insert_fails(self, dsmock):
269
     def test_insert_fails(self, dsmock):
270
         """ test LeHierach update method"""
270
         """ test LeHierach update method"""
271
         from dyncode import LeObject, Rubrique, Numero, Article, Textes, Personne, Personnes, LeHierarch, LeRel2Type, RelTextesPersonneAuteur
271
         from dyncode import LeObject, Rubrique, Numero, Article, Textes, Personne, Personnes, LeHierarch, LeRel2Type, RelTextesPersonneAuteur

+ 3
- 3
leapi/test/test_letype.py View File

102
         """ Remove the temporary directory created at class setup """
102
         """ Remove the temporary directory created at class setup """
103
         leapi.test.utils.cleanup(cls.tmpdir)
103
         leapi.test.utils.cleanup(cls.tmpdir)
104
 
104
 
105
-    @patch('DataSource.dummy.leapidatasource.DummyDatasource.select')
105
+    @patch('DataSource.dummy.leapidatasource.LeapiDataSource.select')
106
     def test_populate(self, dsmock):
106
     def test_populate(self, dsmock):
107
         from dyncode import Publication, Numero, LeObject
107
         from dyncode import Publication, Numero, LeObject
108
 
108
 
112
             num.populate()
112
             num.populate()
113
             dsmock.assert_called_once_with(Numero, missing_fields, [('lodel_id','=',1)],[])
113
             dsmock.assert_called_once_with(Numero, missing_fields, [('lodel_id','=',1)],[])
114
 
114
 
115
-    @patch('DataSource.dummy.leapidatasource.DummyDatasource.update')
115
+    @patch('DataSource.dummy.leapidatasource.LeapiDataSource.update')
116
     def test_update(self, dsmock):
116
     def test_update(self, dsmock):
117
         from dyncode import Publication, Numero, LeObject
117
         from dyncode import Publication, Numero, LeObject
118
         
118
         
125
             mock_populate.assert_called_once_with()
125
             mock_populate.assert_called_once_with()
126
             dsmock.assert_called_once_with(Numero, num.uidget(), **datas)
126
             dsmock.assert_called_once_with(Numero, num.uidget(), **datas)
127
     
127
     
128
-    @patch('DataSource.dummy.leapidatasource.DummyDatasource.delete')
128
+    @patch('DataSource.dummy.leapidatasource.LeapiDataSource.delete')
129
     def test_delete(self, dsmock):
129
     def test_delete(self, dsmock):
130
         from dyncode import Publication, Numero, LeObject
130
         from dyncode import Publication, Numero, LeObject
131
         
131
         

+ 1
- 3
leapi/test/utils.py View File

5
 from EditorialModel.model import Model
5
 from EditorialModel.model import Model
6
 import leapi
6
 import leapi
7
 from EditorialModel.backend.json_backend import EmBackendJson
7
 from EditorialModel.backend.json_backend import EmBackendJson
8
-from DataSource.MySQL.leapidatasource import DummyDatasource
8
+from DataSource.dummy.leapidatasource import LeapiDataSource
9
 from leapi.lefactory import LeFactory
9
 from leapi.lefactory import LeFactory
10
 
10
 
11
 
11
 
12
 
12
 
13
 genepy_args = {
13
 genepy_args = {
14
     'model' : Model(EmBackendJson(json_file = 'EditorialModel/test/me.json')),
14
     'model' : Model(EmBackendJson(json_file = 'EditorialModel/test/me.json')),
15
-    'datasource_cls': DummyDatasource,
16
-    'datasource_args': {}
17
 }
15
 }
18
 
16
 
19
 def tmp_load_factory_code(name='dyncode'):
17
 def tmp_load_factory_code(name='dyncode'):

+ 2
- 3
refreshdyn.py View File

6
 from EditorialModel.model import Model
6
 from EditorialModel.model import Model
7
 from leapi.lefactory import LeFactory
7
 from leapi.lefactory import LeFactory
8
 from EditorialModel.backend.json_backend import EmBackendJson
8
 from EditorialModel.backend.json_backend import EmBackendJson
9
-from DataSource.MySQL.leapidatasource import LeDataSourceSQL
10
 
9
 
11
 OUTPUT = 'leapi/dyn.py' if len(sys.argv) == 1 else sys.argv[1]
10
 OUTPUT = 'leapi/dyn.py' if len(sys.argv) == 1 else sys.argv[1]
12
 EMJSON = 'EditorialModel/test/me.json' if len(sys.argv) < 3 else sys.argv[2]
11
 EMJSON = 'EditorialModel/test/me.json' if len(sys.argv) < 3 else sys.argv[2]
14
 em = Model(EmBackendJson(EMJSON))
13
 em = Model(EmBackendJson(EMJSON))
15
 
14
 
16
 fact = LeFactory(OUTPUT)
15
 fact = LeFactory(OUTPUT)
17
-fact.create_pyfile(em, LeDataSourceSQL, {})
18
-print(fact.generate_python(em, LeDataSourceSQL, {}))
16
+fact.create_pyfile(em)
17
+print(fact.generate_python(em))
19
 
18
 
20
 
19
 

Loading…
Cancel
Save