<s> import sys <EOL> import unittest <EOL> from libcloud . utils . py3 import httplib <EOL> from libcloud . dns . types import RecordType , ZoneDoesNotExistError <EOL> from libcloud . dns . types import RecordDoesNotExistError <EOL> from libcloud . dns . drivers . route53 import Route53DNSDriver <EOL> from libcloud . test import MockHttp <EOL> from libcloud . test . file_fixtures import DNSFileFixtures <EOL> from libcloud . test . secrets import DNS_PARAMS_ROUTE53 <EOL> class Route53Tests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> Route53DNSDriver . connectionCls . conn_classes = ( <EOL> Route53MockHttp , Route53MockHttp ) <EOL> Route53MockHttp . type = None <EOL> self . driver = Route53DNSDriver ( * DNS_PARAMS_ROUTE53 ) <EOL> def test_list_record_types ( self ) : <EOL> record_types = self . driver . list_record_types ( ) <EOL> self . assertEqual ( len ( record_types ) , <NUM_LIT:10> ) <EOL> self . assertTrue ( RecordType . A in record_types ) <EOL> def test_list_zones ( self ) : <EOL> zones = self . driver . list_zones ( ) <EOL> self . assertEqual ( len ( zones ) , <NUM_LIT:5> ) <EOL> zone = zones [ <NUM_LIT:0> ] <EOL> self . assertEqual ( zone . id , '<STR_LIT>' ) <EOL> self . assertEqual ( zone . type , '<STR_LIT>' ) <EOL> self . assertEqual ( zone . domain , '<STR_LIT>' ) <EOL> def test_list_records ( self ) : <EOL> zone = self . driver . list_zones ( ) [ <NUM_LIT:0> ] <EOL> records = self . driver . list_records ( zone = zone ) <EOL> self . assertEqual ( len ( records ) , <NUM_LIT:10> ) <EOL> record = records [ <NUM_LIT:1> ] <EOL> self . assertEqual ( record . name , '<STR_LIT>' ) <EOL> self . assertEqual ( record . id , '<STR_LIT>' ) <EOL> self . assertEqual ( record . type , RecordType . A ) <EOL> self . assertEqual ( record . data , '<STR_LIT>' ) <EOL> self . assertEqual ( record . extra [ '<STR_LIT>' ] , <NUM_LIT> ) <EOL> record = records [ <NUM_LIT:3> ] <EOL> self . assertEqual ( record . type , RecordType . MX ) <EOL> self . assertEqual ( record . data , '<STR_LIT>' ) <EOL> self . assertEqual ( record . extra [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> record = records [ <NUM_LIT:4> ] <EOL> self . assertEqual ( record . type , RecordType . MX ) <EOL> self . assertEqual ( record . data , '<STR_LIT>' ) <EOL> self . assertEqual ( record . extra [ '<STR_LIT>' ] , <NUM_LIT:5> ) <EOL> record = records [ <NUM_LIT:8> ] <EOL> self . assertEqual ( record . type , RecordType . SRV ) <EOL> self . assertEqual ( record . data , '<STR_LIT>' ) <EOL> self . assertEqual ( record . extra [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( record . extra [ '<STR_LIT>' ] , <NUM_LIT:10> ) <EOL> self . assertEqual ( record . extra [ '<STR_LIT:port>' ] , <NUM_LIT> ) <EOL> def test_get_zone ( self ) : <EOL> zone = self . driver . get_zone ( zone_id = '<STR_LIT>' ) <EOL> self . assertEqual ( zone . id , '<STR_LIT>' ) <EOL> self . assertEqual ( zone . type , '<STR_LIT>' ) <EOL> self . assertEqual ( zone . domain , '<STR_LIT>' ) <EOL> def test_get_record ( self ) : <EOL> record = self . driver . get_record ( zone_id = '<STR_LIT>' , <EOL> record_id = '<STR_LIT>' ) <EOL> self . assertEqual ( record . name , '<STR_LIT>' ) <EOL> self . assertEqual ( record . type , RecordType . CNAME ) <EOL> self . assertEqual ( record . data , '<STR_LIT>' ) <EOL> def test_list_records_zone_does_not_exist ( self ) : <EOL> zone = self . driver . list_zones ( ) [ <NUM_LIT:0> ] <EOL> Route53MockHttp . type = '<STR_LIT>' <EOL> try : <EOL> self . driver . list_records ( zone = zone ) <EOL> except ZoneDoesNotExistError : <EOL> e = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> self . assertEqual ( e . zone_id , zone . id ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def test_get_zone_does_not_exist ( self ) : <EOL> Route53MockHttp . type = '<STR_LIT>' <EOL> try : <EOL> self . driver . get_zone ( zone_id = '<STR_LIT>' ) <EOL> except ZoneDoesNotExistError : <EOL> e = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> self . assertEqual ( e . zone_id , '<STR_LIT>' ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def test_get_record_zone_does_not_exist ( self ) : <EOL> Route53MockHttp . type = '<STR_LIT>' <EOL> try : <EOL> self . driver . get_record ( zone_id = '<STR_LIT>' , record_id = '<STR_LIT>' ) <EOL> except ZoneDoesNotExistError : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def test_get_record_record_does_not_exist ( self ) : <EOL> Route53MockHttp . type = '<STR_LIT>' <EOL> rid = '<STR_LIT>' <EOL> try : <EOL> self . driver . get_record ( zone_id = '<STR_LIT>' , <EOL> record_id = rid ) <EOL> except RecordDoesNotExistError : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def test_create_zone ( self ) : <EOL> zone = self . driver . create_zone ( domain = '<STR_LIT>' , type = '<STR_LIT>' , <EOL> ttl = None , extra = None ) <EOL> self . assertEqual ( zone . id , '<STR_LIT>' ) <EOL> self . assertEqual ( zone . domain , '<STR_LIT>' ) <EOL> def test_create_record ( self ) : <EOL> zone = self . driver . list_zones ( ) [ <NUM_LIT:0> ] <EOL> record = self . driver . create_record ( <EOL> name = '<STR_LIT>' , zone = zone , <EOL> type = RecordType . A , data = '<STR_LIT:127.0.0.1>' , <EOL> extra = { '<STR_LIT>' : <NUM_LIT:0> } <EOL> ) <EOL> self . assertEqual ( record . id , '<STR_LIT>' ) <EOL> self . assertEqual ( record . name , '<STR_LIT>' ) <EOL> self . assertEqual ( record . zone , zone ) <EOL> self . assertEqual ( record . type , RecordType . A ) <EOL> self . assertEqual ( record . data , '<STR_LIT:127.0.0.1>' ) <EOL> def test_create_record_zone_name ( self ) : <EOL> zone = self . driver . list_zones ( ) [ <NUM_LIT:0> ] <EOL> record = self . driver . create_record ( <EOL> name = '<STR_LIT>' , zone = zone , <EOL> type = RecordType . A , data = '<STR_LIT:127.0.0.1>' , <EOL> extra = { '<STR_LIT>' : <NUM_LIT:0> } <EOL> ) <EOL> self . assertEqual ( record . id , '<STR_LIT>' ) <EOL> self . assertEqual ( record . name , '<STR_LIT>' ) <EOL> self . assertEqual ( record . zone , zone ) <EOL> self . assertEqual ( record . type , RecordType . A ) <EOL> self . assertEqual ( record . data , '<STR_LIT:127.0.0.1>' ) <EOL> def test_create_multi_value_record ( self ) : <EOL> zone = self . driver . list_zones ( ) [ <NUM_LIT:0> ] <EOL> records = self . driver . ex_create_multi_value_record ( <EOL> name = '<STR_LIT>' , zone = zone , <EOL> type = RecordType . A , data = '<STR_LIT>' , <EOL> extra = { '<STR_LIT>' : <NUM_LIT:0> } <EOL> ) <EOL> self . assertEqual ( len ( records ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( records [ <NUM_LIT:0> ] . id , '<STR_LIT>' ) <EOL> self . assertEqual ( records [ <NUM_LIT:1> ] . id , '<STR_LIT>' ) <EOL> self . assertEqual ( records [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( records [ <NUM_LIT:1> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( records [ <NUM_LIT:0> ] . zone , zone ) <EOL> self . assertEqual ( records [ <NUM_LIT:1> ] . zone , zone ) <EOL> self . assertEqual ( records [ <NUM_LIT:0> ] . type , RecordType . A ) <EOL> self . assertEqual ( records [ <NUM_LIT:1> ] . type , RecordType . A ) <EOL> self . assertEqual ( records [ <NUM_LIT:0> ] . data , '<STR_LIT:127.0.0.1>' ) <EOL> self . assertEqual ( records [ <NUM_LIT:1> ] . data , '<STR_LIT>' ) <EOL> def test_update_record ( self ) : <EOL> zone = self . driver . list_zones ( ) [ <NUM_LIT:0> ] <EOL> record = self . driver . list_records ( zone = zone ) [ <NUM_LIT:1> ] <EOL> params = { <EOL> '<STR_LIT>' : record , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:type>' : RecordType . A , <EOL> '<STR_LIT:data>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:0> } } <EOL> updated_record = self . driver . update_record ( ** params ) <EOL> self . assertEqual ( record . data , '<STR_LIT>' ) <EOL> self . assertEqual ( updated_record . id , '<STR_LIT>' ) <EOL> self . assertEqual ( updated_record . name , '<STR_LIT>' ) <EOL> self . assertEqual ( updated_record . zone , record . zone ) <EOL> self . assertEqual ( updated_record . type , RecordType . A ) <EOL> self . assertEqual ( updated_record . data , '<STR_LIT>' ) <EOL> def test_delete_zone ( self ) : <EOL> zone = self . driver . list_zones ( ) [ <NUM_LIT:0> ] <EOL> status = self . driver . delete_zone ( zone = zone ) <EOL> self . assertTrue ( status ) <EOL> def test_delete_zone_does_not_exist ( self ) : <EOL> zone = self . driver . list_zones ( ) [ <NUM_LIT:0> ] <EOL> Route53MockHttp . type = '<STR_LIT>' <EOL> try : <EOL> self . driver . delete_zone ( zone = zone ) <EOL> except ZoneDoesNotExistError : <EOL> e = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> self . assertEqual ( e . zone_id , zone . id ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def test_delete_record ( self ) : <EOL> zone = self . driver . list_zones ( ) [ <NUM_LIT:0> ] <EOL> record = self . driver . list_records ( zone = zone ) [ <NUM_LIT:0> ] <EOL> status = self . driver . delete_record ( record = record ) <EOL> self . assertTrue ( status ) <EOL> def test_delete_record_does_not_exist ( self ) : <EOL> zone = self . driver . list_zones ( ) [ <NUM_LIT:0> ] <EOL> record = self . driver . list_records ( zone = zone ) [ <NUM_LIT:0> ] <EOL> Route53MockHttp . type = '<STR_LIT>' <EOL> try : <EOL> self . driver . delete_record ( record = record ) <EOL> except RecordDoesNotExistError : <EOL> e = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> self . assertEqual ( e . record_id , record . id ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> class Route53MockHttp ( MockHttp ) : <EOL> fixtures = DNSFileFixtures ( '<STR_LIT>' ) <EOL> def _2012_02_29_hostedzone_47234 ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _2012_02_29_hostedzone ( self , method , url , body , headers ) : <EOL> if method == "<STR_LIT:POST>" : <EOL> body = self . fixtures . load ( "<STR_LIT>" ) <EOL> return ( httplib . CREATED , body , { } , httplib . responses [ httplib . OK ] ) <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _2012_02_29_hostedzone_47234_rrset ( self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _2012_02_29_hostedzone_47234_rrset_ZONE_DOES_NOT_EXIST ( self , method , <EOL> url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . NOT_FOUND , body , <EOL> { } , httplib . responses [ httplib . NOT_FOUND ] ) <EOL> def _2012_02_29_hostedzone_4444_ZONE_DOES_NOT_EXIST ( self , method , <EOL> url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . NOT_FOUND , body , <EOL> { } , httplib . responses [ httplib . NOT_FOUND ] ) <EOL> def _2012_02_29_hostedzone_47234_ZONE_DOES_NOT_EXIST ( self , method , <EOL> url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . NOT_FOUND , body , <EOL> { } , httplib . responses [ httplib . NOT_FOUND ] ) <EOL> def _2012_02_29_hostedzone_47234_rrset_RECORD_DOES_NOT_EXIST ( self , method , <EOL> url , body , headers ) : <EOL> if method == "<STR_LIT:POST>" : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . BAD_REQUEST , body , { } , httplib . responses [ httplib . BAD_REQUEST ] ) <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _2012_02_29_hostedzone_47234_RECORD_DOES_NOT_EXIST ( self , method , <EOL> url , body , headers ) : <EOL> body = self . fixtures . load ( '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> sys . exit ( unittest . main ( ) ) </s>
