Skip to content

Commit 79411bb

Browse files
committed
fix(api-core): mock json_format.MessageToDict in test_operations_client.py for protobuf version branches
1 parent b3218b7 commit 79411bb

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

packages/google-api-core/tests/unit/operations_v1/test_operations_client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,23 @@ def test_operations_v1_transport_base_to_dict_protobuf_versions(monkeypatch):
113113
credentials=ga_credentials.AnonymousCredentials()
114114
)
115115

116+
calls = []
117+
118+
def mock_message_to_dict(*args, **kwargs):
119+
calls.append(kwargs)
120+
return {"name": "test_op"}
121+
122+
monkeypatch.setattr(base.json_format, "MessageToDict", mock_message_to_dict)
123+
116124
monkeypatch.setattr(base, "PROTOBUF_VERSION", "3.20.0")
117125
res3 = transport._convert_protobuf_message_to_dict(message)
118126
assert res3.get("name") == "test_op"
127+
assert "including_default_value_fields" in calls[-1]
119128

120129
monkeypatch.setattr(base, "PROTOBUF_VERSION", "5.26.0")
121130
res5 = transport._convert_protobuf_message_to_dict(message)
122131
assert res5.get("name") == "test_op"
132+
assert "always_print_fields_with_no_presence" in calls[-1]
123133

124134

125135
def test_operations_v1_init_import_error_fallback(monkeypatch):

0 commit comments

Comments
 (0)