def test_automatic_load_of_the_client_credentials(self):
        cisco_hello_api = CiscoHelloApi()
        assert cisco_hello_api.is_ready_for_use() is False

        assert cisco_hello_api.client_id is None
        assert cisco_hello_api.client_secret is None

        cisco_hello_api.get_client_credentials()

        assert cisco_hello_api.client_id is not None
        assert cisco_hello_api.client_secret is not None
    def test_automatic_load_of_the_client_credentials(self):
        cisco_hello_api = CiscoHelloApi()
        assert cisco_hello_api.is_ready_for_use() is False

        assert cisco_hello_api.client_id is None
        assert cisco_hello_api.client_secret is None

        cisco_hello_api.get_client_credentials()

        assert cisco_hello_api.client_id is not None
        assert cisco_hello_api.client_secret is not None
    def test_base_functionality(self):
        cisco_hello_api = CiscoHelloApi()
        assert cisco_hello_api.is_ready_for_use() is False

        assert cisco_hello_api.client_id is None
        assert cisco_hello_api.client_secret is None

        with pytest.raises(CredentialsNotFoundException):
            cisco_hello_api.create_temporary_access_token()

        cisco_hello_api.load_client_credentials()
        assert cisco_hello_api.client_id != "dummy_id", "Should contain valid test credentials"
        assert cisco_hello_api.client_id != "dummy_secret", "Should contain valid test credentials"

        with open(BaseCiscoApiConsoleSettings.CREDENTIALS_FILE) as f:
            jdata = json.loads(f.read())
        assert jdata == cisco_hello_api.get_client_credentials()

        # create a temporary access token
        cisco_hello_api.create_temporary_access_token()
        assert cisco_hello_api.current_access_token is not None
        assert cache.get(CiscoHelloApi.AUTH_TOKEN_CACHE_KEY,
                         None) is not None, "Cached value should be created"

        # test that the class is now ready to use
        assert cisco_hello_api.is_ready_for_use() is True

        # test automatic recreation of the http_auth_header if no cached temp token is available
        cisco_hello_api.http_auth_header = None
        cache.delete(CiscoHelloApi.AUTH_TOKEN_CACHE_KEY)
        assert cisco_hello_api.is_ready_for_use() is True
        assert cisco_hello_api.http_auth_header is not None

        # try to recreate it
        token_before = cisco_hello_api.current_access_token
        cisco_hello_api.create_temporary_access_token()
        assert cisco_hello_api.current_access_token == token_before

        # force the recreation of the token
        cisco_hello_api.current_access_token = {
            "token_type": "my dummy value",
            "access_token": "my dummy value"
        }  # manually overwrite it to see that something happens
        cisco_hello_api.create_temporary_access_token(force_new_token=True)
        assert cisco_hello_api.current_access_token != "my dummy value"

        # cleanup
        cisco_hello_api.drop_cached_token()
        assert cisco_hello_api.current_access_token is None
        assert cache.get(CiscoHelloApi.AUTH_TOKEN_CACHE_KEY,
                         None) is None, "Cached value should be removed"

        # try to drop it again (nothing should happen)
        cisco_hello_api.drop_cached_token()
    def test_base_functionality(self):
        cisco_hello_api = CiscoHelloApi()
        assert cisco_hello_api.is_ready_for_use() is False

        assert cisco_hello_api.client_id is None
        assert cisco_hello_api.client_secret is None

        with pytest.raises(CredentialsNotFoundException):
            cisco_hello_api.create_temporary_access_token()

        cisco_hello_api.load_client_credentials()
        assert cisco_hello_api.client_id != "dummy_id", "Should contain valid test credentials"
        assert cisco_hello_api.client_id != "dummy_secret", "Should contain valid test credentials"

        with open(BaseCiscoApiConsoleSettings.CREDENTIALS_FILE) as f:
            jdata = json.loads(f.read())
        assert jdata == cisco_hello_api.get_client_credentials()

        # create a temporary access token
        cisco_hello_api.create_temporary_access_token()
        assert cisco_hello_api.current_access_token is not None
        assert cache.get(CiscoHelloApi.AUTH_TOKEN_CACHE_KEY, None) is not None, "Cached value should be created"

        # test that the class is now ready to use
        assert cisco_hello_api.is_ready_for_use() is True

        # test automatic recreation of the http_auth_header if no cached temp token is available
        cisco_hello_api.http_auth_header = None
        cache.delete(CiscoHelloApi.AUTH_TOKEN_CACHE_KEY)
        assert cisco_hello_api.is_ready_for_use() is True
        assert cisco_hello_api.http_auth_header is not None

        # try to recreate it
        token_before = cisco_hello_api.current_access_token
        cisco_hello_api.create_temporary_access_token()
        assert cisco_hello_api.current_access_token == token_before

        # force the recreation of the token
        cisco_hello_api.current_access_token = {
            "token_type": "my dummy value",
            "access_token": "my dummy value"
        }  # manually overwrite it to see that something happens
        cisco_hello_api.create_temporary_access_token(force_new_token=True)
        assert cisco_hello_api.current_access_token != "my dummy value"

        # cleanup
        cisco_hello_api.drop_cached_token()
        assert cisco_hello_api.current_access_token is None
        assert cache.get(CiscoHelloApi.AUTH_TOKEN_CACHE_KEY, None) is None, "Cached value should be removed"

        # try to drop it again (nothing should happen)
        cisco_hello_api.drop_cached_token()