コード例 #1
0
    def test_assert_exact_structure_extra(self):
        with self.assertRaises(AssertionError) as error_info:
            assertions.assert_exact_structure(
                {
                    'user': {
                        'id': 12,
                        'name': AnyValue('str')
                    },
                    'parent': {
                        'id': AnyValue('int'),
                        'name': 'Roger'
                    }
                },
                {
                    'user': {
                        'id': 12,
                        'name': 'Seth'
                    },
                    'parent': {
                        'id': 79,
                        'name': 'Roger',
                        'age': 65
                    }
                },
            )

        self.assertIn('Extra values', error_info.exception.args[0])
コード例 #2
0
 def test_assert_not_wanted_errors_array_empty(self):
     assertions.assert_actual_list_not_subset(
         [
             Error(code='INVALID',
                   message=AnyValue('str'),
                   field=AnyValue('str', permit_none=True))
         ],
         [],
     )
コード例 #3
0
 def test_assert_not_wanted_errors_mismatch_field(self):
     assertions.assert_actual_list_not_subset(
         [
             Error(code='FOO',
                   message=AnyValue('str'),
                   field=AnyValue('str', permit_none=True)),
             Error(code='BAR', message=AnyValue('str'), field='bar_field'),
         ],
         [
             Error(code='BAR', message='Bar message', field=None),
         ],
     )
コード例 #4
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),
         ],
     )
コード例 #5
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)),
             ],
             [],
         )
コード例 #6
0
 def test_assert_all_wanted_errors_mismatch_empty_list_other_way(self):
     with self.assertRaises(AssertionError):
         assertions.assert_lists_match_any_order(
             [],
             [
                 Error(code='FOO',
                       message=AnyValue('str'),
                       field=AnyValue('str', permit_none=True)),
                 Error(code='BAR',
                       message=AnyValue('str'),
                       field=AnyValue('str', permit_none=True)),
             ],
         )
コード例 #7
0
 def test_assert_not_wanted_errors_mismatch_list(self):
     assertions.assert_actual_list_not_subset(
         [
             Error(code='FOO',
                   message=AnyValue('str'),
                   field=AnyValue('str', permit_none=True)),  # type: ignore
             Error(code='BAR',
                   message=AnyValue('str'),
                   field=AnyValue('str', permit_none=True)),  # type: ignore
         ],
         [
             Error(code='BAZ', message='Baz message', field=None),
         ],
     )
コード例 #8
0
 def test_assert_all_wanted_errors_match_different_order(self):
     assertions.assert_lists_match_any_order(
         [
             Error(code='FOO',
                   message=AnyValue('str'),
                   field=AnyValue('str', permit_none=True)),
             Error(code='BAR',
                   message=AnyValue('str'),
                   field=AnyValue('str', permit_none=True)),
         ],
         [
             Error(code='BAR', message='Bar message', field=None),
             Error(code='FOO', message='Foo message', field='foo_field'),
         ],
     )
コード例 #9
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),
             ],
         )
コード例 #10
0
 def test_assert_not_wanted_errors_match_list_with_field(self):
     with self.assertRaises(AssertionError):
         assertions.assert_actual_list_not_subset(
             [
                 Error(code='FOO',
                       message=AnyValue('str'),
                       field=AnyValue('str', permit_none=True)),
                 Error(code='BAR',
                       message=AnyValue('str'),
                       field=AnyValue('str', permit_none=True)),
             ],
             [
                 Error(code='FOO', message='Foo message',
                       field='foo_field'),
             ],
         )
コード例 #11
0
 def test_assert_all_wanted_errors_mismatch_missing_error(self):
     with self.assertRaises(AssertionError):
         assertions.assert_lists_match_any_order(
             [
                 Error(code='FOO',
                       message=AnyValue('str'),
                       field=AnyValue('str',
                                      permit_none=True)),  # type: ignore
                 Error(code='BAR',
                       message=AnyValue('str'),
                       field=AnyValue('str',
                                      permit_none=True)),  # type: ignore
             ],
             [
                 Error(code='BAR', message='Bar message', field=None),
             ],
         )
コード例 #12
0
 def test_assert_not_present_not_present_sub_structure(self):
     assertions.assert_not_present(
         {'user': {
             'foo': AnyValue('str')
         }},
         {'user': {
             'bar': 42
         }},
     )
コード例 #13
0
 def test_assert_not_present_but_present(self):
     with self.assertRaises(AssertionError):
         assertions.assert_not_present(
             {'foo': AnyValue('str')},
             {
                 'foo': 'Hello',
                 'bar': 42
             },
         )
コード例 #14
0
 def test_assert_exact_structure_match(self):
     assertions.assert_exact_structure(
         {
             'user': {
                 'id': 12,
                 'name': AnyValue('str')
             },
             'parent': {
                 'id': AnyValue('int'),
                 'name': 'Roger'
             }
         },
         {
             'user': {
                 'id': 12,
                 'name': 'Seth'
             },
             'parent': {
                 'id': 79,
                 'name': 'Roger'
             }
         },
     )
コード例 #15
0
    def ingest_from_parsed_test_fixture(self, action_case, test_case,
                                        parse_results, file_name, line_number):
        path = 'expects_{not_q}{job_q}{exact_q}error'.format(
            not_q='not_' if getattr(parse_results, 'not', None) else '',
            job_q='job_' if parse_results.job else '',
            exact_q='exact_' if parse_results.exact else '',
        )

        try:
            errors = path_get(action_case, path)
        except (KeyError, IndexError):
            errors = []
            path_put(action_case, path, errors)

        errors.append(
            Error(
                code=parse_results.error_code,
                message=getattr(parse_results, 'error_message', None)
                or AnyValue('str'),
                field=getattr(parse_results, 'field_name', None)
                or AnyValue('str', permit_none=True),
                traceback=AnyValue('str', permit_none=True),
                variables=AnyValue('list', permit_none=True),
            ))
コード例 #16
0
 def test_assert_exact_structure_list_mismatch(self):
     with self.assertRaises(AssertionError):
         assertions.assert_exact_structure(
             {
                 'user': {
                     'id': 12,
                     'name': AnyValue('str')
                 },
                 'parents': [79, 86]
             },
             {
                 'user': {
                     'id': 12,
                     'name': 'Seth'
                 },
                 'parents': [79, 86, 51]
             },
         )
コード例 #17
0
    def ingest_from_parsed_test_fixture(self, action_case, test_case, parse_results, file_name, line_number):
        path = 'expects_{not_q}{job_q}{exact_q}error'.format(
            not_q='not_' if getattr(parse_results, 'not', None) else '',
            job_q='job_' if parse_results.job else '',
            exact_q='exact_' if parse_results.exact else '',
        )

        try:
            errors = path_get(action_case, path)
        except (KeyError, IndexError):
            errors = []
            path_put(action_case, path, errors)

        # noinspection PyTypeChecker
        errors.append(Error(  # type: ignore
            code=parse_results.error_code,
            message=getattr(parse_results, 'error_message', None) or AnyValue('str'),  # type: ignore
            field=getattr(parse_results, 'field_name', None) or AnyValue('str', permit_none=True),  # type: ignore
            traceback=AnyValue('str', permit_none=True),  # type: ignore
            variables=AnyValue('dict', permit_none=True),  # type: ignore
            denied_permissions=AnyValue('list', permit_none=True),  # type: ignore
            is_caller_error=AnyValue('bool'),  # type: ignore
        ))
コード例 #18
0
 def test_assert_not_present_not_present(self):
     assertions.assert_not_present(
         {'foo': AnyValue('str')},
         {'bar': 42},
     )