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 import list_pager 23from apitools.base.py.testing import mock 24 25from samples.dns_sample.dns_v1 import dns_v1_client 26from samples.dns_sample.dns_v1 import dns_v1_messages 27 28 29class DnsGenClientSanityTest(unittest.TestCase): 30 31 def testBaseUrl(self): 32 self.assertEquals(u'https://www.googleapis.com/dns/v1/', 33 dns_v1_client.DnsV1.BASE_URL) 34 35 def testMessagesModule(self): 36 self.assertEquals(dns_v1_messages, dns_v1_client.DnsV1.MESSAGES_MODULE) 37 38 def testAttributes(self): 39 inner_classes = set([]) 40 for key, value in dns_v1_client.DnsV1.__dict__.items(): 41 if isinstance(value, six.class_types): 42 inner_classes.add(key) 43 self.assertEquals(set([ 44 'ChangesService', 45 'ProjectsService', 46 'ManagedZonesService', 47 'ResourceRecordSetsService']), inner_classes) 48 49 50class DnsGenClientTest(unittest.TestCase): 51 52 def setUp(self): 53 self.mocked_dns_v1 = mock.Client(dns_v1_client.DnsV1) 54 self.mocked_dns_v1.Mock() 55 self.addCleanup(self.mocked_dns_v1.Unmock) 56 57 def testFlatPath(self): 58 get_method_config = self.mocked_dns_v1.projects.GetMethodConfig('Get') 59 self.assertIsNone(get_method_config.flat_path) 60 self.assertEquals('projects/{project}', 61 get_method_config.relative_path) 62 63 def testRecordSetList(self): 64 response_record_set = dns_v1_messages.ResourceRecordSet( 65 kind=u"dns#resourceRecordSet", 66 name=u"zone.com.", 67 rrdatas=[u"1.2.3.4"], 68 ttl=21600, 69 type=u"A") 70 self.mocked_dns_v1.resourceRecordSets.List.Expect( 71 dns_v1_messages.DnsResourceRecordSetsListRequest( 72 project=u'my-project', 73 managedZone=u'test_zone_name', 74 type=u'green', 75 maxResults=100), 76 dns_v1_messages.ResourceRecordSetsListResponse( 77 rrsets=[response_record_set])) 78 79 results = list(list_pager.YieldFromList( 80 self.mocked_dns_v1.resourceRecordSets, 81 dns_v1_messages.DnsResourceRecordSetsListRequest( 82 project='my-project', 83 managedZone='test_zone_name', 84 type='green'), 85 limit=100, field='rrsets')) 86 87 self.assertEquals([response_record_set], results) 88