|
6 | 6 | from ni.measurements.data.v1.data_store_service_pb2_grpc import ( |
7 | 7 | DataStoreServiceStub, |
8 | 8 | ) |
| 9 | +from ni.protobuf.types import array_pb2, vector_pb2 |
9 | 10 | from pytest_mock import MockerFixture |
10 | 11 |
|
11 | 12 | from ni.measurements.data.v1.client import DataStoreClient |
@@ -248,6 +249,44 @@ def test__get_measurement__request_and_response_pass_through( |
248 | 249 | assert stub_response == client_response |
249 | 250 |
|
250 | 251 |
|
| 252 | +def test__read_condition_value__request_and_response_pass_through( |
| 253 | + data_store_client: DataStoreClient, data_store_stub: Mock |
| 254 | +) -> None: |
| 255 | + client_request = data_store_service_types.ReadConditionValueRequest() |
| 256 | + client_request.condition_id = "6118CBCE-74A1-4DE8-9B3A-98DE34A3B837" |
| 257 | + stub_response = data_store_service_types.ReadConditionValueResponse() |
| 258 | + stub_response.vector.MergeFrom( |
| 259 | + vector_pb2.Vector(double_array=array_pb2.DoubleArray(values=[1.0, 2.0, 3.0])) |
| 260 | + ) |
| 261 | + data_store_stub.ReadConditionValue.return_value = stub_response |
| 262 | + |
| 263 | + client_response = data_store_client.read_condition_value(client_request) |
| 264 | + |
| 265 | + data_store_stub.ReadConditionValue.assert_called_once() |
| 266 | + stub_request = data_store_stub.ReadConditionValue.call_args[0][0] |
| 267 | + assert stub_request == client_request |
| 268 | + assert stub_response == client_response |
| 269 | + |
| 270 | + |
| 271 | +def test__read_measurement_value__request_and_response_pass_through( |
| 272 | + data_store_client: DataStoreClient, data_store_stub: Mock |
| 273 | +) -> None: |
| 274 | + client_request = data_store_service_types.ReadMeasurementValueRequest() |
| 275 | + client_request.measurement_id = "6118CBCE-74A1-4DE8-9B3A-98DE34A3B837" |
| 276 | + stub_response = data_store_service_types.ReadMeasurementValueResponse() |
| 277 | + stub_response.vector.MergeFrom( |
| 278 | + vector_pb2.Vector(double_array=array_pb2.DoubleArray(values=[1.0, 2.0, 3.0])) |
| 279 | + ) |
| 280 | + data_store_stub.ReadMeasurementValue.return_value = stub_response |
| 281 | + |
| 282 | + client_response = data_store_client.read_measurement_value(client_request) |
| 283 | + |
| 284 | + data_store_stub.ReadMeasurementValue.assert_called_once() |
| 285 | + stub_request = data_store_stub.ReadMeasurementValue.call_args[0][0] |
| 286 | + assert stub_request == client_request |
| 287 | + assert stub_response == client_response |
| 288 | + |
| 289 | + |
251 | 290 | @pytest.fixture |
252 | 291 | def data_store_client( |
253 | 292 | mocker: MockerFixture, |
@@ -280,4 +319,6 @@ def data_store_stub(mocker: MockerFixture) -> Mock: |
280 | 319 | stub.QueryMeasurements = mocker.create_autospec(grpc.UnaryUnaryMultiCallable) |
281 | 320 | stub.GetCondition = mocker.create_autospec(grpc.UnaryUnaryMultiCallable) |
282 | 321 | stub.GetMeasurement = mocker.create_autospec(grpc.UnaryUnaryMultiCallable) |
| 322 | + stub.ReadConditionValue = mocker.create_autospec(grpc.UnaryUnaryMultiCallable) |
| 323 | + stub.ReadMeasurementValue = mocker.create_autospec(grpc.UnaryUnaryMultiCallable) |
283 | 324 | return stub |
0 commit comments