I am trying to mock "ConfigFactory.parse_file" for unit testing purpose and getting the following error.
AttributeError: 'str' object has no attribute 'as_plain_ordered_dict'
I tried mocking the attribute as_plain_ordered_dict to resolve the issue, but still getting the same error.
class Testt2StatsExporter(unittest.TestCase):
@patch('t2.client.OverlayClient')
@patch('pyhocon.ConfigFactory.parse_file')
@patch('oci.auth.signers.instance_principals_security_token_signer.InstancePrincipalsSecurityTokenSigner')
def test_create_telemetry_client(self, mock_config_factory, mock_security_token_signer, mock_client):
test_config = Mock()
test_config.json.return_value = {'metricsConfig': 'test_config'}
path_to_local_config = Mock()
type(path_to_local_config).as_plain_ordered_dict = PropertyMock(return_value=test_config)
mock_security_token_signer.return_value = "test_token"
mock_config_factory.return_value = test_config
mock_client.return_value = True
self.assertEqual(True, _create_telemetry_client(path_to_local_config))
and here is the main code base that I am testing.
path_to_local_config = '/etc/dlp/t2_config.conf'
def _create_telemetry_client(path_to_local_config: str):
t2config = ConfigFactory.parse_file(path_to_local_config).as_plain_ordered_dict()
common_config = t2config['metricsConfig']
t2_client_config = {'metricsConfig': common_config}
auth_provider = InstancePrincipalsSecurityTokenSigner()
return client.OverlayClient(t2_client_config, authentication_provider=auth_provider)
What can I try next?