|
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,46 @@ def test_create_reasoning_engine( |
794 | 795 | retry=_TEST_RETRY, |
795 | 796 | ) |
796 | 797 |
|
| 798 | + def test_get_iam_policy(self): |
| 799 | + with mock.patch.object( |
| 800 | + base.VertexAiResourceNoun, "_get_gca_resource" |
| 801 | + ) as mock_get_gca_resource: |
| 802 | + mock_get_gca_resource.return_value = types.ReasoningEngine( |
| 803 | + name=_TEST_REASONING_ENGINE_RESOURCE_NAME |
| 804 | + ) |
| 805 | + reasoning_engine = reasoning_engines.ReasoningEngine( |
| 806 | + _TEST_REASONING_ENGINE_RESOURCE_NAME |
| 807 | + ) |
| 808 | + |
| 809 | + test_policy = policy_pb2.Policy(version=1) |
| 810 | + with mock.patch.object( |
| 811 | + reasoning_engine.api_client, "get_iam_policy" |
| 812 | + ) as mock_get_iam_policy: |
| 813 | + mock_get_iam_policy.return_value = test_policy |
| 814 | + policy = reasoning_engine.get_iam_policy(policy_version=1) |
| 815 | + mock_get_iam_policy.assert_called_once() |
| 816 | + assert policy == test_policy |
| 817 | + |
| 818 | + def test_set_iam_policy(self): |
| 819 | + with mock.patch.object( |
| 820 | + base.VertexAiResourceNoun, "_get_gca_resource" |
| 821 | + ) as mock_get_gca_resource: |
| 822 | + mock_get_gca_resource.return_value = types.ReasoningEngine( |
| 823 | + name=_TEST_REASONING_ENGINE_RESOURCE_NAME |
| 824 | + ) |
| 825 | + reasoning_engine = reasoning_engines.ReasoningEngine( |
| 826 | + _TEST_REASONING_ENGINE_RESOURCE_NAME |
| 827 | + ) |
| 828 | + |
| 829 | + test_policy = policy_pb2.Policy(version=1) |
| 830 | + with mock.patch.object( |
| 831 | + reasoning_engine.api_client, "set_iam_policy" |
| 832 | + ) as mock_set_iam_policy: |
| 833 | + mock_set_iam_policy.return_value = test_policy |
| 834 | + policy = reasoning_engine.set_iam_policy(test_policy) |
| 835 | + mock_set_iam_policy.assert_called_once() |
| 836 | + assert policy == test_policy |
| 837 | + |
797 | 838 | @pytest.mark.usefixtures("caplog") |
798 | 839 | def test_create_reasoning_engine_warn_resource_name( |
799 | 840 | self, |
|
0 commit comments