Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add back elif policy
  • Loading branch information
swathipil committed Feb 22, 2024
commit 146d436330c1dfc6cbe72d542fd91b7fcf556260
4 changes: 4 additions & 0 deletions sdk/core/corehttp/corehttp/runtime/pipeline/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ def __init__(
self._impl_policies.append(policy)
elif is_sansio_http_policy(policy):
self._impl_policies.append(_SansIOHTTPPolicyRunner(policy))
elif policy:
raise AttributeError(
f"'{type(policy)}' object has no attribute 'send' or 'on_request' and 'on_response'."
)
for index in range(len(self._impl_policies) - 1):
self._impl_policies[index].next = self._impl_policies[index + 1]
if self._impl_policies:
Expand Down
4 changes: 4 additions & 0 deletions sdk/core/corehttp/corehttp/runtime/pipeline/_base_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ def __init__(
self._impl_policies.append(policy)
elif is_sansio_http_policy(policy):
self._impl_policies.append(_SansIOAsyncHTTPPolicyRunner(policy))
elif policy:
raise AttributeError(
f"'{type(policy)}' object has no attribute 'send' or 'on_request' and 'on_response'."
)
for index in range(len(self._impl_policies) - 1):
self._impl_policies[index].next = self._impl_policies[index + 1]
if self._impl_policies:
Expand Down
8 changes: 8 additions & 0 deletions sdk/core/corehttp/tests/async_tests/test_pipeline_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ async def __aexit__(self, exc_type, exc_value, traceback):
await pipeline.run(req)


def test_invalid_policy_error():
class FooPolicy:
pass

with pytest.raises(AttributeError):
pipeline = Pipeline(transport=Mock(), policies=[FooPolicy()])


@pytest.mark.asyncio
@pytest.mark.parametrize("transport", ASYNC_TRANSPORTS)
async def test_transport_socket_timeout(transport):
Expand Down
9 changes: 9 additions & 0 deletions sdk/core/corehttp/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# license information.
# -------------------------------------------------------------------------

from unittest.mock import Mock
import json
from io import BytesIO
import xml.etree.ElementTree as ET
Expand Down Expand Up @@ -52,6 +53,14 @@ def __exit__(self, exc_type, exc_value, traceback):
pipeline.run(req)


def test_invalid_policy_error():
class FooPolicy:
pass

with pytest.raises(AttributeError):
pipeline = Pipeline(transport=Mock(), policies=[FooPolicy()])


@pytest.mark.parametrize("transport", SYNC_TRANSPORTS)
def test_transport_socket_timeout(transport):
request = HttpRequest("GET", "https://bing.com")
Expand Down