From 126fee0fc102accbe4055b42a9e46d70d9c6474f Mon Sep 17 00:00:00 2001 From: BuriedInCode <6057651+Buried-In-Code@users.noreply.github.com> Date: Wed, 2 Oct 2024 15:34:11 +1300 Subject: [PATCH] Fix testing --- esak/schemas/__init__.py | 36 +++++++++++++++++++++++++++++++++++- esak/schemas/base.py | 31 +++---------------------------- esak/schemas/comic.py | 3 ++- esak/schemas/generic.py | 2 +- esak/schemas/urls.py | 2 +- tox.ini | 2 +- 6 files changed, 43 insertions(+), 33 deletions(-) diff --git a/esak/schemas/__init__.py b/esak/schemas/__init__.py index d6cfe85..3fc139d 100644 --- a/esak/schemas/__init__.py +++ b/esak/schemas/__init__.py @@ -1 +1,35 @@ -"""esak.schemas package entry file.""" +"""esak.schemas package entry file. + +This module provides the following classes: + +- BaseModel +""" + +__all__ = ["BaseModel"] + +from pydantic import BaseModel as PydanticModel + + +def to_camel_case(value: str) -> str: + """Convert attribute name to camelCase. + + Args: + value: Attribute name + + Returns: + Value converted to camelCase + """ + temp = value.replace("_", " ").title().replace(" ", "") + return temp[0].lower() + temp[1:] + + +class BaseModel( + PydanticModel, + alias_generator=to_camel_case, + populate_by_name=True, + str_strip_whitespace=True, + validate_assignment=True, + revalidate_instances="always", + extra="ignore", +): + """Base model for esak resources.""" diff --git a/esak/schemas/base.py b/esak/schemas/base.py index 512dd3b..9a33401 100644 --- a/esak/schemas/base.py +++ b/esak/schemas/base.py @@ -2,44 +2,19 @@ This module provides the following classes: -- BaseModel - BaseResource """ -__all__ = ["BaseResource", "BaseModel"] +__all__ = ["BaseResource"] from datetime import datetime -from pydantic import BaseModel as PydanticModel, Field, HttpUrl, field_validator +from pydantic import Field, HttpUrl, field_validator +from esak.schemas import BaseModel from esak.schemas.urls import Urls -def to_camel_case(value: str) -> str: - """Convert attribute name to camelCase. - - Args: - value: Attribute name - - Returns: - Value converted to camelCase - """ - temp = value.replace("_", " ").title().replace(" ", "") - return temp[0].lower() + temp[1:] - - -class BaseModel( - PydanticModel, - alias_generator=to_camel_case, - populate_by_name=True, - str_strip_whitespace=True, - validate_assignment=True, - revalidate_instances="always", - extra="ignore", -): - """Base model for esak resources.""" - - class BaseResource(BaseModel): r"""Base resource for esak resources. diff --git a/esak/schemas/comic.py b/esak/schemas/comic.py index f5f2c1a..2594c44 100644 --- a/esak/schemas/comic.py +++ b/esak/schemas/comic.py @@ -11,7 +11,8 @@ from pydantic import ConfigDict, Field, HttpUrl, field_validator -from esak.schemas.base import BaseModel, BaseResource +from esak.schemas import BaseModel +from esak.schemas.base import BaseResource from esak.schemas.generic import GenericCreator, GenericItem, GenericStory diff --git a/esak/schemas/generic.py b/esak/schemas/generic.py index 3369e35..bfc241d 100644 --- a/esak/schemas/generic.py +++ b/esak/schemas/generic.py @@ -11,7 +11,7 @@ from pydantic import Field, HttpUrl -from esak.schemas.base import BaseModel +from esak.schemas import BaseModel class GenericItem(BaseModel): diff --git a/esak/schemas/urls.py b/esak/schemas/urls.py index b58c732..35a202c 100644 --- a/esak/schemas/urls.py +++ b/esak/schemas/urls.py @@ -10,7 +10,7 @@ from pydantic import HttpUrl -from esak.schemas.base import BaseModel +from esak.schemas import BaseModel class Urls(BaseModel): diff --git a/tox.ini b/tox.ini index 52c9c6c..fb81d46 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ envlist = py3{10,11,12} min_version = 4.0 [testenv] -whitelist_externals = poetry +allowlist_externals = poetry commands = poetry install -v poetry run pytest tests/