<s> import sys <EOL> from libcloud . test import unittest <EOL> from libcloud . utils . py3 import httplib <EOL> from libcloud . dns . types import RecordDoesNotExistError <EOL> from libcloud . dns . types import RecordType <EOL> from libcloud . dns . types import ZoneDoesNotExistError <EOL> from libcloud . dns . drivers . softlayer import SoftLayerDNSDriver <EOL> from libcloud . test import MockHttp <EOL> from libcloud . test . file_fixtures import DNSFileFixtures <EOL> from libcloud . test . secrets import SOFTLAYER_PARAMS <EOL> from libcloud . utils . py3 import xmlrpclib <EOL> class SoftLayerTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> SoftLayerDNSDriver . connectionCls . conn_classes = ( <EOL> SoftLayerDNSMockHttp , SoftLayerDNSMockHttp ) <EOL> SoftLayerDNSMockHttp . type = None <EOL> self . driver = SoftLayerDNSDriver ( * SOFTLAYER_PARAMS ) <EOL> def test_create_zone ( self ) : <EOL> zone = self . driver . create_zone ( domain = '<STR_LIT>' ) <EOL> self . assertEqual ( zone . id , '<STR_LIT>' ) <EOL> self . assertEqual ( zone . domain , '<STR_LIT>' ) <EOL> def test_list_zones ( self ) : <EOL> zones = self . driver . list_zones ( ) <EOL> self . assertEqual ( len ( zones ) , <NUM_LIT:1> ) <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_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_zone_does_not_exist ( self ) : <EOL> SoftLayerDNSMockHttp . type = '<STR_LIT>' <EOL> with self . assertRaises ( ZoneDoesNotExistError ) : <EOL> self . driver . get_zone ( zone_id = '<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> SoftLayerDNSMockHttp . type = '<STR_LIT>' <EOL> with self . assertRaises ( ZoneDoesNotExistError ) : <EOL> self . driver . delete_zone ( zone = zone ) <EOL> def test_list_records ( self ) : <EOL> zone = self . driver . list_zones ( ) [ <NUM_LIT:0> ] <EOL> records = zone . list_records ( ) <EOL> self . assertEqual ( records [ <NUM_LIT:0> ] . id , '<STR_LIT>' ) <EOL> self . assertEqual ( records [ <NUM_LIT:0> ] . type , RecordType . SOA ) <EOL> self . assertEqual ( records [ <NUM_LIT:0> ] . data , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> records [ <NUM_LIT:0> ] . extra , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> <EOL> } <EOL> ) <EOL> self . assertEqual ( records [ <NUM_LIT:1> ] . id , '<STR_LIT>' ) <EOL> self . assertEqual ( records [ <NUM_LIT:1> ] . type , RecordType . NS ) <EOL> self . assertEqual ( records [ <NUM_LIT:1> ] . data , '<STR_LIT>' ) <EOL> self . assertEqual ( records [ <NUM_LIT:2> ] . id , '<STR_LIT>' ) <EOL> self . assertEqual ( records [ <NUM_LIT:2> ] . type , RecordType . NS ) <EOL> self . assertEqual ( records [ <NUM_LIT:2> ] . data , '<STR_LIT>' ) <EOL> self . assertEqual ( records [ <NUM_LIT:3> ] . id , '<STR_LIT>' ) <EOL> self . assertEqual ( records [ <NUM_LIT:3> ] . type , RecordType . A ) <EOL> self . assertEqual ( records [ <NUM_LIT:3> ] . data , '<STR_LIT:127.0.0.1>' ) <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_get_record ( self ) : <EOL> record = self . driver . get_record ( zone_id = '<STR_LIT>' , record_id = '<STR_LIT>' ) <EOL> self . assertEqual ( record . id , '<STR_LIT>' ) <EOL> self . assertEqual ( record . type , RecordType . SOA ) <EOL> self . assertEqual ( record . data , '<STR_LIT>' ) <EOL> def test_get_record_record_does_not_exist ( self ) : <EOL> SoftLayerDNSMockHttp . type = '<STR_LIT>' <EOL> with self . assertRaises ( RecordDoesNotExistError ) : <EOL> self . driver . get_record ( zone_id = '<STR_LIT>' , <EOL> record_id = '<STR_LIT:1>' ) <EOL> def test_delete_record ( self ) : <EOL> record = self . driver . get_record ( zone_id = '<STR_LIT>' , record_id = '<STR_LIT>' ) <EOL> status = self . driver . delete_record ( record = record ) <EOL> self . assertTrue ( status ) <EOL> def test_delete_record_does_not_exist ( self ) : <EOL> record = self . driver . get_record ( zone_id = '<STR_LIT>' , record_id = '<STR_LIT>' ) <EOL> SoftLayerDNSMockHttp . type = '<STR_LIT>' <EOL> with self . assertRaises ( RecordDoesNotExistError ) : <EOL> self . driver . delete_record ( record = record ) <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:30> } <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_update_record ( self ) : <EOL> zone = self . driver . list_zones ( ) [ <NUM_LIT:0> ] <EOL> record = self . driver . list_records ( zone = zone ) [ <NUM_LIT:1> ] <EOL> SoftLayerDNSMockHttp . type = '<STR_LIT>' <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:30> } } <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> class SoftLayerDNSMockHttp ( MockHttp ) : <EOL> fixtures = DNSFileFixtures ( '<STR_LIT>' ) <EOL> def _get_method_name ( self , type , use_param , qs , path ) : <EOL> return "<STR_LIT>" <EOL> def _xmlrpc ( self , method , url , body , headers ) : <EOL> params , meth_name = xmlrpclib . loads ( body ) <EOL> url = url . replace ( "<STR_LIT:/>" , "<STR_LIT:_>" ) <EOL> meth_name = "<STR_LIT>" % ( url , meth_name ) <EOL> return getattr ( self , meth_name ) ( method , url , body , headers ) <EOL> def _xmlrpc_v3_SoftLayer_Dns_Domain_createObject ( <EOL> self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( <EOL> '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc_v3_SoftLayer_Dns_Domain_getByDomainName ( <EOL> self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( <EOL> '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc_v3_SoftLayer_Dns_Domain_getObject ( <EOL> self , method , url , body , headers ) : <EOL> fixture = { <EOL> None : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } [ self . type ] <EOL> body = self . fixtures . load ( fixture ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc_v3_SoftLayer_Dns_Domain_deleteObject ( <EOL> self , method , url , body , headers ) : <EOL> fixture = { <EOL> None : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } [ self . type ] <EOL> body = self . fixtures . load ( fixture ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc_v3_SoftLayer_Dns_Domain_getResourceRecords ( <EOL> self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( <EOL> '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc_v3_SoftLayer_Dns_Domain_ResourceRecord_getObject ( <EOL> self , method , url , body , headers ) : <EOL> fixture = { <EOL> None : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } [ self . type ] <EOL> body = self . fixtures . load ( fixture ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc_v3_SoftLayer_Dns_Domain_ResourceRecord_deleteObject ( <EOL> self , method , url , body , headers ) : <EOL> fixture = { <EOL> None : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } [ self . type ] <EOL> body = self . fixtures . load ( fixture ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc_v3_SoftLayer_Dns_Domain_ResourceRecord_createObject ( <EOL> self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( <EOL> '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> def _xmlrpc_v3_SoftLayer_Dns_Domain_ResourceRecord_editObject ( <EOL> self , method , url , body , headers ) : <EOL> body = self . fixtures . load ( <EOL> '<STR_LIT>' ) <EOL> return ( httplib . OK , body , { } , httplib . responses [ httplib . OK ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> sys . exit ( unittest . main ( ) ) </s>
