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

Using the capabilities of sqlmodel and pydantic to do data validation. #207

Merged
merged 8 commits into from
Jan 31, 2023

Conversation

clstaudt
Copy link
Contributor

@clstaudt clstaudt commented Jan 29, 2023

Demo code:

class TestClient:
    """Tests for the Client model."""

    def test_valid_instantiation(self):
        invoicing_contact = Contact(
            first_name="Sam",
            last_name="Lowry",
            email="sam.lowry@miniinf.gov",
            company="Ministry of Information",
        )
        client = Client.validate(
            dict(
                name="Ministry of Information",
                invoicing_contact=invoicing_contact,
            )
        )
        assert store_and_retrieve(client)

    def test_missing_name(self):
        """Test that a ValidationError is raised when the name is missing."""
        with pytest.raises(ValidationError):
            Client.validate(dict())

        try:
            client = Client.validate(dict())
        except ValidationError as ve:
            for error in ve.errors():
                field_name = error.get("loc")[0]
                error_message = error.get("msg")
                assert field_name == "name"

@clstaudt clstaudt self-assigned this Jan 29, 2023
@clstaudt clstaudt marked this pull request as draft January 29, 2023 12:35
@clstaudt clstaudt marked this pull request as ready for review January 30, 2023 09:01
@clstaudt clstaudt changed the title WIP: Using the capabilities of sqlmodel and pydantic to do data validation. Using the capabilities of sqlmodel and pydantic to do data validation. Jan 30, 2023
@clstaudt clstaudt linked an issue Jan 30, 2023 that may be closed by this pull request
@clstaudt clstaudt mentioned this pull request Jan 30, 2023
@vlad-ed-git vlad-ed-git merged commit f5f55cf into dev Jan 31, 2023
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

Successfully merging this pull request may close these issues.

Ui/Model: Add field validation / format methods
2 participants