1# 2# Copyright 2016 Google Inc. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16"""Test for generated sample module.""" 17 18import unittest 19 20import six 21 22from apitools.base.py.testing import mock 23 24from samples.iam_sample.iam_v1 import iam_v1_client # nopep8 25from samples.iam_sample.iam_v1 import iam_v1_messages # nopep8 26 27 28class DnsGenClientSanityTest(unittest.TestCase): 29 30 def testBaseUrl(self): 31 self.assertEquals(u'https://iam.googleapis.com/', 32 iam_v1_client.IamV1.BASE_URL) 33 34 def testMessagesModule(self): 35 self.assertEquals(iam_v1_messages, iam_v1_client.IamV1.MESSAGES_MODULE) 36 37 def testAttributes(self): 38 inner_classes = set([]) 39 for key, value in iam_v1_client.IamV1.__dict__.items(): 40 if isinstance(value, six.class_types): 41 inner_classes.add(key) 42 self.assertEquals(set([ 43 'IamPoliciesService', 44 'ProjectsService', 45 'ProjectsServiceAccountsKeysService', 46 'ProjectsServiceAccountsService', 47 'RolesService']), inner_classes) 48 49 50class IamGenClientTest(unittest.TestCase): 51 52 def setUp(self): 53 self.mocked_iam_v1 = mock.Client(iam_v1_client.IamV1) 54 self.mocked_iam_v1.Mock() 55 self.addCleanup(self.mocked_iam_v1.Unmock) 56 57 def testFlatPath(self): 58 get_method_config = (self.mocked_iam_v1.projects_serviceAccounts_keys 59 .GetMethodConfig('Get')) 60 self.assertEquals('v1/projects/{projectsId}/serviceAccounts' 61 '/{serviceAccountsId}/keys/{keysId}', 62 get_method_config.flat_path) 63 self.assertEquals('v1/{+name}', get_method_config.relative_path) 64 65 def testServiceAccountsKeysList(self): 66 response_key = iam_v1_messages.ServiceAccountKey( 67 name=u'test-key') 68 self.mocked_iam_v1.projects_serviceAccounts_keys.List.Expect( 69 iam_v1_messages.IamProjectsServiceAccountsKeysListRequest( 70 name=u'test-service-account.'), 71 iam_v1_messages.ListServiceAccountKeysResponse( 72 keys=[response_key])) 73 74 result = self.mocked_iam_v1.projects_serviceAccounts_keys.List( 75 iam_v1_messages.IamProjectsServiceAccountsKeysListRequest( 76 name=u'test-service-account.')) 77 78 self.assertEquals([response_key], result.keys) 79