Проблема Marshmallow ValidationError 'field_name'

У меня есть один вопрос относительно более новых версий Marhsmallow API. В нашем проекте мы сейчас используем Marshmallow версии 3.0.0b14; и у нас определены следующие тестовые функции (работают отлично):

      from marshmallow.exceptions import ValidationError
from hamcrest import assert_that, calling, has_properties, has_item, not_

def test_invalid_expiration(self):
        invalid_values = [None, True, False, 'foobar', 0]

        for value in invalid_values:
            body = {'expiration': value}
            assert_that(
                calling(self.schema.load).with_args(body),
                raises(ValidationError).matching(
                    has_properties(field_names=has_item('expiration'))
                ),
            )

def test_that_acces_type_offline_requires_a_client_id(self):
        body = {'access_type': 'offline'}

        assert_that(
            calling(self.schema.load).with_args(body),
            raises(ValidationError).matching(
                has_properties(field_names=has_item('_schema'))
            ),
        )

def test_that_the_access_type_is_online_when_using_a_refresh_token(self):
        body = {'refresh_token': 'foobar', 'client_id': 'x'}

        assert_that(calling(self.schema.load).with_args(body), not_(raises(Exception)))

        assert_that(
            calling(self.schema.load).with_args({'access_type': 'online', **body}),
            not_(raises(Exception)),
        )

        assert_that(
            calling(self.schema.load).with_args({'access_type': 'offline', **body}),
            raises(ValidationError).matching(
                has_properties(field_names=has_item('_schema'))
            ),
        )

def test_that_a_refresh_token_requires_a_client_id(self):
        body = {'refresh_token': 'the-token'}

        assert_that(
            calling(self.schema.load).with_args({'client_id': 'x', **body}),
            not_(raises(Exception)),
        )

        assert_that(
            calling(self.schema.load).with_args(body),
            raises(ValidationError).matching(
                has_properties(field_names=has_item('_schema'))
            ),
        )

Теперь мы пытаемся поднять версию Marshmallow, чтобы обновить ее до 3.10.0; однако в этой версии field_names от ValidationError был удален и заменен на (что всегда равно, если я прав).

Итак, мой вопрос заключается в следующем: как мы можем изменить/модифицировать тесты, размещенные выше, чтобы у нас не было ошибок при их выполнении. Это то, что я пробовал до сих пор:

      raises(ValidationError).matching(
                     has_properties(messages=has_item('expiration'))
                 ),


raises(ValidationError).matching(
                 has_properties(messages=has_item('_schema'))
             ),

Мы не подходили по новому field_name так как он всегда равен _schema; поэтому мы продолжали сопоставлять/прощупывать messagesполе; следующая проблема относится к проблеме, аналогичной тому, с чем мы сталкиваемся:

https://github.com/marshmallow-code/marshmallow/issues/1499

0 ответов

Другие вопросы по тегам