async def test_closes_after_internal_error(self, zeebe_adapter: ZeebeAdapterBase):
        error = grpc.aio.AioRpcError(grpc.StatusCode.INTERNAL, None, None)
        zeebe_adapter._close = AsyncMock()
        zeebe_adapter._max_connection_retries = 1
        with pytest.raises(ZeebeInternalError):
            await zeebe_adapter._common_zeebe_grpc_errors(error)

        zeebe_adapter._close.assert_called_once()
    async def test_closes_after_retries_exceeded(self, zeebe_adapter: ZeebeAdapterBase):
        error = grpc.aio.AioRpcError(grpc.StatusCode.UNAVAILABLE, None, None)

        zeebe_adapter._close = AsyncMock()
        zeebe_adapter._max_connection_retries = 1
        with pytest.raises(ZeebeGatewayUnavailableError):
            await zeebe_adapter._common_zeebe_grpc_errors(error)

        zeebe_adapter._close.assert_called_once()
Exemple #3
0
def test_credentials_connection_uri_gotten(zeebe_adapter):
    client_id = str(uuid4())
    client_secret = str(uuid4())
    cluster_id = str(uuid4())
    CamundaCloudCredentials.get_access_token = MagicMock(
        return_value=str(uuid4()))
    credentials = CamundaCloudCredentials(client_id, client_secret, cluster_id)
    zeebe_adapter = ZeebeAdapterBase(credentials=credentials)
    assert zeebe_adapter.connection_uri == f"{cluster_id}.zeebe.camunda.io:443"
Exemple #4
0
def test_with_camunda_cloud_credentials(zeebe_adapter):
    CamundaCloudCredentials.get_access_token = MagicMock(
        return_value=str(uuid4()))
    credentials = CamundaCloudCredentials(str(uuid4()), str(uuid4()),
                                          str(uuid4()))

    with patch("grpc.secure_channel") as grpc_secure_channel_mock:
        ZeebeAdapterBase(credentials=credentials)
        grpc_secure_channel_mock.assert_called()
Exemple #5
0
def test_credentials_no_connection_uri(zeebe_adapter):
    hostname = str(uuid4())
    port = randint(0, RANDOM_RANGE)
    url = f"https://{str(uuid4())}/oauth/token"
    client_id = str(uuid4())
    client_secret = str(uuid4())
    audience = str(uuid4())

    with patch("requests_oauthlib.OAuth2Session.post"):
        credentials = OAuthCredentials(url, client_id, client_secret, audience)
    zeebe_adapter = ZeebeAdapterBase(hostname=hostname,
                                     port=port,
                                     credentials=credentials)
    assert zeebe_adapter.connection_uri == f"{hostname}:{port}"
Exemple #6
0
 def test_returns_false_when_current_retries_over_max(
         self, zeebe_adapter: ZeebeAdapterBase):
     zeebe_adapter._max_connection_retries = 1
     zeebe_adapter._current_connection_retries = 1
     assert not zeebe_adapter._should_retry()
Exemple #7
0
 def test_returns_true_when_no_current_retries(
         self, zeebe_adapter: ZeebeAdapterBase):
     zeebe_adapter._max_connection_retries = 1
     assert zeebe_adapter._should_retry()
Exemple #8
0
def test_with_secure_connection(zeebe_adapter):
    with patch("grpc.secure_channel") as grpc_secure_channel_mock:
        ZeebeAdapterBase(secure_connection=True)
        grpc_secure_channel_mock.assert_called()
Exemple #9
0
def test_host_and_port(zeebe_adapter):
    hostname = str(uuid4())
    port = randint(0, 10000)
    zeebe_adapter = ZeebeAdapterBase(hostname=hostname, port=port)
    assert zeebe_adapter.connection_uri == f"{hostname}:{port}"
Exemple #10
0
def test_only_host(zeebe_adapter):
    hostname = str(uuid4())
    zeebe_adapter = ZeebeAdapterBase(hostname=hostname)
    assert zeebe_adapter.connection_uri == f"{hostname}:26500"
Exemple #11
0
def test_only_port(zeebe_adapter):
    port = randint(0, 10000)
    zeebe_adapter = ZeebeAdapterBase(port=port)
    assert zeebe_adapter.connection_uri == f"localhost:{port}"