| Conditions | 1 |
| Total Lines | 189 |
| Code Lines | 155 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | """Module to test the main napp file.""" |
||
| 274 | def test_load_circuits_by_interface(self): |
||
| 275 | """Test if existing circuits are correctly loaded to the cache.""" |
||
| 276 | stored_circuits = { |
||
| 277 | "182f5bac84074017a262a2321195dbb4": { |
||
| 278 | "active": False, |
||
| 279 | "archived": True, |
||
| 280 | "backup_links": [], |
||
| 281 | "backup_path": [], |
||
| 282 | "bandwidth": 0, |
||
| 283 | "circuit_scheduler": [ |
||
| 284 | { |
||
| 285 | "action": "create", |
||
| 286 | "frequency": "*/3 * * * *", |
||
| 287 | "id": "db7f8a301e2b4ff69a2ad9a6267430e2" |
||
| 288 | }, |
||
| 289 | { |
||
| 290 | "action": "remove", |
||
| 291 | "frequency": "2-59/3 * * * *", |
||
| 292 | "id": "b8a8bbe85bc144b0afc65181e4c069a1" |
||
| 293 | } |
||
| 294 | ], |
||
| 295 | "creation_time": "2019-08-09T19:25:06", |
||
| 296 | "current_path": [], |
||
| 297 | "dynamic_backup_path": True, |
||
| 298 | "enabled": False, |
||
| 299 | "end_date": "2018-12-29T15:16:50", |
||
| 300 | "id": "182f5bac84074017a262a2321195dbb4", |
||
| 301 | "name": "Teste2", |
||
| 302 | "owner": None, |
||
| 303 | "primary_links": [], |
||
| 304 | "primary_path": [], |
||
| 305 | "priority": 0, |
||
| 306 | "request_time": "2019-08-09T19:25:06", |
||
| 307 | "start_date": "2019-08-09T19:25:06", |
||
| 308 | "uni_a": { |
||
| 309 | "interface_id": "00:00:00:00:00:00:00:03:12", |
||
| 310 | "tag": { |
||
| 311 | "tag_type": 1, |
||
| 312 | "value": 321 |
||
| 313 | } |
||
| 314 | }, |
||
| 315 | "uni_z": { |
||
| 316 | "interface_id": "00:00:00:00:00:00:00:06:11", |
||
| 317 | "tag": { |
||
| 318 | "tag_type": 1, |
||
| 319 | "value": 612 |
||
| 320 | } |
||
| 321 | } |
||
| 322 | }, |
||
| 323 | "65c4582cc8f249c2a5947ef500c19e37": { |
||
| 324 | "active": False, |
||
| 325 | "archived": False, |
||
| 326 | "backup_links": [], |
||
| 327 | "backup_path": [], |
||
| 328 | "bandwidth": 0, |
||
| 329 | "circuit_scheduler": [ |
||
| 330 | { |
||
| 331 | "action": "create", |
||
| 332 | "frequency": "*/3 * * * *", |
||
| 333 | "id": "0939dedf66ce431f85beb53daf578d73" |
||
| 334 | }, |
||
| 335 | { |
||
| 336 | "action": "remove", |
||
| 337 | "frequency": "2-59/3 * * * *", |
||
| 338 | "id": "6cdcab31a11f44708e23776b4dad7893" |
||
| 339 | } |
||
| 340 | ], |
||
| 341 | "creation_time": "2019-07-22T16:01:24", |
||
| 342 | "current_path": [], |
||
| 343 | "dynamic_backup_path": True, |
||
| 344 | "enabled": False, |
||
| 345 | "end_date": "2018-12-29T15:16:50", |
||
| 346 | "id": "65c4582cc8f249c2a5947ef500c19e37", |
||
| 347 | "name": "Teste2", |
||
| 348 | "owner": None, |
||
| 349 | "primary_links": [], |
||
| 350 | "primary_path": [ |
||
| 351 | { |
||
| 352 | "active": False, |
||
| 353 | "enabled": True, |
||
| 354 | "endpoint_a": { |
||
| 355 | "active": False, |
||
| 356 | "enabled": True, |
||
| 357 | "id": "00:00:00:00:00:00:00:03:3", |
||
| 358 | "link": "0e2b5d7bc858b9f38db11b69", |
||
| 359 | "mac": "ae:6e:d3:96:83:5a", |
||
| 360 | "metadata": {}, |
||
| 361 | "name": "s3-eth3", |
||
| 362 | "nni": True, |
||
| 363 | "port_number": 3, |
||
| 364 | "speed": 1250000000.0, |
||
| 365 | "switch": "00:00:00:00:00:00:00:03", |
||
| 366 | "type": "interface", |
||
| 367 | "uni": False |
||
| 368 | }, |
||
| 369 | "endpoint_b": { |
||
| 370 | "active": False, |
||
| 371 | "enabled": True, |
||
| 372 | "id": "00:00:00:00:00:00:00:05:2", |
||
| 373 | "link": "0e2b5d7bc858b9f38db11b69", |
||
| 374 | "mac": "de:eb:d0:b0:14:cf", |
||
| 375 | "metadata": {}, |
||
| 376 | "name": "s5-eth2", |
||
| 377 | "nni": True, |
||
| 378 | "port_number": 2, |
||
| 379 | "speed": 1250000000.0, |
||
| 380 | "switch": "00:00:00:00:00:00:00:05", |
||
| 381 | "type": "interface", |
||
| 382 | "uni": False |
||
| 383 | }, |
||
| 384 | "id": "0e2b5d7bc858b9f38db11b69", |
||
| 385 | "metadata": {} |
||
| 386 | }, |
||
| 387 | { |
||
| 388 | "active": False, |
||
| 389 | "enabled": True, |
||
| 390 | "endpoint_a": { |
||
| 391 | "active": False, |
||
| 392 | "enabled": True, |
||
| 393 | "id": "00:00:00:00:00:00:00:05:4", |
||
| 394 | "link": "53bd36ff55a5aa2029bd5d50", |
||
| 395 | "mac": "6e:c2:ea:c4:18:12", |
||
| 396 | "metadata": {}, |
||
| 397 | "name": "s5-eth4", |
||
| 398 | "nni": True, |
||
| 399 | "port_number": 4, |
||
| 400 | "speed": 1250000000.0, |
||
| 401 | "switch": "00:00:00:00:00:00:00:05", |
||
| 402 | "type": "interface", |
||
| 403 | "uni": False |
||
| 404 | }, |
||
| 405 | "endpoint_b": { |
||
| 406 | "active": False, |
||
| 407 | "enabled": True, |
||
| 408 | "id": "00:00:00:00:00:00:00:06:2", |
||
| 409 | "link": "53bd36ff55a5aa2029bd5d50", |
||
| 410 | "mac": "5a:25:7b:7c:0d:ac", |
||
| 411 | "metadata": {}, |
||
| 412 | "name": "s6-eth2", |
||
| 413 | "nni": True, |
||
| 414 | "port_number": 2, |
||
| 415 | "speed": 1250000000.0, |
||
| 416 | "switch": "00:00:00:00:00:00:00:06", |
||
| 417 | "type": "interface", |
||
| 418 | "uni": False |
||
| 419 | }, |
||
| 420 | "id": "53bd36ff55a5aa2029bd5d50", |
||
| 421 | "metadata": {} |
||
| 422 | } |
||
| 423 | ], |
||
| 424 | "priority": 0, |
||
| 425 | "request_time": "2019-07-22T16:01:24", |
||
| 426 | "start_date": "2019-07-22T16:01:24", |
||
| 427 | "uni_a": { |
||
| 428 | "interface_id": "00:00:00:00:00:00:00:03:12", |
||
| 429 | "tag": { |
||
| 430 | "tag_type": 1, |
||
| 431 | "value": 321 |
||
| 432 | } |
||
| 433 | }, |
||
| 434 | "uni_z": { |
||
| 435 | "interface_id": "00:00:00:00:00:00:00:06:11", |
||
| 436 | "tag": { |
||
| 437 | "tag_type": 1, |
||
| 438 | "value": 612 |
||
| 439 | } |
||
| 440 | } |
||
| 441 | } |
||
| 442 | } |
||
| 443 | |||
| 444 | expected_result = { |
||
| 445 | '00:00:00:00:00:00:00:03:12': |
||
| 446 | {'182f5bac84074017a262a2321195dbb4', |
||
| 447 | '65c4582cc8f249c2a5947ef500c19e37'}, |
||
| 448 | '00:00:00:00:00:00:00:06:11': |
||
| 449 | {'182f5bac84074017a262a2321195dbb4', |
||
| 450 | '65c4582cc8f249c2a5947ef500c19e37'}, |
||
| 451 | '00:00:00:00:00:00:00:03:3': |
||
| 452 | {'65c4582cc8f249c2a5947ef500c19e37'}, |
||
| 453 | '00:00:00:00:00:00:00:05:2': |
||
| 454 | {'65c4582cc8f249c2a5947ef500c19e37'}, |
||
| 455 | '00:00:00:00:00:00:00:05:4': |
||
| 456 | {'65c4582cc8f249c2a5947ef500c19e37'}, |
||
| 457 | '00:00:00:00:00:00:00:06:2': |
||
| 458 | {'65c4582cc8f249c2a5947ef500c19e37'} |
||
| 459 | } |
||
| 460 | self.napp.load_circuits_by_interface(stored_circuits) |
||
| 461 | # pylint: disable=protected-access |
||
| 462 | self.assertEqual(self.napp._circuits_by_interface, expected_result) |
||
| 463 |