Sunday 1 August 2021

TypeError: super() argument 1 must be type, not MagicMock - azure-devops python package

I am using the azure-devOps python module to access the azure APIs to retrieve some information. I have used the below code to set up the authentication required to make a connection.

def retrieve_projects_from_organization(self): 
   credentials = BasicAuthentication('', AZURE_PRIVATE_TOKEN)
   self.azure_connection = Connection(base_url=os.environ.get('AZURE_BASE_URL',''),creds=credentials)
   core_client = self.azure_connection.clients_v6_0.get_core_client()
   project_list = []
   projects_response = core_client.get_projects()
   while projects_response is not None:
     for project in projects_response:
        project_list.append(project)

While writing the unit test case , I am unable to mock the Connection class since it requires the object of type BasicAuthentication. Below is my unit test case:

def test_retrieve_projects_from_organization(mocker):
    credentials = mocker.patch('msrest.authentication. BasicAuthentication')).return_value
    connection = mocker.patch('azure.devops.connection.Connection').return_value
    core_client = mocker.patch('azure.devops.v6_0.core.CoreClient').return_value
    projects = mocker.patch('azure.devops.v6_0.core.TeamProjectReference').return_value
    connection._creds = type(credentials)
    connection.clients_v6_0.get_core_client.return_value = core_client
    core_client.get_projects.return_value = [projects]

    assert AzureDataFetcher().retrieve_projects_from_organization() == [projects]

I get the below error :

TypeError: super() argument 1 must be type, not MagicMock

Is there a different way to mock this class or a way to bypass the authentication to the API .



from TypeError: super() argument 1 must be type, not MagicMock - azure-devops python package

No comments:

Post a Comment