Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pytest failure: ValidationError #117

Closed
peterschutt opened this issue May 24, 2022 · 1 comment
Closed

Pytest failure: ValidationError #117

peterschutt opened this issue May 24, 2022 · 1 comment

Comments

@peterschutt
Copy link
Contributor

________________________________________________________ test_conversion_from_model_instance[VanillaDataClassPerson-exclude1-field_mapping1-plugins1] ________________________________________________________

model = <class 'tests.VanillaDataClassPerson'>, exclude = ['id'], field_mapping = {'complex': 'ultra'}, plugins = []

    @pytest.mark.parametrize(  # type: ignore[misc]
        "model, exclude, field_mapping, plugins",
        [
            [Person, ["id"], {"complex": "ultra"}, []],
            [VanillaDataClassPerson, ["id"], {"complex": "ultra"}, []],
            [Pet, ["age"], {"species": "kind"}, [SQLAlchemyPlugin()]],
        ],
    )
    def test_conversion_from_model_instance(model: Any, exclude: list, field_mapping: dict, plugins: list) -> None:
        DTO = DTOFactory(plugins=plugins)("MyDTO", model, exclude=exclude, field_mapping=field_mapping)
    
        if issubclass(model, (Person, VanillaDataClassPerson)):
            model_instance = model(
                first_name="moishe",
                last_name="zuchmir",
                id=1,
                optional="some-value",
                complex={"key": [{"key": "value"}]},
                pets=None,
            )
        else:
            model_instance = cast(Type[Pet], model)(  # type: ignore
                id=1,
                species=Species.MONKEY,
                name="Mike",
                age=3,
                owner_id=1,
            )
>       dto_instance = DTO.from_model_instance(model_instance=model_instance)

tests/test_dto_factory.py:180: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
starlite/dto.py:51: in from_model_instance
    return cls(**values)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   pydantic.error_wrappers.ValidationError: 1 validation error for MyDTO
E   pets
E     none is not an allowed value (type=type_error.none.not_allowed)

pydantic/main.py:331: ValidationError

Occurs after #116.

@peterschutt
Copy link
Contributor Author

Nvm, solved it in #115

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant