def test_prepare_configuration_with_incorrect_http_method(self): unknown_http_method = 'unknown' with self.assertRaises(ImproperlyConfigured) as cm: prepare_configuration([('a', 200, unknown_http_method)]) raised_exception = cm.exception exception_msg = str(raised_exception) self.assertIn(UNKNOWN_HTTP_METHOD_MSG % unknown_http_method, 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_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)
def test_prepare_configuration_with_all_http_methods(self): config = [] for http_method in HTTP_METHODS: config.append(('url', 200, http_method, {})) prepared_config = prepare_configuration(config) self.assertEqual(config, prepared_config)
def test_prepare_configuration(self): test = prepare_configuration([('a', 200, 'GET'), ('b', 200, 'GET')]) self.assertIsNotNone(test) self.assertEqual( test, [('a', 200, 'GET', {}), ('b', 200, 'GET', {})])