소스 검색

Bugfix in super calls + tests modification given modifications in _prepare_filters

Yann Weber 9 년 전
부모
커밋
117ecad86a
5개의 변경된 파일32개의 추가작업 그리고 11개의 파일을 삭제
  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 파일 보기

@@ -39,4 +39,4 @@ class _LeClass(_LeObject):
39 39
     @classmethod
40 40
     def get(cls, query_filters, field_list = None):
41 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 파일 보기

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

+ 7
- 0
leapi/lerelation.py 파일 보기

@@ -116,6 +116,12 @@ class _LeRel2Type(_LeRelation):
116 116
     def delete(self):
117 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 125
     ## @brief Given a superior and a subordinate, returns the classname of the give rel2type
120 126
     # @param lesupclass LeClass : LeClass child class (can be a LeType or a LeClass child)
121 127
     # @param lesubclass LeType : A LeType child class
@@ -126,3 +132,4 @@ class _LeRel2Type(_LeRelation):
126 132
         subname = lesubclass.__name__
127 133
 
128 134
         return "Rel_%s2%s" % (supname, subname)
135
+

+ 1
- 1
leapi/letype.py 파일 보기

@@ -67,7 +67,7 @@ class _LeType(_LeClass):
67 67
     @classmethod
68 68
     def get(cls, query_filters, field_list = None):
69 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 72
     @classmethod
73 73
     def fieldtypes(cls):

+ 15
- 4
leapi/test/test_lecrud.py 파일 보기

@@ -215,7 +215,10 @@ class LeCrudTestCase(TestCase):
215 215
                 ['titre != "foobar"'],
216 216
 
217 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,7 +227,10 @@ class LeCrudTestCase(TestCase):
224 227
                 ['superior.parent in  [1,2,3,4,5]'],
225 228
 
226 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 234
                 [( (leapi.leobject.REL_SUP, 'parent'), ' in ', '[1,2,3,4,5]')]
229 235
             ),
230 236
             (
@@ -233,7 +239,10 @@ class LeCrudTestCase(TestCase):
233 239
                 [],
234 240
 
235 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,7 +251,9 @@ class LeCrudTestCase(TestCase):
242 251
                 ['titre != "foobar"'],
243 252
 
244 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…
취소
저장