def test_non_required_params_definition(self): for param_name, param_type in NOT_REQUIRED_PARAM_TYPE_CHECK.items(): self.assertIsInstance(param_name, string_types) self.assertIn('type', param_type) self.assertIsInstance(param_type['type'], string_types) self.assertIn('func', param_type) self.assertTrue(callable(param_type['func']), 'Non-required parameter type check func must be ' 'callable.')
def test_prepare_configuration_with_all_incorrect_parameters(self): incorrect_required_params = [ 100500, # url should be string_types 'incorrect', # status should be int 666 # method should be string_types ] incorrect_not_required_params = { 'redirect_to': 123, # should be string_types 'comment': 123, # should be string_types 'initialize': 'initialize', # should be callable 'url_args': 'url_args', # should be list or callable 'url_kwargs': 'url_kwargs', # should be dict or callable 'request_data': 'request_data', # should be dict or callable 'user_credentials': 'user' # should be dict or callable } with self.assertRaises(ImproperlyConfigured) as cm: prepare_configuration([ (incorrect_required_params[0], incorrect_required_params[1], incorrect_required_params[2], incorrect_not_required_params,) ]) raised_exception = cm.exception exception_msg = str(raised_exception) error_messages = [] counter = 0 for param_dict in REQUIRED_PARAMS: value = incorrect_required_params[counter] error_messages.append( INCORRECT_REQUIRED_PARAM_TYPE_MSG % ( param_dict['display_name'], counter, param_dict['expected_type'], type(value), value ) ) counter += 1 for param, type_info in NOT_REQUIRED_PARAM_TYPE_CHECK.items(): value = incorrect_not_required_params[param] actual_type = type(value) error_messages.append( INCORRECT_NOT_REQUIRED_PARAM_TYPE_MSG % ( param, type_info['type'], actual_type, value )) error_messages.append(LINK_TO_DOCUMENTATION) for error_message in error_messages: self.assertIn(error_message, exception_msg)
def test_prepare_configuration_with_all_incorrect_parameters(self): incorrect_required_params = [ 100500, # url should be string_types 'incorrect', # status should be int 666 # method should be string_types ] incorrect_not_required_params = { 'redirect_to': 123, # should be string_types 'comment': 123, # should be string_types 'initialize': 'initialize', # should be callable 'url_kwargs': 'url_kwargs', # should be dict or callable 'request_data': 'request_data', # should be dict or callable 'user_credentials': 'user' # should be dict or callable } with self.assertRaises(ImproperlyConfigured) as cm: prepare_configuration([ (incorrect_required_params[0], incorrect_required_params[1], incorrect_required_params[2], incorrect_not_required_params,) ]) raised_exception = cm.exception exception_msg = str(raised_exception) error_messages = [] counter = 0 for param_dict in REQUIRED_PARAMS: value = incorrect_required_params[counter] error_messages.append( INCORRECT_REQUIRED_PARAM_TYPE_MSG % ( param_dict['display_name'], counter, param_dict['expected_type'], type(value), value ) ) counter += 1 for param, type_info in NOT_REQUIRED_PARAM_TYPE_CHECK.items(): value = incorrect_not_required_params[param] actual_type = type(value) error_messages.append( INCORRECT_NOT_REQUIRED_PARAM_TYPE_MSG % ( param, type_info['type'], actual_type, value )) error_messages.append(LINK_TO_DOCUMENTATION) for error_message in error_messages: self.assertIn(error_message, exception_msg)