Browse Source

Bugfix in super calls + tests modification given modifications in _prepare_filters

Yann Weber 9 years ago
parent
commit
117ecad86a
5 changed files with 32 additions and 11 deletions
  1. 1
    1
      leapi/leclass.py
  2. 8
    5
      leapi/lecrud.py
  3. 7
    0
      leapi/lerelation.py
  4. 1
    1
      leapi/letype.py
  5. 15
    4
      leapi/test/test_lecrud.py

+ 1
- 1
leapi/leclass.py View File

39
     @classmethod
39
     @classmethod
40
     def get(cls, query_filters, field_list = None):
40
     def get(cls, query_filters, field_list = None):
41
         query_filters.append(('class_id', '=', cls._class_id))
41
         query_filters.append(('class_id', '=', cls._class_id))
42
-        return cls.name2class('LeObject').get(query_filters, field_list)
42
+        return super().get(query_filters, field_list)

+ 8
- 5
leapi/lecrud.py View File

13
     # @param exptexptions dict : A list of data check Exception with concerned field (or stuff) as key
13
     # @param exptexptions dict : A list of data check Exception with concerned field (or stuff) as key
14
     def __init__(self, msg = "Unknow error", exceptions = None):
14
     def __init__(self, msg = "Unknow error", exceptions = None):
15
         self._msg = msg
15
         self._msg = msg
16
-        self._exceptions = list() if exceptions is None else exceptions
16
+        self._exceptions = dict() if exceptions is None else exceptions
17
+
18
+    def __repr__(self):
19
+        return self.__str__()
17
 
20
 
18
     def __str__(self):
21
     def __str__(self):
19
         msg = self._msg
22
         msg = self._msg
257
 
260
 
258
         #preparing filters
261
         #preparing filters
259
         filters, relational_filters = cls._prepare_filters(query_filters)
262
         filters, relational_filters = cls._prepare_filters(query_filters)
260
-
263
+        
261
         #Fetching editorial components from datasource
264
         #Fetching editorial components from datasource
262
         results = cls._datasource.select(cls, field_list, filters, relational_filters)
265
         results = cls._datasource.select(cls, field_list, filters, relational_filters)
263
 
266
 
267
     # @param datas dict : The value of object we want to insert
270
     # @param datas dict : The value of object we want to insert
268
     # @return A new id if success else False
271
     # @return A new id if success else False
269
     @classmethod
272
     @classmethod
270
-    def insert(cls, datas = datas, classname = None):
273
+    def insert(cls, datas, classname = None):
271
         callcls = cls if classname is None else cls.name2class(classname)
274
         callcls = cls if classname is None else cls.name2class(classname)
272
         if not callcls.is_letype() and not callcls.implements_lerelation():
275
         if not callcls.is_letype() and not callcls.implements_lerelation():
273
             raise ValueError("You can only insert relations and LeTypes objects but tying to insert a '%s'"%callcls.__name__)
276
             raise ValueError("You can only insert relations and LeTypes objects but tying to insert a '%s'"%callcls.__name__)
285
     @classmethod
288
     @classmethod
286
     def prepare_datas(cls, datas, complete = False, allow_internal = True):
289
     def prepare_datas(cls, datas, complete = False, allow_internal = True):
287
         if not complete:
290
         if not complete:
288
-            warnings.warn("Actual implementation can make datas construction and consitency checks fails when datas are not complete")
291
+            warnings.warn("\nActual implementation can make datas construction and consitency checks fails when datas are not complete\n")
289
         ret_datas = cls.check_datas_value(datas, complete, allow_internal)
292
         ret_datas = cls.check_datas_value(datas, complete, allow_internal)
290
         if isinstance(ret_datas, Exception):
293
         if isinstance(ret_datas, Exception):
291
             raise ret_datas
294
             raise ret_datas
417
                     res_filters.append((field,operator, value))
420
                     res_filters.append((field,operator, value))
418
 
421
 
419
         if len(err_l) > 0:
422
         if len(err_l) > 0:
420
-            raise LeApiDataCheckError(err_l)
423
+            raise LeApiDataCheckError("Error while preparing filters : ", err_l)
421
         return (res_filters, rel_filters)
424
         return (res_filters, rel_filters)
422
 
425
 
423
 
426
 

+ 7
- 0
leapi/lerelation.py View File

116
     def delete(self):
116
     def delete(self):
117
         lecrud._LeCrud._delete(self)
117
         lecrud._LeCrud._delete(self)
118
 
118
 
119
+    @classmethod
120
+    def insert(cls, datas, classname):
121
+        if 'nature' not in datas:
122
+            datas['nature'] = None
123
+        cls.name2class('LeCrud').insert(datas, classname)
124
+
119
     ## @brief Given a superior and a subordinate, returns the classname of the give rel2type
125
     ## @brief Given a superior and a subordinate, returns the classname of the give rel2type
120
     # @param lesupclass LeClass : LeClass child class (can be a LeType or a LeClass child)
126
     # @param lesupclass LeClass : LeClass child class (can be a LeType or a LeClass child)
121
     # @param lesubclass LeType : A LeType child class
127
     # @param lesubclass LeType : A LeType child class
126
         subname = lesubclass.__name__
132
         subname = lesubclass.__name__
127
 
133
 
128
         return "Rel_%s2%s" % (supname, subname)
134
         return "Rel_%s2%s" % (supname, subname)
135
+

+ 1
- 1
leapi/letype.py View File

67
     @classmethod
67
     @classmethod
68
     def get(cls, query_filters, field_list = None):
68
     def get(cls, query_filters, field_list = None):
69
         query_filters.append(('type_id', '=', cls._type_id))
69
         query_filters.append(('type_id', '=', cls._type_id))
70
-        return cls._leclass.get(query_filters, field_list)
70
+        return super().get(query_filters, field_list)
71
 
71
 
72
     @classmethod
72
     @classmethod
73
     def fieldtypes(cls):
73
     def fieldtypes(cls):

+ 15
- 4
leapi/test/test_lecrud.py View File

215
                 ['titre != "foobar"'],
215
                 ['titre != "foobar"'],
216
 
216
 
217
                 ['lodel_id', (leapi.leobject.REL_SUP, 'parent')],
217
                 ['lodel_id', (leapi.leobject.REL_SUP, 'parent')],
218
-                [('titre','!=', '"foobar"')],
218
+                [   ('titre','!=', '"foobar"'),
219
+                    ('type_id', '=', Numero._type_id),
220
+                    ('class_id', '=', Numero._class_id),
221
+                ],
219
                 []
222
                 []
220
             ),
223
             ),
221
             (
224
             (
224
                 ['superior.parent in  [1,2,3,4,5]'],
227
                 ['superior.parent in  [1,2,3,4,5]'],
225
 
228
 
226
                 ['lodel_id', 'titre', (leapi.leobject.REL_SUP,'parent'), (leapi.leobject.REL_SUB, 'translation')],
229
                 ['lodel_id', 'titre', (leapi.leobject.REL_SUP,'parent'), (leapi.leobject.REL_SUB, 'translation')],
227
-                [],
230
+                [
231
+                    ('type_id', '=', Numero._type_id),
232
+                    ('class_id', '=', Numero._class_id),
233
+                ],
228
                 [( (leapi.leobject.REL_SUP, 'parent'), ' in ', '[1,2,3,4,5]')]
234
                 [( (leapi.leobject.REL_SUP, 'parent'), ' in ', '[1,2,3,4,5]')]
229
             ),
235
             ),
230
             (
236
             (
233
                 [],
239
                 [],
234
 
240
 
235
                 Numero._fields,
241
                 Numero._fields,
236
-                [],
242
+                [
243
+                    ('type_id', '=', Numero._type_id),
244
+                    ('class_id', '=', Numero._class_id),
245
+                ],
237
                 []
246
                 []
238
             ),
247
             ),
239
             (
248
             (
242
                 ['titre != "foobar"'],
251
                 ['titre != "foobar"'],
243
 
252
 
244
                 ['lodel_id', 'titre', 'soustitre', (leapi.leobject.REL_SUP, 'parent')],
253
                 ['lodel_id', 'titre', 'soustitre', (leapi.leobject.REL_SUP, 'parent')],
245
-                [('titre','!=', '"foobar"')],
254
+                [   ('titre','!=', '"foobar"'),
255
+                    ('class_id', '=', Textes._class_id),
256
+                ],
246
                 [],
257
                 [],
247
             ),
258
             ),
248
             (
259
             (

Loading…
Cancel
Save