def test_add_credentials_for_unsecure_authentication(self): """check username and key are really added to options""" config = load_config_file(self.root_path+'/domaintools/conf/api.ini') configuration = Configuration(config) configuration.secure_auth = False request = Request(configuration) request.add_credentials_options() options = request.get_options() self.assertTrue(config['username']==options['api_username'] and config['key']==options['api_key'])
def test_add_credentials_for_unsecure_authentication(self): """check username and key are really added to options""" config = load_config_file(self.root_path + '/domaintools/conf/api.ini') configuration = Configuration(config) configuration.secure_auth = False request = Request(configuration) request.add_credentials_options() options = request.get_options() self.assertTrue(config['username'] == options['api_username'] and config['key'] == options['api_key'])
def __init__(self, configuration=None): """ Construction of the class with an optional given configuration object (If no configuration given, the default one is taken) """ "Configuration (credentials, host,...)" self.configuration = None #Name of the service to call self.service_name = '' #Type of the return self.return_type = None #Authorized return types self.authorized_return_types = ('json', 'xml', 'html') #Url of the resource to call self.url = None #Dictionary of options self.options = {} #Name of the domain to use self.domain_name = '' #The raw response sent by domaintoolsAPI self.raw_response = None #The proxy url self.proxy = None self.configuration = Configuration() if(configuration == None) else configuration
def test_default_config_called_if_none_given(self): default_config_path = os.path.realpath( os.path.dirname(__file__) + '/../domaintools/conf/api.ini') configuration = Configuration() self.assertTrue( default_config_path == configuration.default_config_path)
def test_default_transport_called_if_invalid_given(self): configuration = Configuration({ 'username': '******', 'key': 'password', 'transport_type': 'fake' }) default_config = configuration.default_config self.assertTrue( default_config['transport_type'] == configuration.transport_type)
def setUp(self): """to execute before each test""" self.root_path = os.path.realpath(os.curdir) self.configuration = Configuration(self.root_path + '/domaintools/conf/api.ini') self.request = Request(self.configuration) self.request.domain('domaintools.com') transport = Mock('RestService') transport.get_status.mock_returns = 200 transport.get.mock_returns = open( self.root_path + '/tests/fixtures/domain-profile/domaintools.com/good.json').read() self.request.set_transport(transport) self.response = self.request.execute()
def test_transport_called_on_get(self): """test transport is really called""" configuration = Configuration(self.root_path + "/domaintools/conf/api.ini") request = Request(configuration) request.withType('json').domain('domaintools.com') transport = Mock('RestService') transport.get_status.mock_returns = 200 transport.get.mock_returns = open( self.root_path + '/tests/fixtures/domain-profile/domaintools.com/good.json').read() request.set_transport(transport) try: request.execute() except Exception as e: pass self.assertTrue(transport.get_status() == 200)
def test_service_exception_if_empty_key(self): try: configuration = Configuration({'username': '******', 'key': ''}) except ServiceException as e: self.assertTrue(True)
def test_merge_with_default_confguration(self): config = {"username": "******", "key": "password"} configuration = Configuration(config) self.assertTrue(configuration.username == config['username'] and configuration.password == config['key'])
def test_service_exception_if_config_file_do_not_exists(self): try: configuration = Configuration('invalid_path') except Exception as e: self.assertTrue(True)