def test_make_configuration(self, project_id, cluster_id): cluster = CtxCluster.create(cluster_id, project_id, token='token') config_service = BcsKubeConfigurationService(cluster) faked_credentials = { 'server_address_path': '/example-foo-cluster', 'user_token': 'faked-foo-token' } with StubBcsApiClient.get_cluster_credentials.mock( return_value=faked_credentials): config = config_service.make_configuration() assert config.host == 'https://my-stag-bcs-server.example.com/example-foo-cluster' assert config.api_key[ 'authorization'] == f'Bearer {faked_credentials["user_token"]}'
def make_cluster_configuration(access_token: str, project_id: str, cluster_id: str) -> Dict: ctx_cluster = CtxCluster.create( id=cluster_id, project_id=project_id, token=access_token, ) return BcsKubeConfigurationService(ctx_cluster).make_configuration()
def test_make_configuration(self, project_id, cluster_id): config_service = BcsKubeConfigurationService('token', project_id, cluster_id) with mock.patch( 'backend.resources.client.http_get') as http_get_mocker: http_get_mocker.side_effect = [ { 'id': '10000' }, # Query BKE Server ID { 'server_address_path': '/foo', 'user_token': 'foo-token' }, # Query credentials ] config = config_service.make_configuration() assert http_get_mocker.call_count == 2 assert ( http_get_mocker.call_args[0][0] == 'https://bcs-api.example.com/my_stag/rest/clusters/10000/client_credentials' ) assert config.host == 'https://my-stag-bcs-server.example.com/foo' assert config.api_key['authorization'] == 'Bearer foo-token'