Parcourir la source

Upgrade type check in leo fieldtype + unskip some tests

Yann Weber il y a 9 ans
Parent
révision
6a6326831a
3 fichiers modifiés avec 55 ajouts et 28 suppressions
  1. 1
    1
      EditorialModel/fieldtypes/leo.py
  2. 54
    26
      leapi/test/test_lerelation.py
  3. 0
    1
      leapi/test/test_letype.py

+ 1
- 1
EditorialModel/fieldtypes/leo.py Voir le fichier

@@ -17,7 +17,7 @@ class EmFieldType(GenericFieldType):
17 17
     def _check_data_value(self, value):
18 18
         err = None
19 19
         if not isinstance(value, int):
20
-            if not isinstance(value, letype._LeType):
20
+            if not letype._LeType.implements_leobject():
21 21
                 return (None, ValueError("An instance of a child class of LeType was expected"))
22 22
             if not hasattr(value, 'lodel_id'):
23 23
                 return (None, ValueError("The LeType instance given has no lodel_id !"))

+ 54
- 26
leapi/test/test_lerelation.py Voir le fichier

@@ -22,7 +22,6 @@ class LeRelationTestCase(TestCase):
22 22
         """ Remove the temporary directory created at class setup """
23 23
         leapi.test.utils.cleanup(cls.tmpdir)
24 24
     
25
-    # @unittest.skip("Wating LeRelation._prepare_filters() to unskip")
26 25
     def test_prepare_filters(self):
27 26
         """ Testing the _prepare_filters() method """
28 27
         from dyncode import Numero, LeObject, LeRelation
@@ -80,7 +79,6 @@ class LeRelationTestCase(TestCase):
80 79
 
81 80
 class LeHierarch(LeRelationTestCase):
82 81
     
83
-    # @unittest.skip("Wait for  LeRelation._prepare_filters() to unskip")
84 82
     @patch('leapi.datasources.dummy.DummyDatasource.select')
85 83
     def test_get(self, dsmock):
86 84
         """ Tests the LeHierarch.get() method """
@@ -124,40 +122,67 @@ class LeHierarch(LeRelationTestCase):
124 122
 
125 123
             dsmock.reset_mock()
126 124
     
127
-    @unittest.skip("Wait for  LeRelation._prepare_filters() to unskip")
128 125
     @patch('leapi.datasources.dummy.DummyDatasource.insert')
129 126
     def test_insert(self, dsmock):
130 127
         """ Testing LeHierarch insert method """
131 128
         from dyncode import LeCrud, Publication, Numero, Personnes, LeObject, Rubrique, LeHierarch, LeRelation
132 129
         queries = [
133
-            {
134
-                'lesup': Rubrique(7),
135
-                'lesub': Numero(42),
136
-                'nature': 'parent',
137
-            },
138
-            {
139
-                'lesup': 7,
140
-                'lesub': 42,
141
-                'nature': 'parent',
142
-            },
143
-            {
144
-                'lesup': LeObject(7),
145
-                'lesub': LeObject(42),
146
-                'nature': 'parent',
147
-            },
148
-            {
149
-                'lesup': LeObject(7),
150
-                'lesub': 42,
151
-                'nature': 'parent',
152
-            }
130
+            (
131
+                {
132
+                    'lesup': Rubrique(7),
133
+                    'lesub': Numero(42),
134
+                    'nature': 'parent',
135
+                },
136
+                {
137
+                    'lesup': Rubrique(7),
138
+                    'lesub': Numero(42),
139
+                    'nature': 'parent',
140
+                }
141
+            ),
142
+            (
143
+                {
144
+                    'lesup': 7,
145
+                    'lesub': 42,
146
+                    'nature': 'parent',
147
+                },
148
+                {
149
+                    'lesup': LeObject(7),
150
+                    'lesub': LeObject(42),
151
+                    'nature': 'parent',
152
+                }
153
+            ),
154
+            (
155
+                {
156
+                    'lesup': LeObject(7),
157
+                    'lesub': LeObject(42),
158
+                    'nature': 'parent',
159
+                },
160
+                {
161
+                    'lesup': LeObject(7),
162
+                    'lesub': LeObject(42),
163
+                    'nature': 'parent',
164
+                }
165
+            ),
166
+            (
167
+                {
168
+                    'lesup': LeObject(7),
169
+                    'lesub': 42,
170
+                    'nature': 'parent',
171
+                },
172
+                {
173
+                    'lesup': LeObject(7),
174
+                    'lesub': LeObject(42),
175
+                    'nature': 'parent',
176
+                }
177
+            )
153 178
         ]
154
-        for query in queries:
179
+        for query, equery in queries:
155 180
             LeHierarch.insert(query)
156
-            dsmock.assert_called_once_with(LeHierarch, **query)
181
+            dsmock.assert_called_once_with(LeHierarch, **equery)
157 182
             dsmock.reset_mock()
158 183
 
159 184
             LeRelation.insert(query, 'LeHierarch')
160
-            dsmock.assert_called_once_with(LeHierarch, **query)
185
+            dsmock.assert_called_once_with(LeHierarch, **equery)
161 186
             dsmock.reset_mock()
162 187
     
163 188
 
@@ -223,6 +248,9 @@ class LeRel2TypeTestCase(LeRelationTestCase):
223 248
 
224 249
             eres = {'nature': None}
225 250
             eres.uopdate(query)
251
+            for fname in ('lesup', 'lesub'):
252
+                if isinstance(eres[fname], int):
253
+                    eres[fname] = LeObject(eres[fname])
226 254
 
227 255
             dsmock.assert_called_once_with(Rel_textes2personne, **eres)
228 256
             dsmock.reset_mock()

+ 0
- 1
leapi/test/test_letype.py Voir le fichier

@@ -21,7 +21,6 @@ class LeTypeTestCase(TestCase):
21 21
         """ Remove the temporary directory created at class setup """
22 22
         leapi.test.utils.cleanup(cls.tmpdir)
23 23
 
24
-    @unittest.skip("Waiting for EmFieldType full implementation")
25 24
     def test_init(self):
26 25
         """ testing the constructor """
27 26
         from dyncode import Publication, Numero, LeObject, LeType

Loading…
Annuler
Enregistrer