Skip to content

Commit

Permalink
Add unit tests for http error.
Browse files Browse the repository at this point in the history
  • Loading branch information
a-feld committed Aug 17, 2020
1 parent 5b3470c commit 7a03190
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/agent_unittests/test_agent_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
DiscardDataForRequest,
ForceAgentDisconnect,
ForceAgentRestart,
NetworkInterfaceException,
RetryDataForRequest,
)

Expand Down Expand Up @@ -88,6 +89,18 @@ def close_connection(self):
HttpClientRecorder.STATE -= 1


class HttpClientException(DeveloperModeClient):
def send_request(
self,
method="POST",
path="/agent_listener/invoke_raw_method",
params=None,
headers=None,
payload=None,
):
raise NetworkInterfaceException


@pytest.fixture(autouse=True)
def clear_sent_values():
yield
Expand Down Expand Up @@ -246,6 +259,14 @@ def test_status_code_exceptions(status_code, expected_exc, log_level, caplog):
assert "123LICENSEKEY" not in message


def test_protocol_http_error_causes_retry():
protocol = AgentProtocol(
finalize_application_settings(), client_cls=HttpClientException
)
with pytest.raises(RetryDataForRequest):
protocol.send("analytic_event_data")


def test_protocol_context_manager():
protocol = AgentProtocol(
finalize_application_settings(), client_cls=HttpClientRecorder
Expand Down

0 comments on commit 7a03190

Please sign in to comment.