From 16f4b44295c7ba4302af0c668b9e9f629b83efde Mon Sep 17 00:00:00 2001 From: georgiyekkert Date: Mon, 23 Aug 2021 12:41:37 -0700 Subject: [PATCH] tests: add cases for int64 field, map pagination, field that start with capital letter (#105) * tests: int64, capitalletter, map pagination * unused import * tests: review fix * tests:review fix --- .../tests/system/test_instance_group.py | 20 ++++--- .../tests/system/test_pagination.py | 22 ++++++++ .../tests/system/test_smoke.py | 56 +++++++++++++++++++ 3 files changed, 91 insertions(+), 7 deletions(-) diff --git a/packages/google-cloud-compute/tests/system/test_instance_group.py b/packages/google-cloud-compute/tests/system/test_instance_group.py index 3e6a37226f3f..abb46804739f 100644 --- a/packages/google-cloud-compute/tests/system/test_instance_group.py +++ b/packages/google-cloud-compute/tests/system/test_instance_group.py @@ -135,10 +135,16 @@ def test_instance_group_resize(self): ) self.assertEqual(instance_group.target_size, 1) - # Resize to zero fails, uncomment once fixed b/189145532. - # resize_0_op = self.igm_client.resize(project=self.DEFAULT_PROJECT, - # zone=self.DEFAULT_ZONE, size=0, instance_group_manager=igm_name) - # self.wait_for_zonal_operation(resize_0_op.name) - # igm = self.igm_client.get(project=self.DEFAULT_PROJECT, zone=self.DEFAULT_ZONE, - # instance_group_manager=igm_name) - # self.assertEqual(igm.target_size, 0) + resize_0_op = self.igm_client.resize( + project=self.DEFAULT_PROJECT, + zone=self.DEFAULT_ZONE, + size=0, + instance_group_manager=igm_name, + ) + self.wait_for_zonal_operation(resize_0_op.name) + igm = self.igm_client.get( + project=self.DEFAULT_PROJECT, + zone=self.DEFAULT_ZONE, + instance_group_manager=igm_name, + ) + self.assertEqual(igm.target_size, 0) diff --git a/packages/google-cloud-compute/tests/system/test_pagination.py b/packages/google-cloud-compute/tests/system/test_pagination.py index 3f8f4e546a3c..79781004b70d 100644 --- a/packages/google-cloud-compute/tests/system/test_pagination.py +++ b/packages/google-cloud-compute/tests/system/test_pagination.py @@ -12,8 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +import collections +from google.cloud.compute_v1.services.accelerator_types.client import ( + AcceleratorTypesClient, +) from google.cloud.compute_v1.services.zones.client import ZonesClient +from google.cloud.compute_v1.types import AggregatedListAcceleratorTypesRequest from google.cloud.compute_v1.types import ListZonesRequest from tests.system.base import TestBase @@ -65,3 +70,20 @@ def test_auto_paging(self): presented = True break self.assertTrue(presented) + + +class TestPaginationAggregatedList(TestBase): + def setUp(self) -> None: + super().setUp() + + def test_auto_paging_map_response(self): + client = AcceleratorTypesClient() + request = AggregatedListAcceleratorTypesRequest( + project=self.DEFAULT_PROJECT, max_results=3 + ) + result = client.aggregated_list(request=request) + zone_acc_types = collections.defaultdict(list) + for zone, types in result: + zone_acc_types[zone].extend(at.name for at in types.accelerator_types) + default_zone = "zones/" + self.DEFAULT_ZONE + self.assertIn("nvidia-tesla-t4", zone_acc_types[default_zone]) diff --git a/packages/google-cloud-compute/tests/system/test_smoke.py b/packages/google-cloud-compute/tests/system/test_smoke.py index 36c6fbddf2dd..0668cea6c4a1 100644 --- a/packages/google-cloud-compute/tests/system/test_smoke.py +++ b/packages/google-cloud-compute/tests/system/test_smoke.py @@ -16,8 +16,14 @@ import time import google.api_core.exceptions +from google.cloud.compute_v1.services.firewalls.client import FirewallsClient +from google.cloud.compute_v1.services.images.client import ImagesClient from google.cloud.compute_v1.services.instances.client import InstancesClient from google.cloud.compute_v1.types import ( + Allowed, + Firewall, + Image, + InsertImageRequest, InsertInstanceRequest, Instance, AttachedDisk, @@ -189,3 +195,53 @@ def insert_instance(self): operation = self.client.insert(request=request) self.wait_for_zonal_operation(operation.name) self.instances.append(self.name) + + +class TestComputeImages(TestBase): + def setUp(self) -> None: + super().setUp() + + def test_int64(self): + # we want to test a field with format:int64 + name = self.get_unique_name("image") + license_codes = [5543610867827062957] + image = Image( + name=name, + license_codes=license_codes, + source_image="projects/debian-cloud/global/images/debian-10-buster-v20210721", + ) + images_client = ImagesClient(transport="rest") + request = InsertImageRequest(project=self.DEFAULT_PROJECT, image_resource=image) + op = images_client.insert(request) + try: + self.wait_for_global_operation(op.name) + + fetched = images_client.get(project=self.DEFAULT_PROJECT, image=name) + self.assertEqual(fetched.license_codes, license_codes) + self.assertEqual(fetched.name, name) + finally: + images_client.delete(project=self.DEFAULT_PROJECT, image=name) + + +class TestComputeFirewalls(TestBase): + def setUp(self): + super().setUp() + + def test_capital_letter_field(self): + # we want to test a field like "IPProtocol" + name = self.get_unique_name("firewall") + client = FirewallsClient() + firewall = Firewall( + name=name, + source_ranges=["0.0.0.0/0"], + allowed=[Allowed(I_p_protocol="tcp", ports=["80"])], + ) + op = client.insert(project=self.DEFAULT_PROJECT, firewall_resource=firewall) + try: + self.wait_for_global_operation(op.name) + + fetched = client.get(project=self.DEFAULT_PROJECT, firewall=name) + self.assertEqual(fetched.allowed[0].I_p_protocol, "tcp") + self.assertEqual(fetched.allowed[0].ports, ["80"]) + finally: + client.delete(project=self.DEFAULT_PROJECT, firewall=name)