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 unittest2 19import six 20 21from apitools.base.py.testing import mock 22 23from samples.iam_sample.iam_v1 import iam_v1_client # nopep8 24from samples.iam_sample.iam_v1 import iam_v1_messages # nopep8 25 26 27class DnsGenClientSanityTest(unittest2.TestCase): 28 29 def testBaseUrl(self): 30 self.assertEquals(u'https://iam.googleapis.com/', 31 iam_v1_client.IamV1.BASE_URL) 32 33 def testMessagesModule(self): 34 self.assertEquals(iam_v1_messages, iam_v1_client.IamV1.MESSAGES_MODULE) 35 36 def testAttributes(self): 37 inner_classes = set([]) 38 for key, value in iam_v1_client.IamV1.__dict__.items(): 39 if isinstance(value, six.class_types): 40 inner_classes.add(key) 41 self.assertEquals(set([ 42 'IamPoliciesService', 43 'ProjectsService', 44 'ProjectsServiceAccountsKeysService', 45 'ProjectsServiceAccountsService', 46 'RolesService']), inner_classes) 47 48 49class IamGenClientTest(unittest2.TestCase): 50 51 def setUp(self): 52 self.mocked_iam_v1 = mock.Client(iam_v1_client.IamV1) 53 self.mocked_iam_v1.Mock() 54 self.addCleanup(self.mocked_iam_v1.Unmock) 55 56 def testFlatPath(self): 57 get_method_config = (self.mocked_iam_v1.projects_serviceAccounts_keys 58 .GetMethodConfig('Get')) 59 self.assertEquals('v1/projects/{projectsId}/serviceAccounts' 60 '/{serviceAccountsId}/keys/{keysId}', 61 get_method_config.flat_path) 62 self.assertEquals('v1/{+name}', get_method_config.relative_path) 63 64 def testServiceAccountsKeysList(self): 65 response_key = iam_v1_messages.ServiceAccountKey( 66 name=u'test-key') 67 self.mocked_iam_v1.projects_serviceAccounts_keys.List.Expect( 68 iam_v1_messages.IamProjectsServiceAccountsKeysListRequest( 69 name=u'test-service-account.'), 70 iam_v1_messages.ListServiceAccountKeysResponse( 71 keys=[response_key])) 72 73 result = self.mocked_iam_v1.projects_serviceAccounts_keys.List( 74 iam_v1_messages.IamProjectsServiceAccountsKeysListRequest( 75 name=u'test-service-account.')) 76 77 self.assertEquals([response_key], result.keys) 78