Exemplo n.º 1
0
class TestCaseSkipDirective(Directive):
    """
    Use this directive to skip a test or, with ``global``, to skip all tests in the entire fixture
    """

    @classmethod
    def name(cls):
        return 'test_skip'

    @classmethod
    def get_full_grammar(cls):
        return (
            Literal('test skip') +
            Optional(Literal('global')('is_global').setParseAction(lambda s, l, t: t[0] == 'global')) +
            ':' +
            restOfLine()('reason')
        )

    def ingest_from_parsed_test_fixture(self, action_case, test_case, parse_results, file_name, line_number):
        path_put(test_case, 'skip', parse_results.reason.strip(' \t'))

    def assert_test_case_action_results(*args, **kwargs):
        pass


register_directive(TestCaseCommentDirective)
register_directive(TestCaseNameDirective)
register_directive(TestCaseDescriptionDirective)
register_directive(TestCaseSkipDirective)
Exemplo n.º 2
0
                                        parse_results, file_name, line_number):
        _ingest_expect_called(action_case, parse_results, file_name,
                              line_number)

    def set_up_test_case_action(self, action_name, action_case, test_case,
                                test_fixture, **kwargs):
        _start_stubbed_actions(action_case)

    def tear_down_test_case_action(self, action_name, action_case, test_case,
                                   test_fixture, **kwargs):
        _stop_stubbed_actions(action_case)

    def assert_test_case_action_results(self,
                                        action_name,
                                        action_case,
                                        test_case,
                                        test_fixture,
                                        action_response,
                                        job_response,
                                        msg=None,
                                        **kwargs):
        _assert_stub_expectations(action_case)


register_directive(StubActionBodyForTestPlanDirective)
register_directive(StubActionBodyForActionDirective)
register_directive(StubActionErrorForTestPlanDirective)
register_directive(StubActionErrorForActionDirective)
register_directive(AssertStubActionCalledForTestPlanDirective)
register_directive(AssertStubActionCalledForActionDirective)
    If ``exact`` is used, then all of the errors you define must match all of the errors in your response, and your
    response cannot have any non-matching extra errors. ``exact`` and non-``exact`` are mutually-exclusive
    expectations: an action case that has a mixture of ``exact`` and non-``exact`` error expectations will fail. For
    each error case, you must use one or the other.

    If ``job`` is used, then the job response will be examined for the error instead of the action response.
    """

    @classmethod
    def name(cls):
        return 'expect_error_field_message'

    @classmethod
    def get_full_grammar(cls):
        return (
            super(ActionExpectsFieldMessageErrorsDirective, cls).get_full_grammar() +
            ',' +
            Literal('message') +
            '=' +
            restOfLine('error_message').setParseAction(lambda s, l, t: t[0].strip(' \t'))
        )


# This order is very important; do not disturb
register_directive(ActionExpectsFieldMessageErrorsDirective)
register_directive(ActionExpectsMessageErrorsDirective)
register_directive(ActionExpectsFieldErrorsDirective)
register_directive(ActionExpectsErrorsDirective)
register_directive(ActionExpectsNoErrorsDirective)
Exemplo n.º 4
0
    def tear_down_test_case_action(self, action_name, action_case, test_case, test_fixture, **kwargs):
        if 'mock_patches' in action_case:
            for mock_target, config in six.iteritems(action_case['mock_patches']):
                if 'magic_mock' in config:  # means the patch was started
                    # noinspection PyBroadException
                    try:
                        config['patcher'].stop()
                    except Exception:
                        sys.stderr.write('WARNING: Failed to stop patcher for {} due to error:\n'.format(mock_target))
                        sys.stderr.write('{}\n'.format(traceback.format_exc()))

    def assert_test_case_action_results(
        self,
        action_name,
        action_case,
        test_case,
        test_fixture,
        action_response,
        job_response,
        msg=None,
        **kwargs
    ):
        _assert_mock_expectations(action_case)


register_directive(MockAssertCalledTestPlanDirective)
register_directive(MockAssertCalledActionDirective)
register_directive(MockPathResultForTestPlanDirective)
register_directive(MockPathResultForActionDirective)
Exemplo n.º 5
0
            Optional(Literal('job') + oneOf(('control', 'context'))('job_slot')) +
            Literal('input') +
            Optional(DataTypeGrammar) +
            ':' +
            VarNameGrammar +
            ':' +
            VarValueGrammar
        )

    def ingest_from_parsed_test_fixture(self, action_case, test_case, parse_results, file_name, line_number):
        parsed_data_type_value = get_parsed_data_type_value(parse_results, parse_results.value)

        path = 'inputs'
        if parse_results.job_slot == 'control':
            path = 'job_control_' + path

        if parse_results.job_slot == 'context':
            path = 'job_context_' + path

        path_put(
            action_case,
            '{}.{}'.format(path, parse_results.variable_name),
            parsed_data_type_value,
        )

    def assert_test_case_action_results(*args, **kwargs):
        pass


register_directive(ActionInputDirective)
Exemplo n.º 6
0
        return 'freeze_time_action'

    @classmethod
    def get_full_grammar(cls):
        return (super(FreezeTimeActionDirective, cls).get_full_grammar() +
                Literal('freeze time') + ':' + VarValueGrammar)

    def ingest_from_parsed_test_fixture(self, action_case, test_case,
                                        parse_results, file_name, line_number):
        self.parse_and_store_freeze_to(action_case, parse_results.value,
                                       file_name, line_number)
        self.start_freeze(action_case)

    def post_parse_test_case_action(self, action_case, test_case):
        self.stop_freeze(action_case)

    def set_up_test_case_action(self, action_name, action_case, test_case,
                                test_fixture, **kwargs):
        self.start_freeze(action_case)

    def tear_down_test_case_action(self, action_name, action_case, test_case,
                                   test_fixture, **kwargs):
        self.stop_freeze(action_case)

    def assert_test_case_action_results(self, *args, **kwargs):
        pass


register_directive(FreezeTimeTestPlanDirective)
register_directive(FreezeTimeActionDirective)
Exemplo n.º 7
0
    def ingest_from_parsed_test_fixture(self, action_case, test_case, parse_results, file_name, line_number):
        path_put(
            action_case,
            'expects_not_present.{}'.format(parse_results.variable_name),
            get_parsed_data_type_value(parse_results, parse_results.value),
        )

    def assert_test_case_action_results(
        self,
        action_name,
        action_case,
        test_case,
        test_fixture,
        action_response,
        job_response,
        msg=None,
        **kwargs
    ):
        if 'expects_not_present' in action_case:
            assert_not_present(
                action_case['expects_not_present'],
                action_response.body,
                msg,
            )


register_directive(ActionExpectsFieldValueDirective)
register_directive(ActionExpectsAnyDirective)
register_directive(ActionExpectsNoneDirective)
register_directive(ActionExpectsNotPresentDirective)