Skip to content

Commit 028386d

Browse files
committed
fix import
1 parent 57b191e commit 028386d

File tree

1 file changed

+51
-22
lines changed

1 file changed

+51
-22
lines changed

tests/test_client.py

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
load_dryrun_entities,
2323
parse_target,
2424
)
25-
from netboxlabs.diode.sdk.diode.v1.ingester_pb2 import Entity as EntityPb
25+
from netboxlabs.diode.sdk.diode.v1 import ingester_pb2
2626
from netboxlabs.diode.sdk.exceptions import DiodeClientError, DiodeConfigError
2727
from netboxlabs.diode.sdk.ingester import Entity
2828
from netboxlabs.diode.sdk.version import version_semver
@@ -64,7 +64,9 @@ def test_config_errors(client_id, client_secret, env_var_name):
6464
client_id=client_id,
6565
client_secret=client_secret,
6666
)
67-
assert str(err.value) == f"parameter or {env_var_name} environment variable required"
67+
assert (
68+
str(err.value) == f"parameter or {env_var_name} environment variable required"
69+
)
6870

6971

7072
def test_client_error(mock_diode_authentication):
@@ -90,7 +92,10 @@ def test_diode_client_error_repr_returns_correct_string():
9092
error = DiodeClientError(grpc_error)
9193
error._status_code = grpc.StatusCode.UNAVAILABLE
9294
error._details = "Some details about the error"
93-
assert repr(error) == "<DiodeClientError status code: StatusCode.UNAVAILABLE, details: Some details about the error>"
95+
assert (
96+
repr(error)
97+
== "<DiodeClientError status code: StatusCode.UNAVAILABLE, details: Some details about the error>"
98+
)
9499

95100

96101
def test_load_certs_returns_bytes():
@@ -180,7 +185,9 @@ def test_setup_sentry_initializes_with_correct_parameters(mock_diode_authenticat
180185
)
181186

182187

183-
def test_client_sets_up_secure_channel_when_grpcs_scheme_is_found_in_target(mock_diode_authentication):
188+
def test_client_sets_up_secure_channel_when_grpcs_scheme_is_found_in_target(
189+
mock_diode_authentication,
190+
):
184191
"""Check that DiodeClient.__init__() sets up the gRPC secure channel when grpcs:// scheme is found in the target."""
185192
client = DiodeClient(
186193
target="grpcs://localhost:8081",
@@ -205,7 +212,9 @@ def test_client_sets_up_secure_channel_when_grpcs_scheme_is_found_in_target(mock
205212
mock_secure_channel.assert_called_once()
206213

207214

208-
def test_client_sets_up_insecure_channel_when_grpc_scheme_is_found_in_target(mock_diode_authentication):
215+
def test_client_sets_up_insecure_channel_when_grpc_scheme_is_found_in_target(
216+
mock_diode_authentication,
217+
):
209218
"""Check that DiodeClient.__init__() sets up the gRPC insecure channel when grpc:// scheme is found in the target."""
210219
client = DiodeClient(
211220
target="grpc://localhost:8081",
@@ -347,10 +356,14 @@ def test_client_setup_sentry_called_when_sentry_dsn_exists(mock_diode_authentica
347356
client_secret="123456",
348357
sentry_dsn="https://user@password.mock.dsn/123456",
349358
)
350-
mock_setup_sentry.assert_called_once_with("https://user@password.mock.dsn/123456", 1.0, 1.0)
359+
mock_setup_sentry.assert_called_once_with(
360+
"https://user@password.mock.dsn/123456", 1.0, 1.0
361+
)
351362

352363

353-
def test_client_setup_sentry_not_called_when_sentry_dsn_not_exists(mock_diode_authentication):
364+
def test_client_setup_sentry_not_called_when_sentry_dsn_not_exists(
365+
mock_diode_authentication,
366+
):
354367
"""Check that DiodeClient._setup_sentry() is not called when sentry_dsn does not exist."""
355368
client = DiodeClient(
356369
target="grpc://localhost:8081",
@@ -471,7 +484,10 @@ def continuation(x, _):
471484
None,
472485
)
473486
request = None
474-
assert interceptor.intercept_unary_unary(continuation, client_call_details, request) == "/my/path/diode.v1.IngesterService/Ingest"
487+
assert (
488+
interceptor.intercept_unary_unary(continuation, client_call_details, request)
489+
== "/my/path/diode.v1.IngesterService/Ingest"
490+
)
475491

476492

477493
def test_interceptor_intercepts_stream_unary_calls():
@@ -491,7 +507,9 @@ def continuation(x, _):
491507
)
492508
request_iterator = None
493509
assert (
494-
interceptor.intercept_stream_unary(continuation, client_call_details, request_iterator)
510+
interceptor.intercept_stream_unary(
511+
continuation, client_call_details, request_iterator
512+
)
495513
== "/my/path/diode.v1.IngesterService/Ingest"
496514
)
497515

@@ -569,7 +587,9 @@ def test_diode_authentication_success(mock_diode_authentication):
569587
with mock.patch("http.client.HTTPConnection") as mock_http_conn:
570588
mock_conn_instance = mock_http_conn.return_value
571589
mock_conn_instance.getresponse.return_value.status = 200
572-
mock_conn_instance.getresponse.return_value.read.return_value = json.dumps({"access_token": "mocked_token"}).encode()
590+
mock_conn_instance.getresponse.return_value.read.return_value = json.dumps(
591+
{"access_token": "mocked_token"}
592+
).encode()
573593

574594
token = auth.authenticate()
575595
assert token == "mocked_token"
@@ -595,14 +615,17 @@ def test_diode_authentication_failure(mock_diode_authentication):
595615
assert "Failed to obtain access token" in str(excinfo.value)
596616

597617

598-
@pytest.mark.parametrize("path", [
599-
"/diode",
600-
"",
601-
None,
602-
"/diode/",
603-
"diode",
604-
"diode/",
605-
])
618+
@pytest.mark.parametrize(
619+
"path",
620+
[
621+
"/diode",
622+
"",
623+
None,
624+
"/diode/",
625+
"diode",
626+
"diode/",
627+
],
628+
)
606629
def test_diode_authentication_url_with_path(mock_diode_authentication, path):
607630
"""Test that the authentication URL is correctly formatted with a path."""
608631
auth = _DiodeAuthentication(
@@ -616,9 +639,13 @@ def test_diode_authentication_url_with_path(mock_diode_authentication, path):
616639
with mock.patch("http.client.HTTPConnection") as mock_http_conn:
617640
mock_conn_instance = mock_http_conn.return_value
618641
mock_conn_instance.getresponse.return_value.status = 200
619-
mock_conn_instance.getresponse.return_value.read.return_value = json.dumps({"access_token": "mocked_token"}).encode()
642+
mock_conn_instance.getresponse.return_value.read.return_value = json.dumps(
643+
{"access_token": "mocked_token"}
644+
).encode()
620645
auth.authenticate()
621-
mock_conn_instance.request.assert_called_once_with("POST", f"{(path or '').rstrip('/')}/auth/token", mock.ANY, mock.ANY)
646+
mock_conn_instance.request.assert_called_once_with(
647+
"POST", f"{(path or '').rstrip('/')}/auth/token", mock.ANY, mock.ANY
648+
)
622649

623650

624651
def test_diode_authentication_request_exception(mock_diode_authentication):
@@ -639,6 +666,7 @@ def test_diode_authentication_request_exception(mock_diode_authentication):
639666
auth.authenticate()
640667
assert "Failed to obtain access token: Connection error" in str(excinfo.value)
641668

669+
642670
def test_ingest_dry_run_stdout(capsys):
643671
"""Verify ingest prints JSON when dry run is enabled."""
644672
client = DiodeDryRunClient()
@@ -664,6 +692,7 @@ def test_ingest_dry_run_file(tmp_path):
664692
assert client._stub.Ingest.call_count == 0
665693
assert output_file.read_text().startswith("{")
666694

695+
667696
def test_load_dryrun_entities(tmp_path):
668697
"""Verify ``load_dryrun_entities`` yields protobuf entities."""
669698
output_file = tmp_path / "dryrun.jsonl"
@@ -674,7 +703,7 @@ def test_load_dryrun_entities(tmp_path):
674703
entities = list(load_dryrun_entities(output_file))
675704

676705
assert len(entities) == 2
677-
assert isinstance(entities[0], EntityPb)
706+
assert isinstance(entities[0], ingester_pb2.Entity)
678707
assert entities[0].site.name == "Site1"
679-
assert isinstance(entities[1], EntityPb)
708+
assert isinstance(entities[1], ingester_pb2.Entity)
680709
assert entities[1].device.name == "Device1"

0 commit comments

Comments
 (0)