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