|
158 | 158 | }
|
159 | 159 |
|
160 | 160 | OPERATION_DONE_MODEL_JSON_1 = {
|
161 |
| - 'name': OPERATION_NAME_1, |
162 | 161 | 'done': True,
|
163 | 162 | 'response': CREATED_UPDATED_MODEL_JSON_1
|
164 | 163 | }
|
165 | 164 | OPERATION_MALFORMED_JSON_1 = {
|
166 |
| - 'name': OPERATION_NAME_1, |
167 | 165 | 'done': True,
|
168 | 166 | # if done is true then either response or error should be populated
|
169 | 167 | }
|
170 | 168 | OPERATION_MISSING_NAME = {
|
| 169 | + # Name is required if the operation is not done. |
171 | 170 | 'done': False
|
172 | 171 | }
|
173 | 172 | OPERATION_ERROR_CODE = 400
|
174 | 173 | OPERATION_ERROR_MSG = "Invalid argument"
|
175 | 174 | OPERATION_ERROR_EXPECTED_STATUS = 'INVALID_ARGUMENT'
|
176 | 175 | OPERATION_ERROR_JSON_1 = {
|
177 |
| - 'name': OPERATION_NAME_1, |
178 | 176 | 'done': True,
|
179 | 177 | 'error': {
|
180 | 178 | 'code': OPERATION_ERROR_CODE,
|
@@ -609,17 +607,10 @@ def test_operation_error(self):
|
609 | 607 | check_operation_error(excinfo, OPERATION_ERROR_EXPECTED_STATUS, OPERATION_ERROR_MSG)
|
610 | 608 |
|
611 | 609 | def test_malformed_operation(self):
|
612 |
| - recorder = instrument_mlkit_service( |
613 |
| - status=[200, 200], |
614 |
| - payload=[OPERATION_MALFORMED_RESPONSE, LOCKED_MODEL_2_RESPONSE]) |
615 |
| - expected_model = mlkit.Model.from_dict(LOCKED_MODEL_JSON_2) |
616 |
| - model = mlkit.create_model(MODEL_1) |
617 |
| - assert model == expected_model |
618 |
| - assert len(recorder) == 2 |
619 |
| - assert recorder[0].method == 'POST' |
620 |
| - assert recorder[0].url == TestCreateModel._url(PROJECT_ID) |
621 |
| - assert recorder[1].method == 'GET' |
622 |
| - assert recorder[1].url == TestCreateModel._get_url(PROJECT_ID, MODEL_ID_1) |
| 610 | + instrument_mlkit_service(status=200, payload=OPERATION_MALFORMED_RESPONSE) |
| 611 | + with pytest.raises(Exception) as excinfo: |
| 612 | + mlkit.create_model(MODEL_1) |
| 613 | + check_error(excinfo, exceptions.UnknownError, 'Internal Error: Malformed Operation.') |
623 | 614 |
|
624 | 615 | def test_rpc_error_create(self):
|
625 | 616 | create_recorder = instrument_mlkit_service(
|
@@ -708,17 +699,10 @@ def test_operation_error(self):
|
708 | 699 | check_operation_error(excinfo, OPERATION_ERROR_EXPECTED_STATUS, OPERATION_ERROR_MSG)
|
709 | 700 |
|
710 | 701 | def test_malformed_operation(self):
|
711 |
| - recorder = instrument_mlkit_service( |
712 |
| - status=[200, 200], |
713 |
| - payload=[OPERATION_MALFORMED_RESPONSE, LOCKED_MODEL_2_RESPONSE]) |
714 |
| - expected_model = mlkit.Model.from_dict(LOCKED_MODEL_JSON_2) |
715 |
| - model = mlkit.update_model(MODEL_1) |
716 |
| - assert model == expected_model |
717 |
| - assert len(recorder) == 2 |
718 |
| - assert recorder[0].method == 'PATCH' |
719 |
| - assert recorder[0].url == TestUpdateModel._url(PROJECT_ID, MODEL_ID_1) |
720 |
| - assert recorder[1].method == 'GET' |
721 |
| - assert recorder[1].url == TestUpdateModel._url(PROJECT_ID, MODEL_ID_1) |
| 702 | + instrument_mlkit_service(status=200, payload=OPERATION_MALFORMED_RESPONSE) |
| 703 | + with pytest.raises(Exception) as excinfo: |
| 704 | + mlkit.update_model(MODEL_1) |
| 705 | + check_error(excinfo, exceptions.UnknownError, 'Internal Error: Malformed Operation.') |
722 | 706 |
|
723 | 707 | def test_rpc_error(self):
|
724 | 708 | create_recorder = instrument_mlkit_service(
|
@@ -824,17 +808,10 @@ def test_operation_error(self, publish_function):
|
824 | 808 |
|
825 | 809 | @pytest.mark.parametrize('publish_function', PUBLISH_UNPUBLISH_FUNCS)
|
826 | 810 | def test_malformed_operation(self, publish_function):
|
827 |
| - recorder = instrument_mlkit_service( |
828 |
| - status=[200, 200], |
829 |
| - payload=[OPERATION_MALFORMED_RESPONSE, LOCKED_MODEL_2_RESPONSE]) |
830 |
| - expected_model = mlkit.Model.from_dict(LOCKED_MODEL_JSON_2) |
831 |
| - model = publish_function(MODEL_ID_1) |
832 |
| - assert model == expected_model |
833 |
| - assert len(recorder) == 2 |
834 |
| - assert recorder[0].method == 'PATCH' |
835 |
| - assert recorder[0].url == TestPublishUnpublish._url(PROJECT_ID, MODEL_ID_1) |
836 |
| - assert recorder[1].method == 'GET' |
837 |
| - assert recorder[1].url == TestPublishUnpublish._url(PROJECT_ID, MODEL_ID_1) |
| 811 | + instrument_mlkit_service(status=200, payload=OPERATION_MALFORMED_RESPONSE) |
| 812 | + with pytest.raises(Exception) as excinfo: |
| 813 | + publish_function(MODEL_ID_1) |
| 814 | + check_error(excinfo, exceptions.UnknownError, 'Internal Error: Malformed Operation.') |
838 | 815 |
|
839 | 816 | @pytest.mark.parametrize('publish_function', PUBLISH_UNPUBLISH_FUNCS)
|
840 | 817 | def test_rpc_error(self, publish_function):
|
|
0 commit comments