diff --git a/dapr/clients/http/client.py b/dapr/clients/http/client.py index d0f178b2..3a3d8704 100644 --- a/dapr/clients/http/client.py +++ b/dapr/clients/http/client.py @@ -54,7 +54,7 @@ def get_api_url(self) -> str: return '{}/{}'.format(settings.DAPR_HTTP_ENDPOINT, settings.DAPR_API_VERSION) return 'http://{}:{}/{}'.format(settings.DAPR_RUNTIME_HOST, - settings.DAPR_HTTP_PORT, settings.DAPR_API_VERSION) + settings.DAPR_HTTP_PORT, settings.DAPR_API_VERSION) async def send_bytes( self, method: str, url: str, diff --git a/tests/clients/test_http_service_invocation_client.py b/tests/clients/test_http_service_invocation_client.py index 587c4d8d..8c53601c 100644 --- a/tests/clients/test_http_service_invocation_client.py +++ b/tests/clients/test_http_service_invocation_client.py @@ -51,9 +51,10 @@ def test_get_api_url_default(self): settings.DAPR_API_VERSION), client.invocation_client._client.get_api_url()) - def test_get_api_url_endpoint_as_argument(self): + @patch.object(settings, "DAPR_HTTP_ENDPOINT", "https://domain1.com:5000") + def test_dont_get_api_url_endpoint_as_argument(self): client = DaprClient("http://localhost:5000") - self.assertEqual('http://localhost:5000/{}'.format(settings.DAPR_API_VERSION), + self.assertEqual('https://domain1.com:5000/{}'.format(settings.DAPR_API_VERSION), client.invocation_client._client.get_api_url()) @patch.object(settings, "DAPR_HTTP_ENDPOINT", "https://domain1.com:5000") diff --git a/tests/clients/test_secure_http_service_invocation_client.py b/tests/clients/test_secure_http_service_invocation_client.py index 704eb0b8..44913294 100644 --- a/tests/clients/test_secure_http_service_invocation_client.py +++ b/tests/clients/test_secure_http_service_invocation_client.py @@ -13,18 +13,13 @@ limitations under the License. """ import ssl +from unittest.mock import patch from dapr.clients.http.client import DaprHttpClient from .certs import CERTIFICATE_CHAIN_PATH from .fake_http_server import FakeHttpServer from dapr.conf import settings from dapr.clients import DaprClient -from dapr.proto import common_v1 -from asyncio import TimeoutError - - -from opencensus.trace.tracer import Tracer # type: ignore -from opencensus.trace import print_exporter, samplers from .test_http_service_invocation_client import DaprInvocationHttpClientTests @@ -45,7 +40,8 @@ def setUp(self): self.server.start() settings.DAPR_HTTP_PORT = self.server_port settings.DAPR_API_METHOD_INVOCATION_PROTOCOL = 'http' - self.client = DaprClient("https://localhost:{}".format(self.server_port)) + settings.DAPR_HTTP_ENDPOINT = "https://localhost:{}".format(self.server_port) + self.client = DaprClient() self.app_id = 'fakeapp' self.method_name = 'fakemethod' self.invoke_url = f'/v1.0/invoke/{self.app_id}/method/{self.method_name}' @@ -55,37 +51,10 @@ def tearDown(self): settings.DAPR_API_TOKEN = None settings.DAPR_API_METHOD_INVOCATION_PROTOCOL = 'http' - def test_global_timeout_setting_is_honored(self): - previous_timeout = settings.DAPR_HTTP_TIMEOUT_SECONDS - settings.DAPR_HTTP_TIMEOUT_SECONDS = 1 - new_client = DaprClient("https://localhost:{}".format(self.server_port)) - self.server.set_server_delay(1.5) - with self.assertRaises(TimeoutError): - new_client.invoke_method(self.app_id, self.method_name, "") - - settings.DAPR_HTTP_TIMEOUT_SECONDS = previous_timeout - - def test_invoke_method_with_tracer(self): - tracer = Tracer(sampler=samplers.AlwaysOnSampler(), exporter=print_exporter.PrintExporter()) - - self.client = DaprClient("https://localhost:{}".format(self.server_port), - headers_callback=lambda: tracer.propagator.to_headers( - tracer.span_context)) - self.server.set_response(b"FOO") - - with tracer.span(name="test"): - req = common_v1.StateItem(key='test') - resp = self.client.invoke_method(self.app_id, self.method_name, http_verb='PUT', - data=req, ) - - request_headers = self.server.get_request_headers() - - self.assertIn('Traceparent', request_headers) - self.assertEqual(b'FOO', resp.data) - - def test_timeout_exception_thrown_when_timeout_reached(self): - new_client = DaprClient("https://localhost:{}".format(self.server_port), - http_timeout_seconds=1) - self.server.set_server_delay(1.5) - with self.assertRaises(TimeoutError): - new_client.invoke_method(self.app_id, self.method_name, "") + @patch.object(settings, "DAPR_HTTP_ENDPOINT", None) + def test_get_api_url_default(self): + client = DaprClient() + self.assertEqual( + 'http://{}:{}/{}'.format(settings.DAPR_RUNTIME_HOST, settings.DAPR_HTTP_PORT, + settings.DAPR_API_VERSION), + client.invocation_client._client.get_api_url())