Browse Source

Unskip, delete and fix some tests

Yann Weber 9 years ago
parent
commit
4d9ced1807

+ 34
- 6
DataSource/MySQL/test/test_datasource.py View File

56
             DataSource(conn_args = conn_args)
56
             DataSource(conn_args = conn_args)
57
             mock_db.assert_called_once_with(pymysql, **conn_args)
57
             mock_db.assert_called_once_with(pymysql, **conn_args)
58
     
58
     
59
-    @unittest.skip("Broken because of multivalue fields")
60
     def test_insert_leobject(self):
59
     def test_insert_leobject(self):
61
         """ Test the insert method on LeObjects """
60
         """ Test the insert method on LeObjects """
62
         from dyncode import Article, Personne, Rubrique
61
         from dyncode import Article, Personne, Rubrique
82
 
81
 
83
             sql_query = 'SELECT wow FROM splendid_table'
82
             sql_query = 'SELECT wow FROM splendid_table'
84
 
83
 
85
-            class_table_datas = { fname: random.randint(42,1337) for fname in letype.fieldlist(complete = False) }
86
-            for fname in class_table_datas:
84
+            class_table_datas = {
85
+                fname: random.randint(42,1337)
86
+                for fname in letype.fieldlist(complete = False)
87
+                if not isinstance(letype.fieldtypes()[fname], MultiValueFieldType)
88
+            }
89
+            i18n = dict()
90
+            for fname in letype.fieldlist():
87
                 if isinstance(letype.fieldtypes()[fname], MultiValueFieldType):
91
                 if isinstance(letype.fieldtypes()[fname], MultiValueFieldType):
88
-                    class_table_datas[fname] = {'fre': 'bonjour', 'eng': 'hello'}
89
-            #class_table_datas = { 'title': 'foo', 'number': 42 }
92
+                    i18n[fname] = {'fre': 'bonjour', 'eng': 'hello'}
93
+                    class_table_datas[fname] = i18n[fname]
90
             object_table_datas = { 'string': random.randint(-42,42) }
94
             object_table_datas = { 'string': random.randint(-42,42) }
91
             
95
             
92
             # build the insert datas argument
96
             # build the insert datas argument
103
                     object_table_datas['type_id'] = letype._type_id
107
                     object_table_datas['type_id'] = letype._type_id
104
                     # construct expected datas used in class table insert
108
                     # construct expected datas used in class table insert
105
                     class_table_datas['lodel_id'] = lodel_id
109
                     class_table_datas['lodel_id'] = lodel_id
110
+                    for fname in i18n:
111
+                        del(class_table_datas[fname])
106
 
112
 
107
                     expected_calls = [
113
                     expected_calls = [
108
                         # insert in object table call
114
                         # insert in object table call
116
                             class_table_datas
122
                             class_table_datas
117
                         ),
123
                         ),
118
                     ]
124
                     ]
119
-
125
+                    i18n_calls = dict()
126
+                    for fname, fval in i18n.items():
127
+                        keyname = letype.fieldtypes()[fname].keyname
128
+                        if not keyname in i18n_calls:
129
+                            i18n_calls[keyname] = dict()
130
+                        for lang, val in fval.items():
131
+                            if not lang in i18n_calls[keyname]:
132
+                                i18n_calls[keyname][lang] = dict()
133
+                            i18n_calls[keyname][lang][fname] = val
134
+                    real_i18n_calls = []
135
+                    for keyname, kval in i18n_calls.items():
136
+                        table_name = db_utils.multivalue_table_name(
137
+                            db_utils.object_table_name(letype._leclass.__name__),
138
+                            keyname
139
+                        )
140
+                        for lang, value in kval.items():
141
+                            value[keyname] = lang
142
+                            value[letype.uidname()] = lodel_id
143
+                            expected_calls.append(call(
144
+                                    table_name,
145
+                                    value
146
+                                )
147
+                            )
120
                     expected_utils_query_calls = [
148
                     expected_utils_query_calls = [
121
                         call(datasource.connection, sql_query),
149
                         call(datasource.connection, sql_query),
122
                         call(datasource.connection, sql_query),
150
                         call(datasource.connection, sql_query),

+ 5
- 0
leapi/lerelation.py View File

177
     def object_from_data(cls, datas):
177
     def object_from_data(cls, datas):
178
         return cls.name2class('LeHierarch')(**datas)
178
         return cls.name2class('LeHierarch')(**datas)
179
 
179
 
180
+    ## @warning Abastract method
181
+    def update(self):
182
+        raise NotImplementedError("Abstract method")
183
+        
184
+
180
 ## @brief Abstract class to handle rel2type relations
185
 ## @brief Abstract class to handle rel2type relations
181
 class _LeRel2Type(_LeRelation):
186
 class _LeRel2Type(_LeRelation):
182
     ## @brief Stores the list of fieldtypes handling relations attributes
187
     ## @brief Stores the list of fieldtypes handling relations attributes

+ 0
- 50
leapi/test/test_leobject.py View File

46
         with self.assertRaises(KeyError):
46
         with self.assertRaises(KeyError):
47
             dyncode.LeObject.uid2leobj(i)
47
             dyncode.LeObject.uid2leobj(i)
48
     
48
     
49
-    @unittest.skip("Obsolete but may be usefull for datasources tests")
50
-    def test_prepare_targets(self):
51
-        """ Testing _prepare_targets() method """
52
-        from dyncode import Publication, Numero, LeObject
53
-
54
-        test_v = {
55
-            (None, None) : (None, None),
56
-
57
-            (Publication, Numero): (Publication, Numero),
58
-            (Publication, None): (Publication, None),
59
-            (None, Numero): (Publication, Numero),
60
-
61
-            (Publication,'Numero'): (Publication, Numero),
62
-            ('Publication', Numero): (Publication, Numero),
63
-
64
-            ('Publication', 'Numero'): (Publication, Numero),
65
-            ('Publication', None): (Publication, None),
66
-            (None, 'Numero'): (Publication, Numero),
67
-        }
68
-
69
-        for (leclass, letype), (rleclass, rletype) in test_v.items():
70
-            self.assertEqual((rletype,rleclass), LeObject._prepare_targets(letype, leclass))
71
-
72
-    @unittest.skip("Obsolete but may be usefull for datasources tests")
73
-    def test_invalid_prepare_targets(self):
74
-        """ Testing _prepare_targets() method with invalid arguments """
75
-        from dyncode import Publication, Numero, LeObject, Personnes
76
-        
77
-        test_v = [
78
-            ('',''),
79
-            (Personnes, Numero),
80
-            (leapi.leclass.LeClass, Numero),
81
-            (Publication, leapi.letype.LeType),
82
-            ('foobar', Numero),
83
-            (Publication, 'foobar'),
84
-            (Numero, Numero),
85
-            (Publication, Publication),
86
-            (None, Publication),
87
-            ('foobar', 'foobar'),
88
-            (42,1337),
89
-            (type, Numero),
90
-            (LeObject, Numero),
91
-            (LeObject, LeObject),
92
-            (Publication, LeObject),
93
-        ]
94
-
95
-        for (leclass, letype) in test_v:
96
-            with self.assertRaises(ValueError):
97
-                LeObject._prepare_targets(letype, leclass)
98
-
99
 class LeObjectMockDatasourceTestCase(TestCase):
49
 class LeObjectMockDatasourceTestCase(TestCase):
100
     """ Testing _LeObject using a mock on the datasource """
50
     """ Testing _LeObject using a mock on the datasource """
101
 
51
 

+ 0
- 1
leapi/test/test_lerelation.py View File

203
         dsmock.assert_called_once_with(LeHierarch, 10)
203
         dsmock.assert_called_once_with(LeHierarch, 10)
204
         
204
         
205
     
205
     
206
-    @unittest.skip("Wait for LeRelation.update() to unskip")
207
     @patch('DataSource.dummy.leapidatasource.DummyDatasource.update')
206
     @patch('DataSource.dummy.leapidatasource.DummyDatasource.update')
208
     def test_update(self, dsmock):
207
     def test_update(self, dsmock):
209
         """ test LeHierach update method"""
208
         """ test LeHierach update method"""

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

10
 import leapi
10
 import leapi
11
 import DataSource.dummy
11
 import DataSource.dummy
12
 import leapi.test.utils
12
 import leapi.test.utils
13
+from leapi.lecrud import _LeCrud
13
 
14
 
14
 class LeTypeTestCase(TestCase):
15
 class LeTypeTestCase(TestCase):
15
     
16
     
112
             dsmock.assert_called_once_with(Numero, missing_fields, [('lodel_id','=',1)],[])
113
             dsmock.assert_called_once_with(Numero, missing_fields, [('lodel_id','=',1)],[])
113
 
114
 
114
     @patch('DataSource.dummy.leapidatasource.DummyDatasource.update')
115
     @patch('DataSource.dummy.leapidatasource.DummyDatasource.update')
115
-    @unittest.skip('must verify that populate is called')
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
         
120
         
120
         
121
         #Testing as instance method
121
         #Testing as instance method
122
         num = Numero(lodel_id = 1)
122
         num = Numero(lodel_id = 1)
123
-        num.update(datas)
124
-        dsmock.assert_called_once_with(Numero, [('lodel_id','=',1)], [], **datas)
123
+        with patch.object(_LeCrud, 'populate', return_value=None) as mock_populate:
124
+            num.update(datas)
125
+            mock_populate.assert_called_once_with()
126
+            dsmock.assert_called_once_with(Numero, num.uidget(), **datas)
125
     
127
     
126
     @patch('DataSource.dummy.leapidatasource.DummyDatasource.delete')
128
     @patch('DataSource.dummy.leapidatasource.DummyDatasource.delete')
127
     def test_delete(self, dsmock):
129
     def test_delete(self, dsmock):

Loading…
Cancel
Save