Ejemplo n.º 1
0
    def test_configuration_built_incorrectly2(self):
        data = {
            'request_data': {
                'param': 'value'
            },
            'url_kwargs': lambda _: None,

            # start unsupported data keys
            'unsupported_param1': 1,
            'unsupported_param2': 2,
            # end unsupported data keys
        }
        conf = (('url', 200, 'GET', data), )

        unsupported_keys = set(data.keys()) - \
                           set(NOT_REQUIRED_PARAM_TYPE_CHECK.keys())

        BrokenConfig = type(str('BrokenConfig'), (SmokeTestCase, ),
                            {'TESTS_CONFIGURATION': conf})
        self.assertFalse(
            self.check_if_class_contains_test_methods(BrokenConfig),
            'TestCase contains generated test method but should not '
            '(test configuration is broken).')
        self.assertTrue(
            self.check_if_class_contains_fail_test_method(BrokenConfig),
            'Generated TestCase should contain one fake test method to inform '
            'that its configuration is broken.')

        self.assert_called_fail_test_method(
            BrokenConfig,
            UNSUPPORTED_CONFIGURATION_KEY_MSG % ', '.join(unsupported_keys))
Ejemplo n.º 2
0
 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.')
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    def test_configuration_built_incorrectly2(self):
        data = {
            'request_data': {'param': 'value'},
            'url_kwargs': lambda _: None,

            # start unsupported data keys
            'unsupported_param1': 1,
            'unsupported_param2': 2,
            # end unsupported data keys
        }
        conf = (
            ('url', 200, 'GET', data),
        )

        unsupported_keys = set(data.keys()) - \
                           set(NOT_REQUIRED_PARAM_TYPE_CHECK.keys())

        BrokenConfig = type(
            str('BrokenConfig'),
            (SmokeTestCase,),
            {'TESTS_CONFIGURATION': conf})
        self.assertFalse(
            self.check_if_class_contains_test_methods(BrokenConfig),
            'TestCase contains generated test method but should not '
            '(test configuration is broken).'
        )
        self.assertTrue(
            self.check_if_class_contains_fail_test_method(BrokenConfig),
            'Generated TestCase should contain one fake test method to inform '
            'that its configuration is broken.'
        )

        self.assert_called_fail_test_method(
            BrokenConfig,
            UNSUPPORTED_CONFIGURATION_KEY_MSG % ', '.join(unsupported_keys)
        )