ソースを参照

Renamed the package leobject in leapi

Yann Weber 9年前
コミット
e335019f79

leobject/__init__.py → leapi/__init__.py ファイルの表示


leobject/datasources/__init__.py → leapi/datasources/__init__.py ファイルの表示


leobject/datasources/dummy.py → leapi/datasources/dummy.py ファイルの表示


leobject/datasources/ledatasourcesql.py → leapi/datasources/ledatasourcesql.py ファイルの表示

@@ -3,11 +3,11 @@
3 3
 import pymysql
4 4
 import copy
5 5
 
6
-import leobject
7
-from leobject.datasources.dummy import DummyDatasource
8
-from leobject.leobject import REL_SUB, REL_SUP
6
+import leapi
7
+from leapi.datasources.dummy import DummyDatasource
8
+from leapi.leobject import REL_SUB, REL_SUP
9 9
 
10
-from leobject.letype import LeType
10
+from leapi.letype import LeType
11 11
 
12 12
 from mosql.db import Database, all_to_dicts, one_to_dict
13 13
 from mosql.query import select, insert, update, delete, join
@@ -261,7 +261,7 @@ class LeDataSourceSQL(DummyDatasource):
261 261
     # @param get_sub bool : If True leo is the superior and we want subordinates, else its the opposite
262 262
     # @return a list of dict { 'id_relation':.., 'rank':.., 'lesup':.., 'lesub'.., 'rel_attrs': dict() }
263 263
     def get_related(self, leo, letype, get_sub=True):
264
-        if leobject.letype.LeType not in letype.__bases__:
264
+        if leapi.letype.LeType not in letype.__bases__:
265 265
             raise ValueError("letype argument should be a LeType child class, but got %s"%type(letype))
266 266
         if not isinstance(leo, LeType):
267 267
             raise ValueError("leo argument should be a LeType child class instance but got %s"%type(leo))
@@ -331,7 +331,7 @@ class LeDataSourceSQL(DummyDatasource):
331 331
     # @param id_relation int : relation ID
332 332
     # @param rank int|str : 'first', 'last', or an integer value
333 333
     # @throw ValueError if rank is not valid
334
-    # @throw leobject.leobject.LeObjectQueryError if id_relation don't exists
334
+    # @throw leapi.leapi.LeObjectQueryError if id_relation don't exists
335 335
     def set_relation_rank(self, id_relation, rank):
336 336
         self._check_rank(rank)
337 337
         self._set_relation_rank(id_relation, rank)
@@ -343,11 +343,11 @@ class LeDataSourceSQL(DummyDatasource):
343 343
     # @warning there is no way to fail on rank parameters even giving very bad parameters, if you want a method that may fail on rank use set_relation_rank() instead
344 344
     # @param id_relation int : relation ID
345 345
     # @param rank int|str : 'first', 'last', or an integer value
346
-    # @throw leobject.leobject.LeObjectQueryError if id_relation don't exists
346
+    # @throw leapi.leapi.LeObjectQueryError if id_relation don't exists
347 347
     def _set_relation_rank(self, id_relation, rank):
348 348
         ret = self.get_relation(id_relation, no_attr = True)
349 349
         if not ret:
350
-            raise leobject.leobject.LeObjectQueryError("No relation with id_relation = %d"%id_relation)
350
+            raise leapi.leapi.LeObjectQueryError("No relation with id_relation = %d"%id_relation)
351 351
         lesup = ret['lesup']
352 352
         lesub = ret['lesup']
353 353
         cur_rank = ret['rank']
@@ -447,7 +447,7 @@ class LeDataSourceSQL(DummyDatasource):
447 447
             if res['nature'] != None:
448 448
                 raise ValueError("The relation with id %d is not a rel2type relation"%id_relation)
449 449
 
450
-            leobj = leobject.lefactory.LeFactory.leobj_from_name('LeObject')
450
+            leobj = leapi.lefactory.LeFactory.leobj_from_name('LeObject')
451 451
             lesup = leobj.uid2leobj(res['id_sup'])
452 452
             lesub = leobj.uid2leobj(res['id_sub'])
453 453
 
@@ -558,7 +558,7 @@ class LeDataSourceSQL(DummyDatasource):
558 558
     # @return A list of LeType ordered by rank that are subordinates of lesup in a "nature" relation
559 559
     def get_subordinates(self, lesup, nature):
560 560
         with self.connection as cur:
561
-            id_sup = lesup.lodel_id if isinstance(lesup, leobject.letype.LeType) else MySQL.leroot_lodel_id
561
+            id_sup = lesup.lodel_id if isinstance(lesup, leapi.letype.LeType) else MySQL.leroot_lodel_id
562 562
             sql = select(
563 563
                 MySQL.relations_table_name,
564 564
                 columns=('id_sup',),

leobject/leclass.py → leapi/leclass.py ファイルの表示

@@ -1,6 +1,6 @@
1 1
 #-*- coding: utf-8 -*-
2 2
 
3
-import leobject
3
+import leapi
4 4
 
5 5
 
6 6
 

leobject/lecrud.py → leapi/lecrud.py ファイルの表示

@@ -32,16 +32,6 @@ class _LeCrud(object):
32 32
     def fieldtypes_internal(self):
33 33
         return { fname: ft for fname, ft in cls.fieldtypes().items() if hasattr(ft, 'internal') and ft.internal }
34 34
     
35
-    ## @brief Given a ME uid return the corresponding LeClass or LeType class
36
-    # @return a LeType or LeClass child class
37
-    # @throw KeyError if no corresponding child classes
38
-    @classmethod
39
-    def uid2leobj(cls, uid):
40
-        uid = int(uid)
41
-        if uid not in cls._me_uid:
42
-            raise KeyError("No LeType or LeClass child classes with uid '%d'"%uid)
43
-        return cls._me_uid[uid]
44
-    
45 35
     ## @brief Check fields values
46 36
     # @param complete bool : If True expect that datas contains all fieldtypes with no default values
47 37
     # @param allow_internal bool : If False consider datas as invalid if a value is given for an internal fieldtype

leobject/lefactory.py → leapi/lefactory.py ファイルの表示

@@ -24,7 +24,7 @@ class LeFactory(object):
24 24
     @staticmethod
25 25
     def leobj_from_name(name):
26 26
         if LeFactory.modname is None:
27
-            modname = 'leobject.' + LeFactory.output_file.split('.')[0]
27
+            modname = 'leapi.' + LeFactory.output_file.split('.')[0]
28 28
         else:
29 29
             modname = LeFactory.modname
30 30
         mod = importlib.import_module(modname)
@@ -141,10 +141,10 @@ class LeFactory(object):
141 141
         #Putting import directives in result
142 142
         result += """## @author LeFactory
143 143
 
144
-from leobject.lecrud import _LeCrud
145
-from leobject.leobject import _LeObject
146
-from leobject.leclass import LeClass
147
-from leobject.letype import LeType
144
+from leapi.lecrud import _LeCrud
145
+from leapi.leobject import _LeObject
146
+from leapi.leclass import LeClass
147
+from leapi.letype import LeType
148 148
 import EditorialModel.fieldtypes
149 149
 """
150 150
 
@@ -162,12 +162,12 @@ import %s
162 162
 
163 163
         result += """
164 164
 ## @brief _LeCrud concret class
165
-# @see leobject.lecrud._LeCrud
165
+# @see leapi.lecrud._LeCrud
166 166
 class LeCrud(_LeCrud):
167 167
     _datasource = {ds_classname}(**{ds_kwargs})
168 168
 
169 169
 ## @brief _LeObject concret class
170
-# @see leobject.leobject._LeObject
170
+# @see leapi.leapi._LeObject
171 171
 class LeObject(_LeObject, LeCrud):
172 172
     _me_uid = {me_uid_l}
173 173
 

leobject/leobject.py → leapi/leobject.py ファイルの表示

@@ -2,17 +2,17 @@
2 2
 
3 3
 ## @package leobject API to access lodel datas
4 4
 #
5
-# This package contains abstract classes leobject.leclass.LeClass , leobject.letype.LeType, leobject.leobject._LeObject.
6
-# Those abstract classes are designed to be mother classes of dynamically generated classes ( see leobject.lefactory.LeFactory )
5
+# This package contains abstract classes leapi.leclass.LeClass , leapi.letype.LeType, leapi.leapi._LeObject.
6
+# Those abstract classes are designed to be mother classes of dynamically generated classes ( see leapi.lefactory.LeFactory )
7 7
 
8
-## @package leobject.leobject
8
+## @package leapi.leobject
9 9
 # @brief Abstract class designed to be implemented by LeObject
10 10
 #
11
-# @note LeObject will be generated by leobject.lefactory.LeFactory
11
+# @note LeObject will be generated by leapi.lefactory.LeFactory
12 12
 
13 13
 import re
14 14
 
15
-import leobject
15
+import leapi
16 16
 from .lefactory import LeFactory
17 17
 import EditorialModel
18 18
 from EditorialModel.types import EmType
@@ -24,6 +24,7 @@ REL_SUB = 1
24 24
 class _LeObject(object):
25 25
     
26 26
     ## @brief maps em uid with LeType or LeClass keys are uid values are LeObject childs classes
27
+    # @todo check if this attribute shouldn't be in _LeCrud
27 28
     _me_uid = dict()
28 29
 
29 30
     ## @brief Instantiate with a Model and a DataSource
@@ -34,6 +35,7 @@ class _LeObject(object):
34 35
     ## @brief Given a ME uid return the corresponding LeClass or LeType class
35 36
     # @return a LeType or LeClass child class
36 37
     # @throw KeyError if no corresponding child classes
38
+    # @todo check if this method shouldn't be in _LeCrud
37 39
     @classmethod
38 40
     def uid2leobj(cls, uid):
39 41
         uid = int(uid)
@@ -45,7 +47,7 @@ class _LeObject(object):
45 47
     # @param datas list : A list a dict with fieldname as key
46 48
     # @param cls
47 49
     # @return a list of inserted lodel_id
48
-    # @see leobject.datasources.dummy.DummyDatasource.insert(), leobject.letype.LeType.insert()
50
+    # @see leapi.datasources.dummy.DummyDatasource.insert(), leapi.letype.LeType.insert()
49 51
     @classmethod
50 52
     def insert(cls, letype, datas):
51 53
         if isinstance(datas, dict):
@@ -64,7 +66,7 @@ class _LeObject(object):
64 66
     ## @brief Check if a LeType is a hierarchy root
65 67
     @staticmethod
66 68
     def is_root(leo):
67
-        if isinstance(leo, leobject.letype.LeType):
69
+        if isinstance(leo, leapi.letype.LeType):
68 70
             return False
69 71
         elif isinstance(leo, LeRoot):
70 72
             return True
@@ -332,14 +334,14 @@ class _LeObject(object):
332 334
             if isinstance(leclass, str):
333 335
                 leclass = LeFactory.leobj_from_name(leclass)
334 336
             
335
-            if not isinstance(leclass, type) or not (leobject.leclass.LeClass in leclass.__bases__) or leclass.__class__ == leobject.leclass.LeClass:
337
+            if not isinstance(leclass, type) or not (leapi.leclass.LeClass in leclass.__bases__) or leclass.__class__ == leapi.leclass.LeClass:
336 338
                 raise ValueError("None | str | LeType child class excpected, but got : '%s' %s"%(leclass,type(leclass)))
337 339
 
338 340
         if not(letype is None):
339 341
             if isinstance(letype, str):
340 342
                 letype = LeFactory.leobj_from_name(letype)
341 343
 
342
-            if not isinstance(letype, type) or not leobject.letype.LeType in letype.__bases__ or letype.__class__ == leobject.letype.LeType:
344
+            if not isinstance(letype, type) or not leapi.letype.LeType in letype.__bases__ or letype.__class__ == leapi.letype.LeType:
343 345
                 raise ValueError("None | str | LeType child class excpected, but got : %s"%type(letype))
344 346
 
345 347
             if leclass is None:
@@ -498,12 +500,12 @@ class LeObjectQueryError(LeObjectError):
498 500
 # - Relation can takes two values : superiors or subordinates
499 501
 # - Nature is a relation nature ( see EditorialModel.classtypes )
500 502
 # Examples : "superiors.parent", "subordinates.translation" etc.
501
-# @note The field_list arguement of leobject.leobject._LeObject.get() use the same syntax than the FIELD filter part 
503
+# @note The field_list arguement of leapi.leapi._LeObject.get() use the same syntax than the FIELD filter part 
502 504
 # @subsection oppart OPERATOR
503 505
 # The OPERATOR part of a filter is a comparison operator. There is
504 506
 # - standart comparison operators : = , <, > , <=, >=, !=
505 507
 # - list operators : 'in' and 'not in'
506
-# The list of allowed operators is sotred at leobject.leobject._LeObject._query_operators . 
508
+# The list of allowed operators is sotred at leapi.leapi._LeObject._query_operators . 
507 509
 # @subsection valpart VALUE
508 510
 # The VALUE part of a filter is... just a value...
509 511
 #
@@ -517,7 +519,7 @@ class LeObjectQueryError(LeObjectError):
517 519
 # ( RELATION, NATURE ) where NATURE is a string ( see EditorialModel.classtypes ) and RELATION is one of
518 520
 # the defined constant : 
519 521
 #
520
-# - leobject.leobject.REL_SUB for "subordinates"
521
-# - leobject.leobject.REL_SUP for "superiors"
522
+# - leapi.leapi.REL_SUB for "subordinates"
523
+# - leapi.leapi.REL_SUP for "superiors"
522 524
 #
523 525
 # @note The filters translation process also check if given field are valids compared to the concerned letype and/or the leclass

leobject/letype.py → leapi/letype.py ファイルの表示

@@ -2,17 +2,17 @@
2 2
 
3 3
 ## @package leobject API to access lodel datas
4 4
 #
5
-# This package contains abstract classes leobject.leclass.LeClass , leobject.letype.LeType, leobject.leobject._LeObject.
6
-# Those abstract classes are designed to be mother classes of dynamically generated classes ( see leobject.lefactory.LeFactory )
5
+# This package contains abstract classes leapi.leclass.LeClass , leapi.letype.LeType, leapi.leapi._LeObject.
6
+# Those abstract classes are designed to be mother classes of dynamically generated classes ( see leapi.lefactory.LeFactory )
7 7
 
8
-## @package leobject.leobject
8
+## @package leapi.leobject
9 9
 # @brief Abstract class designed to be implemented by LeObject
10 10
 #
11
-# @note LeObject will be generated by leobject.lefactory.LeFactory
11
+# @note LeObject will be generated by leapi.lefactory.LeFactory
12 12
 
13
-import leobject
14
-from leobject.leclass import LeClass
15
-from leobject.leobject import LeObjectError
13
+import leapi
14
+from leapi.leclass import LeClass
15
+from leapi.leobject import LeObjectError
16 16
 
17 17
 ## @brief Represent an EmType data instance
18 18
 # @note Is not a derivated class of LeClass because the concrete class will be a derivated class from LeClass
@@ -83,7 +83,7 @@ class LeType(object):
83 83
     # @return a dict with LeType instance as key and dict{attr_name:attr_val...} as value
84 84
     # @todo unit tests
85 85
     def linked(self, letype):
86
-        if leobject.letype.LeType not in letype.__bases__:
86
+        if leapi.letype.LeType not in letype.__bases__:
87 87
             raise ValueError("letype has to be a child class of LeType (not an instance) but %s found"%type(letype))
88 88
         
89 89
         if letype in self._linked_types.keys():
@@ -96,7 +96,7 @@ class LeType(object):
96 96
         return self._datasource.get_related(self, letype, get_sub)
97 97
 
98 98
     ## @brief Link this object with a LeObject as subordinate
99
-    # @note shortcut for @ref leobject.leobject._LeObject.link_together()
99
+    # @note shortcut for @ref leapi.leapi._LeObject.link_together()
100 100
     # @param lesub LeObject : The object to be linked with as subordinate
101 101
     # @param **rel_attr : keywords arguments for relations attributes
102 102
     # @return The relation_id if success else return False
@@ -104,24 +104,24 @@ class LeType(object):
104 104
     # @throw LeObkectError if the link already exists
105 105
     # @throw AttributeError if an non existing relation attribute is given as argument
106 106
     # @throw ValueError if the relation attrivute value check fails
107
-    # @see leobject.lefactory.LeFactory.link_together()
107
+    # @see leapi.lefactory.LeFactory.link_together()
108 108
     def link(self, leo, **rel_attr):
109
-        return leobject.lefactory.LeFactory.leobj_from_name('LeObject').link_together(self, leo, **rel_attr)
109
+        return leapi.lefactory.LeFactory.leobj_from_name('LeObject').link_together(self, leo, **rel_attr)
110 110
     
111 111
     ## @brief Returns linked subordinates in a rel2type given a wanted LeType child class
112 112
     # @param letype LeType(class) : The wanted LeType of result
113 113
     # @return A dict with LeType child class instance as key and dict {'id_relation':id, rel_attr_name:rel_attr_value, ...}
114 114
     # @throw LeObjectError if the relation is not possible
115
-    # @see leobject.lefactory.LeFactory.linked_together()
115
+    # @see leapi.lefactory.LeFactory.linked_together()
116 116
     def linked_subordinates(self, letype):
117
-        return leobject.lefactory.LeFactory.leobj_from_name('LeObject').linked_together(self, letype, True)
117
+        return leapi.lefactory.LeFactory.leobj_from_name('LeObject').linked_together(self, letype, True)
118 118
 
119 119
     ## @brief Remove a link with a subordinate
120 120
     # @param leo LeType : LeType child instance
121 121
     # @return True if a link has been deleted
122 122
     # @throw LeObjectError if the relation do not concern the current LeType
123 123
     def unlink_subordinate(self, id_relation):
124
-        return leobject.lefactory.LeFactory.leobj_from_name('LeObject').linked_together(self, leo)
124
+        return leapi.lefactory.LeFactory.leobj_from_name('LeObject').linked_together(self, leo)
125 125
 
126 126
     ## @brief Remove a link bewteen this object and another
127 127
     # @param leo LeType : LeType child class instance
@@ -143,24 +143,24 @@ class LeType(object):
143 143
     # @param replace_if_exists bool : if True delete the old superior and set the new one. If False and there is a superior raise an LeObjectQueryError
144 144
     # @return The relation ID or False if fails
145 145
     def superior_add(self, leo, nature, rank = 'last', replace_if_exists = False):
146
-        return leobject.lefactory.LeFactory.leobj_from_name('LeObject').hierarchy_add(leo, self, nature, rank, replace_if_exists)
146
+        return leapi.lefactory.LeFactory.leobj_from_name('LeObject').hierarchy_add(leo, self, nature, rank, replace_if_exists)
147 147
 
148 148
     ## @brief Delete a superior given a relation's natue
149 149
     # @param leo LeType | LeRoot : The superior to delete
150 150
     # @param nature str : The nature of the relation @ref EditorialModel.classtypes
151 151
     # @return True if deletion is a success
152 152
     def superior_del(self, leo, nature):
153
-        return leobject.lefactory.leobj_from_name('LeObject').hierarchy_del(leo, self, nature)
153
+        return leapi.lefactory.leobj_from_name('LeObject').hierarchy_del(leo, self, nature)
154 154
     
155 155
     ## @brief Fetch superiors by depth
156 156
     # @return A list of LeObject ordered by depth (the first is the one with the bigger depth)
157 157
     def superiors(self):
158
-        return leobject.lefactory.leobj_from_name('LeObject').hierarchy_get(self,nature, leo_is_sup = False)
158
+        return leapi.lefactory.leobj_from_name('LeObject').hierarchy_get(self,nature, leo_is_sup = False)
159 159
 
160 160
     ## @brief Fetch subordinates ordered by rank
161 161
     # @return A list of LeObject ordered by rank
162 162
     def subordinates(self):
163
-        return leobject.lefactory.leobj_from_name('LeObject').hierarchy_get(self,nature, leo_is_sup = True)
163
+        return leapi.lefactory.leobj_from_name('LeObject').hierarchy_get(self,nature, leo_is_sup = True)
164 164
     
165 165
     ## @brief Delete a LeType from the datasource
166 166
     # @param filters list : list of filters (see @ref leobject_filters)
@@ -170,7 +170,7 @@ class LeType(object):
170 170
     # @throw Leo exception if the lodel_id identify an object from another type
171 171
     @classmethod
172 172
     def delete(cls, filters):
173
-        return leobject.lefactory.LeFactory.leobject().delete(cls, filters)
173
+        return leapi.lefactory.LeFactory.leobject().delete(cls, filters)
174 174
         
175 175
     ## @brief Update a LeType in db
176 176
     def db_update(self):
@@ -183,7 +183,7 @@ class LeType(object):
183 183
     # @param cls
184 184
     # return bool
185 185
     def update(cls, filters, datas):
186
-        return leobject.lefactory.LeFactory.leobject().update(letype = cls, filters = filters, datas = datas)
186
+        return leapi.lefactory.LeFactory.leobject().update(letype = cls, filters = filters, datas = datas)
187 187
         
188 188
     ## @brief Insert a new LeType in the datasource
189 189
     # @param **datas list : A list of dict containing the datas

leobject/test/__init__.py → leapi/test/__init__.py ファイルの表示


leobject/test/test_ledatasourcesql.py → leapi/test/test_ledatasourcesql.py ファイルの表示

@@ -4,7 +4,7 @@ import unittest
4 4
 import sqlite3
5 5
 import pymysql
6 6
 from unittest import TestCase
7
-from leobject.datasources.ledatasourcesql import LeDataSourceSQL
7
+from leapi.datasources.ledatasourcesql import LeDataSourceSQL
8 8
 from mosql.db import Database
9 9
 
10 10
 

leobject/test/test_lefactory.py → leapi/test/test_lefactory.py ファイルの表示

@@ -6,14 +6,14 @@ import sys
6 6
 import shutil
7 7
 
8 8
 import EditorialModel
9
-import leobject
10
-import leobject.test.utils
11
-from leobject.lefactory import LeFactory
9
+import leapi
10
+import leapi.test.utils
11
+from leapi.lefactory import LeFactory
12 12
 
13 13
 class TestLeFactorySyntax(TestCase):
14 14
 
15 15
     def test_generated_code_syntax(self):
16
-        py = LeFactory.generate_python(**leobject.test.utils.genepy_args)
16
+        py = LeFactory.generate_python(**leapi.test.utils.genepy_args)
17 17
         pyc = compile(py, "dyn.py", 'exec')
18 18
         exec(pyc, globals())
19 19
 
@@ -22,14 +22,14 @@ class TestLeFactory(TestCase):
22 22
     @classmethod
23 23
     def setUpClass(cls):
24 24
         """ Write the generated code in a temporary directory and import it """
25
-        cls.tmpdir = leobject.test.utils.tmp_load_factory_code()
25
+        cls.tmpdir = leapi.test.utils.tmp_load_factory_code()
26 26
     @classmethod
27 27
     def tearDownClass(cls):
28 28
         """ Remove the temporary directory created at class setup """
29
-        leobject.test.utils.cleanup(cls.tmpdir)
29
+        leapi.test.utils.cleanup(cls.tmpdir)
30 30
 
31 31
     def setUp(self):
32
-        backend=leobject.test.utils.genepy_args['backend_cls'](**leobject.test.utils.genepy_args['backend_args'])
32
+        backend=leapi.test.utils.genepy_args['backend_cls'](**leapi.test.utils.genepy_args['backend_args'])
33 33
         self.model = EditorialModel.model.Model(backend = backend)
34 34
 
35 35
     def test_leobject(self):
@@ -38,11 +38,11 @@ class TestLeFactory(TestCase):
38 38
         self.assertTrue(hasattr(dyncode, 'LeObject'))
39 39
 
40 40
         for uid, cls in dyncode.LeObject._me_uid.items():
41
-            if leobject.letype.LeType in cls.__bases__:
42
-                self.assertNotEqual(cls, leobject.letype.LeType)
41
+            if leapi.letype.LeType in cls.__bases__:
42
+                self.assertNotEqual(cls, leapi.letype.LeType)
43 43
                 self.assertEqual(cls._type_id, uid)
44
-            elif leobject.leclass.LeClass in cls.__bases__:
45
-                self.assertNotEqual(cls, leobject.leclass.LeClass)
44
+            elif leapi.leclass.LeClass in cls.__bases__:
45
+                self.assertNotEqual(cls, leapi.leclass.LeClass)
46 46
                 self.assertEqual(cls._class_id, uid)
47 47
             else:
48 48
                 self.fail("Bad instance type for _me_uid values : %s"%type(cls))
@@ -60,7 +60,7 @@ class TestLeFactory(TestCase):
60 60
             self.assertEqual(leclass._class_id, emclass.uid)
61 61
             
62 62
             #Testing inheritance
63
-            self.assertEqual(set(leclass.__bases__), set([dyncode.LeObject, leobject.leclass.LeClass]))
63
+            self.assertEqual(set(leclass.__bases__), set([dyncode.LeObject, leapi.leclass.LeClass]))
64 64
             
65 65
             #Testing _linked_types attr
66 66
             self.assertEqual(
@@ -95,7 +95,7 @@ class TestLeFactory(TestCase):
95 95
             #Testing inheritance
96 96
             self.assertEqual(
97 97
                 set(letype.__bases__),
98
-                set([leobject.letype.LeType, letype._leclass])
98
+                set([leapi.letype.LeType, letype._leclass])
99 99
             )
100 100
 
101 101
             #Testing _fields

leobject/test/test_leobject.py → leapi/test/test_leobject.py ファイルの表示

@@ -7,9 +7,9 @@ from unittest import TestCase
7 7
 from unittest.mock import patch
8 8
 
9 9
 import EditorialModel
10
-import leobject
11
-import leobject.test.utils
12
-from leobject.leobject import _LeObject
10
+import leapi
11
+import leapi.test.utils
12
+from leapi.leobject import _LeObject
13 13
 
14 14
 ## Testing methods that need the generated code
15 15
 class LeObjectTestCase(TestCase):
@@ -17,11 +17,11 @@ class LeObjectTestCase(TestCase):
17 17
     @classmethod
18 18
     def setUpClass(cls):
19 19
         """ Write the generated code in a temporary directory and import it """
20
-        cls.tmpdir = leobject.test.utils.tmp_load_factory_code()
20
+        cls.tmpdir = leapi.test.utils.tmp_load_factory_code()
21 21
     @classmethod
22 22
     def tearDownClass(cls):
23 23
         """ Remove the temporary directory created at class setup """
24
-        leobject.test.utils.cleanup(cls.tmpdir)
24
+        leapi.test.utils.cleanup(cls.tmpdir)
25 25
 
26 26
     def test_split_query_filter(self):
27 27
         """ Tests the _split_filter() classmethod """
@@ -69,9 +69,9 @@ class LeObjectTestCase(TestCase):
69 69
         import dyncode
70 70
         for i in dyncode.LeObject._me_uid.keys():
71 71
             cls = dyncode.LeObject.uid2leobj(i)
72
-            if leobject.letype.LeType in cls.__bases__:
72
+            if leapi.letype.LeType in cls.__bases__:
73 73
                 self.assertEqual(i, cls._type_id)
74
-            elif leobject.leclass.LeClass in cls.__bases__:
74
+            elif leapi.leclass.LeClass in cls.__bases__:
75 75
                 self.assertEqual(i, cls._class_id)
76 76
             else:
77 77
                 self.fail("Bad value returned : '%s'"%cls)
@@ -110,8 +110,8 @@ class LeObjectTestCase(TestCase):
110 110
         test_v = [
111 111
             ('',''),
112 112
             (Personnes, Numero),
113
-            (leobject.leclass.LeClass, Numero),
114
-            (Publication, leobject.letype.LeType),
113
+            (leapi.leclass.LeClass, Numero),
114
+            (Publication, leapi.letype.LeType),
115 115
             ('foobar', Numero),
116 116
             (Publication, 'foobar'),
117 117
             (Numero, Numero),
@@ -143,7 +143,7 @@ class LeObjectTestCase(TestCase):
143 143
         LeObject._check_fields(None, None, EditorialModel.classtypes.common_fields.keys())
144 144
 
145 145
         #Invalid fields
146
-        with self.assertRaises(leobject.leobject.LeObjectQueryError):
146
+        with self.assertRaises(leapi.leobject.LeObjectQueryError):
147 147
             LeObject._check_fields(None, None, Numero._fields)
148 148
 
149 149
     def test_prepare_filters(self):
@@ -158,7 +158,7 @@ class LeObjectTestCase(TestCase):
158 158
 
159 159
         filt, rfilt = LeObject._prepare_filters(filters, Numero, None)
160 160
         self.assertEqual(filt, [('lodel_id', '=', '1')])
161
-        self.assertEqual(rfilt, [((leobject.leobject.REL_SUP,'parent'), '>', '2')])
161
+        self.assertEqual(rfilt, [((leapi.leobject.REL_SUP,'parent'), '>', '2')])
162 162
         
163 163
         #All fields, no relationnal and class given
164 164
         filters = []
@@ -179,7 +179,7 @@ class LeObjectTestCase(TestCase):
179 179
         
180 180
         filt, rfilt = LeObject._prepare_filters(filters, Numero, None)
181 181
         self.assertEqual(filt, [('lodel_id', '<=', '0')])
182
-        self.assertEqual(rfilt, [((leobject.leobject.REL_SUB,'parent'), '=', '2')])
182
+        self.assertEqual(rfilt, [((leapi.leobject.REL_SUB,'parent'), '=', '2')])
183 183
 
184 184
     def test_prepare_filters_invalid(self):
185 185
         """ Testing the _prepare_filters() method """
@@ -192,7 +192,7 @@ class LeObjectTestCase(TestCase):
192 192
             filters.append('%s=1'%field)
193 193
             res_filt.append((field, '=', '1'))
194 194
         
195
-        with self.assertRaises(leobject.leobject.LeObjectQueryError):
195
+        with self.assertRaises(leapi.leobject.LeObjectQueryError):
196 196
             LeObject._prepare_filters(filters, None, None)
197 197
 
198 198
 
@@ -207,13 +207,13 @@ class LeObjectMockDatasourceTestCase(TestCase):
207 207
     @classmethod
208 208
     def setUpClass(cls):
209 209
         """ Write the generated code in a temporary directory and import it """
210
-        cls.tmpdir = leobject.test.utils.tmp_load_factory_code()
210
+        cls.tmpdir = leapi.test.utils.tmp_load_factory_code()
211 211
     @classmethod
212 212
     def tearDownClass(cls):
213 213
         """ Remove the temporary directory created at class setup """
214
-        leobject.test.utils.cleanup(cls.tmpdir)
214
+        leapi.test.utils.cleanup(cls.tmpdir)
215 215
     
216
-    @patch('leobject.datasources.dummy.DummyDatasource.insert')
216
+    @patch('leapi.datasources.dummy.DummyDatasource.insert')
217 217
     def test_insert(self, dsmock):
218 218
         from dyncode import Publication, Numero, LeObject
219 219
         ndatas = [
@@ -229,7 +229,7 @@ class LeObjectMockDatasourceTestCase(TestCase):
229 229
             dsmock.assert_called_once_with(Numero, Publication, ndats)
230 230
             dsmock.reset_mock()
231 231
 
232
-    @patch('leobject.datasources.dummy.DummyDatasource.update')
232
+    @patch('leapi.datasources.dummy.DummyDatasource.update')
233 233
     def test_update(self, dsmock):
234 234
         from dyncode import Publication, Numero, LeObject
235 235
 
@@ -242,7 +242,7 @@ class LeObjectMockDatasourceTestCase(TestCase):
242 242
             (   ['superior.parent in [1,2,3,4,5,6]', 'titre != "FooBar"'],
243 243
                 {'titre':'FooBar'},
244 244
                 [( 'titre','!=','"FooBar"')],
245
-                [( (leobject.leobject.REL_SUP, 'parent') ,' in ', '[1,2,3,4,5,6]')]
245
+                [( (leapi.leobject.REL_SUP, 'parent') ,' in ', '[1,2,3,4,5,6]')]
246 246
             ),
247 247
         ]
248 248
 
@@ -255,7 +255,7 @@ class LeObjectMockDatasourceTestCase(TestCase):
255 255
             dsmock.assert_called_once_with(Numero, Publication, ds_filters, ds_relfilters, datas)
256 256
             dsmock.reset_mock()
257 257
 
258
-    @patch('leobject.datasources.dummy.DummyDatasource.delete')
258
+    @patch('leapi.datasources.dummy.DummyDatasource.delete')
259 259
     def test_delete(self, dsmock):
260 260
         from dyncode import Publication, Numero, LeObject
261 261
 
@@ -268,7 +268,7 @@ class LeObjectMockDatasourceTestCase(TestCase):
268 268
             (
269 269
                 ['subordinate.parent not in [1,2,3]', 'titre = "titre nul"'],
270 270
                 [('titre','=', '"titre nul"')],
271
-                [( (leobject.leobject.REL_SUB, 'parent'), ' not in ', '[1,2,3]')]
271
+                [( (leapi.leobject.REL_SUB, 'parent'), ' not in ', '[1,2,3]')]
272 272
             ),
273 273
         ]
274 274
 
@@ -281,7 +281,7 @@ class LeObjectMockDatasourceTestCase(TestCase):
281 281
             dsmock.assert_called_once_with(Numero, Publication, ds_filters, ds_relfilters)
282 282
             dsmock.reset_mock()
283 283
         
284
-    @patch('leobject.datasources.dummy.DummyDatasource.get')
284
+    @patch('leapi.datasources.dummy.DummyDatasource.get')
285 285
     @unittest.skip('Dummy datasource doesn\'t fit anymore')
286 286
     def test_get(self, dsmock):
287 287
         from dyncode import Publication, Numero, LeObject
@@ -291,7 +291,7 @@ class LeObjectMockDatasourceTestCase(TestCase):
291 291
                 ['lodel_id', 'superior.parent'],
292 292
                 ['titre != "foobar"'],
293 293
 
294
-                ['lodel_id', (leobject.leobject.REL_SUP, 'parent')],
294
+                ['lodel_id', (leapi.leobject.REL_SUP, 'parent')],
295 295
                 [('titre','!=', '"foobar"')],
296 296
                 []
297 297
             ),
@@ -299,9 +299,9 @@ class LeObjectMockDatasourceTestCase(TestCase):
299 299
                 ['lodel_id', 'titre', 'superior.parent', 'subordinate.translation'],
300 300
                 ['superior.parent in  [1,2,3,4,5]'],
301 301
 
302
-                ['lodel_id', 'titre', (leobject.leobject.REL_SUP,'parent'), (leobject.leobject.REL_SUB, 'translation')],
302
+                ['lodel_id', 'titre', (leapi.leobject.REL_SUP,'parent'), (leapi.leobject.REL_SUB, 'translation')],
303 303
                 [],
304
-                [( (leobject.leobject.REL_SUP, 'parent'), ' in ', '[1,2,3,4,5]')]
304
+                [( (leapi.leobject.REL_SUP, 'parent'), ' in ', '[1,2,3,4,5]')]
305 305
             ),
306 306
             (
307 307
                 [],
@@ -318,7 +318,7 @@ class LeObjectMockDatasourceTestCase(TestCase):
318 318
             dsmock.assert_called_with(Publication, Numero, fl_ds, filters_ds, rfilters_ds)
319 319
             dsmock.reset_mock()
320 320
 
321
-    @patch('leobject.datasources.dummy.DummyDatasource.get')
321
+    @patch('leapi.datasources.dummy.DummyDatasource.get')
322 322
     @unittest.skip('Dummy datasource doesn\'t fit anymore')
323 323
     def test_get_incomplete_target(self, dsmock):
324 324
         """ Testing LeObject.get() method with partial target specifier """

leobject/test/test_letype.py → leapi/test/test_letype.py ファイルの表示

@@ -7,26 +7,26 @@ from unittest import TestCase
7 7
 from unittest.mock import patch
8 8
 
9 9
 import EditorialModel
10
-import leobject
11
-import leobject.test.utils
10
+import leapi
11
+import leapi.test.utils
12 12
 
13 13
 class LeTypeTestCase(TestCase):
14 14
     
15 15
     @classmethod
16 16
     def setUpClass(cls):
17 17
         """ Write the generated code in a temporary directory and import it """
18
-        cls.tmpdir = leobject.test.utils.tmp_load_factory_code()
18
+        cls.tmpdir = leapi.test.utils.tmp_load_factory_code()
19 19
     @classmethod
20 20
     def tearDownClass(cls):
21 21
         """ Remove the temporary directory created at class setup """
22
-        leobject.test.utils.cleanup(cls.tmpdir)
22
+        leapi.test.utils.cleanup(cls.tmpdir)
23 23
  
24 24
     def test_init(self):
25 25
         """ testing the constructor """
26 26
         from dyncode import Publication, Numero, LeObject
27 27
         
28 28
         with self.assertRaises(NotImplementedError):
29
-            leobject.letype.LeType(42)
29
+            leapi.letype.LeType(42)
30 30
 
31 31
         badargs = [
32 32
             {'class_id':Numero._class_id + 1},
@@ -52,10 +52,10 @@ class LeTypeTestCase(TestCase):
52 52
         datas = { 'titre':'foobar' }
53 53
         Numero.check_datas(datas, False)
54 54
         Numero.check_datas(datas, True)
55
-        with self.assertRaises(leobject.leobject.LeObjectError):
55
+        with self.assertRaises(leapi.leobject.LeObjectError):
56 56
             Numero.check_datas_or_raise({}, True)
57 57
 
58
-    @patch('leobject.letype.LeType.populate')
58
+    @patch('leapi.letype.LeType.populate')
59 59
     def test_datas(self, dsmock):
60 60
         """ Testing the datas @property method """
61 61
         from dyncode import Publication, Numero, LeObject
@@ -70,13 +70,13 @@ class LeTypeMockDsTestCase(TestCase):
70 70
     @classmethod
71 71
     def setUpClass(cls):
72 72
         """ Write the generated code in a temporary directory and import it """
73
-        cls.tmpdir = leobject.test.utils.tmp_load_factory_code()
73
+        cls.tmpdir = leapi.test.utils.tmp_load_factory_code()
74 74
     @classmethod
75 75
     def tearDownClass(cls):
76 76
         """ Remove the temporary directory created at class setup """
77
-        leobject.test.utils.cleanup(cls.tmpdir)
77
+        leapi.test.utils.cleanup(cls.tmpdir)
78 78
 
79
-    @patch('leobject.datasources.dummy.DummyDatasource.get')
79
+    @patch('leapi.datasources.dummy.DummyDatasource.get')
80 80
     @unittest.skip('Dummy datasource doesn\'t fit anymore')
81 81
     def test_populate(self, dsmock):
82 82
         from dyncode import Publication, Numero, LeObject
@@ -86,7 +86,7 @@ class LeTypeMockDsTestCase(TestCase):
86 86
         num.populate()
87 87
         dsmock.assert_called_once_with(Publication, Numero, missing_fields, [('lodel_id','=','1')],[])
88 88
 
89
-    @patch('leobject.datasources.dummy.DummyDatasource.update')
89
+    @patch('leapi.datasources.dummy.DummyDatasource.update')
90 90
     def test_update(self, dsmock):
91 91
         from dyncode import Publication, Numero, LeObject
92 92
         
@@ -95,14 +95,14 @@ class LeTypeMockDsTestCase(TestCase):
95 95
         Numero.update(['lodel_id = 1'], datas)
96 96
         dsmock.assert_called_once_with(Numero, Publication, [('lodel_id','=','1')], [], datas)
97 97
 
98
-    @patch('leobject.datasources.dummy.DummyDatasource.delete')
98
+    @patch('leapi.datasources.dummy.DummyDatasource.delete')
99 99
     def test_delete(self, dsmock):
100 100
         from dyncode import Publication, Numero, LeObject
101 101
         
102 102
         Numero.delete(['lodel_id = 1'])
103 103
         dsmock.assert_called_once_with(Numero, Publication, [('lodel_id','=','1')], [])
104 104
 
105
-    @patch('leobject.datasources.dummy.DummyDatasource.update')
105
+    @patch('leapi.datasources.dummy.DummyDatasource.update')
106 106
     def test_db_update(self, dsmock):
107 107
         from dyncode import Publication, Numero, LeObject
108 108
         
@@ -110,7 +110,7 @@ class LeTypeMockDsTestCase(TestCase):
110 110
         num.db_update()
111 111
         dsmock.assert_called_once_with(Numero, Publication, [('lodel_id','=','1')], [], num.datas)
112 112
 
113
-    @patch('leobject.datasources.dummy.DummyDatasource.delete')
113
+    @patch('leapi.datasources.dummy.DummyDatasource.delete')
114 114
     def test_db_delete(self, dsmock):
115 115
         from dyncode import Publication, Numero, LeObject
116 116
 

leobject/test/utils.py → leapi/test/utils.py ファイルの表示

@@ -3,10 +3,10 @@ import shutil
3 3
 import sys
4 4
 
5 5
 import EditorialModel
6
-import leobject
6
+import leapi
7 7
 from EditorialModel.backend.json_backend import EmBackendJson
8
-from leobject.datasources.dummy import DummyDatasource
9
-from leobject.lefactory import LeFactory
8
+from leapi.datasources.dummy import DummyDatasource
9
+from leapi.lefactory import LeFactory
10 10
 
11 11
 
12 12
 

読み込み中…
キャンセル
保存