Code Duplication    Length = 64-64 lines in 2 locations

tests/test_models.py 1 location

@@ 228-291 (lines=64) @@
225
        self.assertEqual(evc2 == evc3, False)
226
        self.assertEqual(evc3 == evc4, True)
227
228
    def test_as_dict(self):
229
        """Test the method as_dict."""
230
        attributes = {
231
            "id": "custom_id",
232
            "name": "custom_name",
233
            "uni_a": get_uni_mocked(is_valid=True),
234
            "uni_z": get_uni_mocked(is_valid=True),
235
            "start_date": '2018-08-21T18:44:54',
236
            "end_date": '2018-08-21T18:44:55',
237
            'primary_links': [],
238
            'request_time': '2018-08-21T19:10:41',
239
            'creation_time': '2018-08-21T18:44:54',
240
            'owner': "my_name",
241
            'circuit_scheduler': [],
242
            'enabled': True,
243
            'priority': 2
244
        }
245
        evc = EVC(**attributes)
246
247
        expected_dict = {
248
            'id': 'custom_id',
249
            'name': 'custom_name',
250
            'uni_a': attributes['uni_a'].as_dict(),
251
            'uni_z': attributes['uni_z'].as_dict(),
252
            'start_date': '2018-08-21T18:44:54',
253
            'end_date': '2018-08-21T18:44:55',
254
            'bandwidth': 0,
255
            'primary_links': [],
256
            'backup_links': [],
257
            'current_path': [],
258
            'primary_path': [],
259
            'backup_path': [],
260
            'dynamic_backup_path': False,
261
            '_requested': {
262
                           "id": "custom_id",
263
                           "name": "custom_name",
264
                           "uni_a": attributes['uni_a'].as_dict(),
265
                           "uni_z": attributes['uni_z'].as_dict(),
266
                           "start_date": '2018-08-21T18:44:54',
267
                           "end_date": '2018-08-21T18:44:55',
268
                           'primary_links': [],
269
                           'request_time': '2018-08-21T19:10:41',
270
                           'creation_time': '2018-08-21T18:44:54',
271
                           'owner': "my_name",
272
                           'circuit_scheduler': [],
273
                           'enabled': True,
274
                           'priority': 2
275
            },
276
            'request_time': '2018-08-21T19:10:41',
277
            'creation_time': '2018-08-21T18:44:54',
278
            'owner': 'my_name',
279
            'circuit_scheduler': [],
280
            'active': False,
281
            'enabled': True,
282
            'priority': 2
283
        }
284
        actual_dict = evc.as_dict()
285
        for name, value in expected_dict.items():
286
            actual = actual_dict.get(name)
287
            if name == '_requested':
288
                for requested_name, requested_value in value.items():
289
                    if isinstance(requested_value, UNI):
290
                        value[requested_name] = requested_value.as_dict()
291
            self.assertEqual(value, actual)
292
293
    def test_primary_links_zipped(self):
294
        """Test primary links zipped method."""

tests/models/test_evc_base.py 1 location

@@ 150-213 (lines=64) @@
147
        self.assertEqual(evc2 == evc3, False)
148
        self.assertEqual(evc3 == evc4, True)
149
150
    def test_as_dict(self):
151
        """Test the method as_dict."""
152
        attributes = {
153
            "id": "custom_id",
154
            "name": "custom_name",
155
            "uni_a": get_uni_mocked(is_valid=True),
156
            "uni_z": get_uni_mocked(is_valid=True),
157
            "start_date": '2018-08-21T18:44:54',
158
            "end_date": '2018-08-21T18:44:55',
159
            'primary_links': [],
160
            'request_time': '2018-08-21T19:10:41',
161
            'creation_time': '2018-08-21T18:44:54',
162
            'owner': "my_name",
163
            'circuit_scheduler': [],
164
            'enabled': True,
165
            'priority': 2
166
        }
167
        evc = EVC(**attributes)
168
169
        expected_dict = {
170
            'id': 'custom_id',
171
            'name': 'custom_name',
172
            'uni_a': attributes['uni_a'].as_dict(),
173
            'uni_z': attributes['uni_z'].as_dict(),
174
            'start_date': '2018-08-21T18:44:54',
175
            'end_date': '2018-08-21T18:44:55',
176
            'bandwidth': 0,
177
            'primary_links': [],
178
            'backup_links': [],
179
            'current_path': [],
180
            'primary_path': [],
181
            'backup_path': [],
182
            'dynamic_backup_path': False,
183
            '_requested': {
184
                           "id": "custom_id",
185
                           "name": "custom_name",
186
                           "uni_a": attributes['uni_a'].as_dict(),
187
                           "uni_z": attributes['uni_z'].as_dict(),
188
                           "start_date": '2018-08-21T18:44:54',
189
                           "end_date": '2018-08-21T18:44:55',
190
                           'primary_links': [],
191
                           'request_time': '2018-08-21T19:10:41',
192
                           'creation_time': '2018-08-21T18:44:54',
193
                           'owner': "my_name",
194
                           'circuit_scheduler': [],
195
                           'enabled': True,
196
                           'priority': 2
197
            },
198
            'request_time': '2018-08-21T19:10:41',
199
            'creation_time': '2018-08-21T18:44:54',
200
            'owner': 'my_name',
201
            'circuit_scheduler': [],
202
            'active': False,
203
            'enabled': True,
204
            'priority': 2
205
        }
206
        actual_dict = evc.as_dict()
207
        for name, value in expected_dict.items():
208
            actual = actual_dict.get(name)
209
            if name == '_requested':
210
                for requested_name, requested_value in value.items():
211
                    if isinstance(requested_value, UNI):
212
                        value[requested_name] = requested_value.as_dict()
213
            self.assertEqual(value, actual)
214