From a3b7d8c857a0fdb2dd61e4eea1435f7a7455750f Mon Sep 17 00:00:00 2001 From: Sugetha Kalyanaraman Date: Thu, 4 May 2023 10:34:28 -0700 Subject: [PATCH] Test: Unittest lib restructuring (#614) --- tests/lib/mockMagic.py | 16 +++++++--------- tests/unit/conftest.py | 3 ++- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/lib/mockMagic.py b/tests/lib/mockMagic.py index 4e2e3fe02..a23b59278 100644 --- a/tests/lib/mockMagic.py +++ b/tests/lib/mockMagic.py @@ -1,11 +1,9 @@ from tests.data.device_tools_unit import validate_router_bgp, return_validate_config_for_device, validate_intf, validate_true -from unittest.mock import MagicMock -class MockCvpApi(MagicMock): - def validate_config_for_device(self, device_mac, config): - if config == validate_router_bgp['config']: - return return_validate_config_for_device['return_validate_ruter_bgp'] - if config == validate_intf['config']: - return return_validate_config_for_device['return_validate_intf'] - if config == validate_true['config']: - return return_validate_config_for_device['return_validate_true'] +def validate_config_for_device(device_mac, config): + if config == validate_router_bgp['config']: + return return_validate_config_for_device['return_validate_ruter_bgp'] + if config == validate_intf['config']: + return return_validate_config_for_device['return_validate_intf'] + if config == validate_true['config']: + return return_validate_config_for_device['return_validate_true'] diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index e66c05e52..da700d257 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -22,5 +22,6 @@ def mock_cvpClient(): """ # mocked cvpClient object mock_cvpClient = create_autospec(CvpClient) - mock_cvpClient.api = mockMagic.MockCvpApi(spec=CvpApi) + mock_cvpClient.api = create_autospec(spec=CvpApi) + mock_cvpClient.api.validate_config_for_device.side_effect = mockMagic.validate_config_for_device return mock_cvpClient