def test_get_rest_flattened(): client = ImageFamilyViewsClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. return_value = compute.ImageFamilyView() # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 json_return_value = compute.ImageFamilyView.to_json(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value # get arguments that satisfy an http rule for this method sample_request = { "project": "sample1", "zone": "sample2", "family": "sample3" } # get truthy value for each flattened field mock_args = dict( project="project_value", zone="zone_value", family="family_value", ) mock_args.update(sample_request) client.get(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( "https://%s/compute/v1/projects/{project}/zones/{zone}/imageFamilyViews/{family}" % client.transport._host, args[1], )
def test_test_iam_permissions_rest_flattened(): client = LicenseCodesClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. return_value = compute.TestPermissionsResponse() # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 json_return_value = compute.TestPermissionsResponse.to_json( return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value # get arguments that satisfy an http rule for this method sample_request = {"project": "sample1", "resource": "sample2"} # get truthy value for each flattened field mock_args = dict( project="project_value", resource="resource_value", test_permissions_request_resource=compute.TestPermissionsRequest( permissions=["permissions_value"]), ) mock_args.update(sample_request) client.test_iam_permissions(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( "https://%s/compute/v1/projects/{project}/global/licenseCodes/{resource}/testIamPermissions" % client.transport._host, args[1], )
def test_validate_failure(tmpl, path): assert not path_template.validate(tmpl, path)
def test_expand_success(tmpl, args, kwargs, expected_result): result = path_template.expand(tmpl, *args, **kwargs) assert result == expected_result assert path_template.validate(tmpl, result)