|
42 | 42 | from vertexai.preview import reasoning_engines |
43 | 43 | from vertexai.reasoning_engines import _reasoning_engines |
44 | 44 | from vertexai.reasoning_engines import _utils |
| 45 | +from google.iam.v1 import policy_pb2 |
45 | 46 | from google.api import httpbody_pb2 |
46 | 47 | from google.protobuf import field_mask_pb2 |
47 | 48 | from google.protobuf import struct_pb2 |
@@ -794,6 +795,56 @@ def test_create_reasoning_engine( |
794 | 795 | retry=_TEST_RETRY, |
795 | 796 | ) |
796 | 797 |
|
| 798 | + def test_get_iam_policy(self): |
| 799 | + """Tests that `get_iam_policy` method correctly calls the underlying API client. |
| 800 | +
|
| 801 | + It verifies that the `get_iam_policy` method is called with the expected |
| 802 | + resource name and returns the policy as provided by the mocked API client. |
| 803 | + """ |
| 804 | + with mock.patch.object( |
| 805 | + base.VertexAiResourceNoun, "_get_gca_resource" |
| 806 | + ) as mock_get_gca_resource: |
| 807 | + mock_get_gca_resource.return_value = types.ReasoningEngine( |
| 808 | + name=_TEST_REASONING_ENGINE_RESOURCE_NAME |
| 809 | + ) |
| 810 | + reasoning_engine = reasoning_engines.ReasoningEngine( |
| 811 | + _TEST_REASONING_ENGINE_RESOURCE_NAME |
| 812 | + ) |
| 813 | + |
| 814 | + test_policy = policy_pb2.Policy(version=1) |
| 815 | + with mock.patch.object( |
| 816 | + reasoning_engine.api_client, "get_iam_policy" |
| 817 | + ) as mock_get_iam_policy: |
| 818 | + mock_get_iam_policy.return_value = test_policy |
| 819 | + policy = reasoning_engine.get_iam_policy(policy_version=1) |
| 820 | + mock_get_iam_policy.assert_called_once() |
| 821 | + assert policy == test_policy |
| 822 | + |
| 823 | + def test_set_iam_policy(self): |
| 824 | + """Tests that `set_iam_policy` method correctly calls the underlying API client. |
| 825 | +
|
| 826 | + It verifies that the `set_iam_policy` method is called with the expected |
| 827 | + policy and returns the policy as provided by the mocked API client. |
| 828 | + """ |
| 829 | + with mock.patch.object( |
| 830 | + base.VertexAiResourceNoun, "_get_gca_resource" |
| 831 | + ) as mock_get_gca_resource: |
| 832 | + mock_get_gca_resource.return_value = types.ReasoningEngine( |
| 833 | + name=_TEST_REASONING_ENGINE_RESOURCE_NAME |
| 834 | + ) |
| 835 | + reasoning_engine = reasoning_engines.ReasoningEngine( |
| 836 | + _TEST_REASONING_ENGINE_RESOURCE_NAME |
| 837 | + ) |
| 838 | + |
| 839 | + test_policy = policy_pb2.Policy(version=1) |
| 840 | + with mock.patch.object( |
| 841 | + reasoning_engine.api_client, "set_iam_policy" |
| 842 | + ) as mock_set_iam_policy: |
| 843 | + mock_set_iam_policy.return_value = test_policy |
| 844 | + policy = reasoning_engine.set_iam_policy(test_policy) |
| 845 | + mock_set_iam_policy.assert_called_once() |
| 846 | + assert policy == test_policy |
| 847 | + |
797 | 848 | @pytest.mark.usefixtures("caplog") |
798 | 849 | def test_create_reasoning_engine_warn_resource_name( |
799 | 850 | self, |
|
0 commit comments