Skip to main content
Active ⭐️⭐️⭐️
Nov 30, 2023 12:27 PM UTC
Solved

Testing CogniteAuthError with monkeypatch_cognite_client

Hello, 

is it possible to test the  CogniteAuthError using monkeypatch context manager  ?

Regards ,

Hakim Arezki 

    Dilini Fernando
    Expert ⭐️⭐️⭐️⭐️
    Jan 3, 2024 8:01 AM UTC

    Hi @Hakim AREZKI,

    I hope the above helped you. As of now, I will close this thread. If you have any questions, please feel free to add a comment.

    Best regards,
    Dilini

    3 replies

    Pierre  Pernot
    Expert ⭐️⭐️⭐️⭐️
    Expert ⭐️⭐️⭐️⭐️
    Dec 8, 2023 9:06 AM UTC

    Hello Hakim,

     

    You can test for this error as follows. You will need to adapt the Pytest fixture to your needs.

     

    import pytest
    from cognite.client import CogniteClient
    from cognite.client.exceptions import CogniteAuthError
    from cognite.client.testing import monkeypatch_cognite_client


    @pytest.fixture
    def cognite_client():
    with monkeypatch_cognite_client() as client:
    client.assets.list.side_effect = CogniteAuthError
    yield client


    def test_auth_error(cognite_client: CogniteClient):
    with pytest.raises(CogniteAuthError):
    cognite_client.assets.list()

    Please let us know if you need more info.

     

    Pierre

    Dilini Fernando
    Expert ⭐️⭐️⭐️⭐️
    Expert ⭐️⭐️⭐️⭐️
    Dec 21, 2023 1:27 PM UTC

    Hi @Hakim AREZKI,

    Did the above help you? 

    Br,
    Dilini 

    Dilini Fernando
    Expert ⭐️⭐️⭐️⭐️
    Expert ⭐️⭐️⭐️⭐️
    Jan 3, 2024 8:01 AM UTC

    Hi @Hakim AREZKI,

    I hope the above helped you. As of now, I will close this thread. If you have any questions, please feel free to add a comment.

    Best regards,
    Dilini