Skip to content

Commit

Permalink
tests: add cases for int64 field, map pagination, field that start wi…
Browse files Browse the repository at this point in the history
…th capital letter (#105)

* tests: int64, capitalletter, map pagination

* unused import

* tests: review fix

* tests:review fix
  • Loading branch information
georgiyekkert authored Aug 23, 2021
1 parent 18b088a commit 16f4b44
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 7 deletions.
20 changes: 13 additions & 7 deletions packages/google-cloud-compute/tests/system/test_instance_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
22 changes: 22 additions & 0 deletions packages/google-cloud-compute/tests/system/test_pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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])
56 changes: 56 additions & 0 deletions packages/google-cloud-compute/tests/system/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

0 comments on commit 16f4b44

Please sign in to comment.