示例#1
0
 def test_assert_any_wanted_error_match_with_field(self):
     assertions.assert_expected_list_subset_of_actual(
         [
             Error(code='FOO',
                   message=AnyValue('str'),
                   field=AnyValue('str', permit_none=True)),
         ],
         [
             Error(code='FOO', message='Foo message', field='foo_field'),
             Error(code='BAR', message='Bar message', field=None),
         ],
     )
示例#2
0
 def test_assert_any_wanted_error_mismatch_empty_actual_list(self):
     with self.assertRaises(AssertionError):
         assertions.assert_expected_list_subset_of_actual(
             [
                 Error(code='FOO',
                       message=AnyValue('str'),
                       field=AnyValue('str', permit_none=True)),
                 Error(code='BAR',
                       message=AnyValue('str'),
                       field=AnyValue('str', permit_none=True)),
             ],
             [],
         )
示例#3
0
 def test_assert_any_wanted_error_mismatch_code(self):
     with self.assertRaises(AssertionError):
         assertions.assert_expected_list_subset_of_actual(
             [
                 Error(code='BAZ',
                       message=AnyValue('str'),
                       field=AnyValue('str',
                                      permit_none=True)),  # type: ignore
             ],
             [
                 Error(code='FOO', message='Foo message',
                       field='foo_field'),
                 Error(code='BAR', message='Bar Message', field=None),
             ],
         )
示例#4
0
    def assert_test_case_action_results(self,
                                        action_name,
                                        action_case,
                                        test_case,
                                        test_fixture,
                                        action_response,
                                        job_response,
                                        msg=None,
                                        **kwargs):
        for instruction, expected in six.iteritems(action_case):
            if instruction.startswith('expects_') and instruction.endswith(
                    '_error'):
                target = action_response
                if '_job_' in instruction:
                    target = job_response

                errors = target.errors if target else []

                try:
                    if '_not_' in instruction:
                        assert_actual_list_not_subset(
                            expected, errors,
                            'NOT EXPECTED ERRORS: {}'.format(msg or ''))
                    elif '_exact_' in instruction:
                        assert_lists_match_any_order(
                            expected, errors,
                            'EXPECTED EXACT ERRORS: {}'.format(msg or ''))
                    else:
                        assert_expected_list_subset_of_actual(
                            expected, errors,
                            'EXPECTED ERRORS: {}'.format(msg or ''))
                except AssertionError as e:
                    for error in errors:
                        if error.code == 'SERVER_ERROR':
                            raise type(e)(
                                '{message}\n\nSERVER_ERROR: {detail}'.format(
                                    message=e.args[0],
                                    detail=error.message,
                                ), )
                    raise