@@ -517,45 +517,53 @@ def test_list_resource_record_sets_explicit(self):
517517 self .assertEqual (req ['query_params' ],
518518 {'maxResults' : 3 , 'pageToken' : TOKEN })
519519
520- def test_list_changes_defaults (self ):
520+ def _get_changes (self , token , changes_name ):
521521 from google .cloud ._helpers import _datetime_to_rfc3339
522- from google .cloud .dns .changes import Changes
523- from google .cloud .dns .resource_record_set import ResourceRecordSet
524- self ._setUpConstants ()
525- PATH = 'projects/%s/managedZones/%s/changes' % (
526- self .PROJECT , self .ZONE_NAME )
527- TOKEN = 'TOKEN'
528- NAME_1 = 'www.example.com'
529- TYPE_1 = 'A'
530- TTL_1 = '86400'
531- RRDATAS_1 = ['123.45.67.89' ]
532- NAME_2 = 'alias.example.com'
533- TYPE_2 = 'CNAME'
534- TTL_2 = '3600'
535- RRDATAS_2 = ['www.example.com' ]
536- CHANGES_NAME = 'changeset_id'
537- DATA = {
538- 'nextPageToken' : TOKEN ,
522+
523+ name_1 = 'www.example.com'
524+ type_1 = 'A'
525+ ttl_1 = '86400'
526+ rrdatas_1 = ['123.45.67.89' ]
527+ name_2 = 'alias.example.com'
528+ type_2 = 'CNAME'
529+ ttl_2 = '3600'
530+ rrdatas_2 = ['www.example.com' ]
531+ result = {
539532 'changes' : [{
540533 'kind' : 'dns#change' ,
541- 'id' : CHANGES_NAME ,
534+ 'id' : changes_name ,
542535 'status' : 'pending' ,
543536 'startTime' : _datetime_to_rfc3339 (self .WHEN ),
544537 'additions' : [
545538 {'kind' : 'dns#resourceRecordSet' ,
546- 'name' : NAME_1 ,
547- 'type' : TYPE_1 ,
548- 'ttl' : TTL_1 ,
549- 'rrdatas' : RRDATAS_1 }],
539+ 'name' : name_1 ,
540+ 'type' : type_1 ,
541+ 'ttl' : ttl_1 ,
542+ 'rrdatas' : rrdatas_1 }],
550543 'deletions' : [
551544 {'kind' : 'dns#change' ,
552- 'name' : NAME_2 ,
553- 'type' : TYPE_2 ,
554- 'ttl' : TTL_2 ,
555- 'rrdatas' : RRDATAS_2 }],
545+ 'name' : name_2 ,
546+ 'type' : type_2 ,
547+ 'ttl' : ttl_2 ,
548+ 'rrdatas' : rrdatas_2 }],
556549 }]
557550 }
558- conn = _Connection (DATA )
551+ if token is not None :
552+ result ['nextPageToken' ] = token
553+ return result
554+
555+ def test_list_changes_defaults (self ):
556+ from google .cloud .dns .changes import Changes
557+ from google .cloud .dns .resource_record_set import ResourceRecordSet
558+
559+ self ._setUpConstants ()
560+ path = 'projects/%s/managedZones/%s/changes' % (
561+ self .PROJECT , self .ZONE_NAME )
562+ token = 'TOKEN'
563+ changes_name = 'changeset_id'
564+ data = self ._get_changes (token , changes_name )
565+
566+ conn = _Connection (data )
559567 client = _Client (project = self .PROJECT , connection = conn )
560568 zone = self ._makeOne (self .ZONE_NAME , self .DNS_NAME , client )
561569
@@ -565,10 +573,10 @@ def test_list_changes_defaults(self):
565573 changes = list (iterator .page )
566574 token = iterator .next_page_token
567575
568- self .assertEqual (len (changes ), len (DATA ['changes' ]))
569- for found , expected in zip (changes , DATA ['changes' ]):
576+ self .assertEqual (len (changes ), len (data ['changes' ]))
577+ for found , expected in zip (changes , data ['changes' ]):
570578 self .assertIsInstance (found , Changes )
571- self .assertEqual (found .name , CHANGES_NAME )
579+ self .assertEqual (found .name , changes_name )
572580 self .assertEqual (found .status , 'pending' )
573581 self .assertEqual (found .started , self .WHEN )
574582
@@ -590,67 +598,40 @@ def test_list_changes_defaults(self):
590598 self .assertEqual (found_rr .ttl , int (expected_rr ['ttl' ]))
591599 self .assertEqual (found_rr .rrdatas , expected_rr ['rrdatas' ])
592600
593- self .assertEqual (token , TOKEN )
601+ self .assertEqual (token , token )
594602
595603 self .assertEqual (len (conn ._requested ), 1 )
596604 req = conn ._requested [0 ]
597605 self .assertEqual (req ['method' ], 'GET' )
598- self .assertEqual (req ['path' ], '/%s' % PATH )
606+ self .assertEqual (req ['path' ], '/%s' % ( path ,) )
599607
600608 def test_list_changes_explicit (self ):
601- from google .cloud ._helpers import _datetime_to_rfc3339
602609 from google .cloud .dns .changes import Changes
603610 from google .cloud .dns .resource_record_set import ResourceRecordSet
611+
604612 self ._setUpConstants ()
605- PATH = 'projects/%s/managedZones/%s/changes' % (
613+ path = 'projects/%s/managedZones/%s/changes' % (
606614 self .PROJECT , self .ZONE_NAME )
607- TOKEN = 'TOKEN'
608- NAME_1 = 'www.example.com'
609- TYPE_1 = 'A'
610- TTL_1 = '86400'
611- RRDATAS_1 = ['123.45.67.89' ]
612- NAME_2 = 'alias.example.com'
613- TYPE_2 = 'CNAME'
614- TTL_2 = '3600'
615- RRDATAS_2 = ['www.example.com' ]
616- CHANGES_NAME = 'changeset_id'
617- DATA = {
618- 'changes' : [{
619- 'kind' : 'dns#change' ,
620- 'id' : CHANGES_NAME ,
621- 'status' : 'pending' ,
622- 'startTime' : _datetime_to_rfc3339 (self .WHEN ),
623- 'additions' : [
624- {'kind' : 'dns#resourceRecordSet' ,
625- 'name' : NAME_1 ,
626- 'type' : TYPE_1 ,
627- 'ttl' : TTL_1 ,
628- 'rrdatas' : RRDATAS_1 }],
629- 'deletions' : [
630- {'kind' : 'dns#change' ,
631- 'name' : NAME_2 ,
632- 'type' : TYPE_2 ,
633- 'ttl' : TTL_2 ,
634- 'rrdatas' : RRDATAS_2 }],
635- }]
636- }
615+ changes_name = 'changeset_id'
616+ data = self ._get_changes (None , changes_name )
637617 conn1 = _Connection ()
638618 client1 = _Client (project = self .PROJECT , connection = conn1 )
639- conn2 = _Connection (DATA )
619+ conn2 = _Connection (data )
640620 client2 = _Client (project = self .PROJECT , connection = conn2 )
641621 zone = self ._makeOne (self .ZONE_NAME , self .DNS_NAME , client1 )
642622
623+ page_token = 'TOKEN'
643624 iterator = zone .list_changes (
644- max_results = 3 , page_token = TOKEN , client = client2 )
625+ max_results = 3 , page_token = page_token , client = client2 )
645626 self .assertIs (zone , iterator .zone )
646627 iterator .update_page ()
647628 changes = list (iterator .page )
648629 token = iterator .next_page_token
649630
650- self .assertEqual (len (changes ), len (DATA ['changes' ]))
651- for found , expected in zip (changes , DATA ['changes' ]):
631+ self .assertEqual (len (changes ), len (data ['changes' ]))
632+ for found , expected in zip (changes , data ['changes' ]):
652633 self .assertIsInstance (found , Changes )
653- self .assertEqual (found .name , CHANGES_NAME )
634+ self .assertEqual (found .name , changes_name )
654635 self .assertEqual (found .status , 'pending' )
655636 self .assertEqual (found .started , self .WHEN )
656637
@@ -678,9 +659,9 @@ def test_list_changes_explicit(self):
678659 self .assertEqual (len (conn2 ._requested ), 1 )
679660 req = conn2 ._requested [0 ]
680661 self .assertEqual (req ['method' ], 'GET' )
681- self .assertEqual (req ['path' ], '/%s' % PATH )
662+ self .assertEqual (req ['path' ], '/%s' % ( path ,) )
682663 self .assertEqual (req ['query_params' ],
683- {'maxResults' : 3 , 'pageToken' : TOKEN })
664+ {'maxResults' : 3 , 'pageToken' : page_token })
684665
685666
686667class _Client (object ):
0 commit comments