Skip to content

Commit

Permalink
fix imports order, set warnings=False on json that passes the dict, f…
Browse files Browse the repository at this point in the history
…ix unnecessary loop in one of the test
  • Loading branch information
collerek committed Feb 12, 2024
1 parent ead254c commit 217faae
Show file tree
Hide file tree
Showing 128 changed files with 137 additions and 292 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test_docs:
bash scripts/test_docs.sh -svv

test:
pytest
pytest -svv tests/

coverage:
pytest --cov=ormar --cov=tests --cov-fail-under=100 --cov-report=term-missing tests
Expand Down
4 changes: 1 addition & 3 deletions benchmarks/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
import ormar
import pytest
import pytest_asyncio

from tests.settings import create_config
from tests.lifespan import init_tests

from tests.settings import create_config

base_ormar_config = create_config()
nest_asyncio.apply()
Expand Down
4 changes: 1 addition & 3 deletions docs_src/fastapi/docs001.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import ormar
from fastapi import FastAPI

from tests.settings import create_config
from tests.lifespan import lifespan

from tests.settings import create_config

base_ormar_config = create_config()
app = FastAPI(lifespan=lifespan(base_ormar_config))
Expand Down
1 change: 1 addition & 0 deletions examples/fastapi_quick_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ async def lifespan(app: FastAPI):
if database_.is_connected:
await database_.disconnect()


app = FastAPI(lifespan=lifespan)
metadata = sqlalchemy.MetaData()
database = databases.Database("sqlite:///test.db")
Expand Down
4 changes: 2 additions & 2 deletions ormar/models/newbasemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ def model_dump( # type: ignore # noqa A003
exclude_unset=exclude_unset,
exclude_none=exclude_none,
round_trip=round_trip,
warnings=warnings,
warnings=False,
)

dict_instance = {
Expand Down Expand Up @@ -994,7 +994,7 @@ def model_dump_json( # type: ignore # noqa A003
exclude_primary_keys=exclude_primary_keys,
exclude_through_models=exclude_through_models,
)
return self.__pydantic_serializer__.to_json(data).decode()
return self.__pydantic_serializer__.to_json(data, warnings=False).decode()

@classmethod
@typing_extensions.deprecated(
Expand Down
2 changes: 1 addition & 1 deletion ormar/models/ormar_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(
self.pkname = None # type: ignore
self.metadata = metadata
self.database = database # type: ignore
self.engine = engine # type: ignore
self.engine = engine # type: ignore
self.tablename = tablename # type: ignore
self.orders_by = order_by or []
self.columns: List[sqlalchemy.Column] = []
Expand Down
6 changes: 3 additions & 3 deletions tests/lifespan.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from contextlib import asynccontextmanager
from typing import AsyncIterator

import pytest
import sqlalchemy

from contextlib import asynccontextmanager
from fastapi import FastAPI
from typing import AsyncIterator


def lifespan(config):
Expand Down
3 changes: 1 addition & 2 deletions tests/test_deferred/test_forward_cross_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import ormar
import pytest

from tests.settings import create_config
from tests.lifespan import init_tests

from tests.settings import create_config

base_ormar_config = create_config()

Expand Down
3 changes: 1 addition & 2 deletions tests/test_deferred/test_forward_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import sqlalchemy as sa
from ormar.exceptions import ModelError

from tests.settings import create_config
from tests.lifespan import init_tests

from tests.settings import create_config

base_ormar_config = create_config()

Expand Down
3 changes: 1 addition & 2 deletions tests/test_deferred/test_more_same_table_joins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import ormar
import pytest

from tests.settings import create_config
from tests.lifespan import init_tests

from tests.settings import create_config

base_ormar_config = create_config(force_rollback=True)

Expand Down
3 changes: 1 addition & 2 deletions tests/test_deferred/test_same_table_joins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import ormar
import pytest

from tests.settings import create_config
from tests.lifespan import init_tests

from tests.settings import create_config

base_ormar_config = create_config()

Expand Down
3 changes: 1 addition & 2 deletions tests/test_encryption/test_encrypted_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
from ormar import ModelDefinitionError, NoMatch
from ormar.fields.sqlalchemy_encrypted import EncryptedString

from tests.settings import create_config
from tests.lifespan import init_tests

from tests.settings import create_config

base_ormar_config = create_config()
default_fernet = dict(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from datetime import datetime
from typing import List, Optional, Union

import databases
import ormar as orm
import pydantic
import pytest
import sqlalchemy

from tests.settings import create_config
from tests.lifespan import init_tests
from tests.settings import create_config

base_ormar_config = create_config()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import ormar
import pytest

from tests.settings import create_config
from tests.lifespan import init_tests

from tests.settings import create_config

base_ormar_config = create_config()

Expand Down
2 changes: 1 addition & 1 deletion tests/test_exclude_include_dict/test_excludable_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import ormar
from ormar.models.excludable import ExcludableItems

from tests.settings import create_config
from tests.lifespan import init_tests
from tests.settings import create_config

base_ormar_config = create_config()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import random
import string

import databases
import ormar
import pydantic
import pytest
Expand All @@ -13,10 +12,9 @@
from ormar import post_save
from pydantic import ConfigDict, computed_field

from tests.lifespan import lifespan, init_tests
from tests.lifespan import init_tests, lifespan
from tests.settings import create_config


base_ormar_config = create_config()
app = FastAPI(lifespan=lifespan(base_ormar_config))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import ormar
import pytest

from tests.settings import create_config
from tests.lifespan import init_tests

from tests.settings import create_config

base_ormar_config = create_config()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import pydantic
import pytest

from tests.settings import create_config
from tests.lifespan import init_tests

from tests.settings import create_config

base_ormar_config = create_config()

Expand Down
3 changes: 1 addition & 2 deletions tests/test_exclude_include_dict/test_pydantic_dict_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import ormar
import pytest

from tests.settings import create_config
from tests.lifespan import init_tests

from tests.settings import create_config

base_ormar_config = create_config()

Expand Down
5 changes: 2 additions & 3 deletions tests/test_fastapi/test_binary_fields.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import base64
import uuid
from enum import Enum
from typing import List
from typing import List

import ormar
import pytest
from asgi_lifespan import LifespanManager
from fastapi import FastAPI
from httpx import AsyncClient

from tests.lifespan import init_tests, lifespan
from tests.settings import create_config
from tests.lifespan import lifespan, init_tests


headers = {"content-type": "application/json"}
base_ormar_config = create_config()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
from fastapi import FastAPI
from httpx import AsyncClient

from tests.lifespan import init_tests, lifespan
from tests.settings import create_config
from tests.lifespan import lifespan, init_tests


base_ormar_config = create_config()
app = FastAPI(lifespan=lifespan(base_ormar_config))
Expand Down
3 changes: 1 addition & 2 deletions tests/test_fastapi/test_enum_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import ormar

from tests.settings import create_config
from tests.lifespan import init_tests

from tests.settings import create_config

base_ormar_config = create_config()

Expand Down
6 changes: 3 additions & 3 deletions tests/test_fastapi/test_excludes_with_get_pydantic.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from typing import ForwardRef, Optional

import ormar
import pytest
from asgi_lifespan import LifespanManager
from fastapi import FastAPI
from httpx import AsyncClient
from typing import ForwardRef, Optional

from tests.lifespan import init_tests, lifespan
from tests.settings import create_config
from tests.lifespan import lifespan, init_tests


base_ormar_config = create_config()
app = FastAPI(lifespan=lifespan(base_ormar_config))
Expand Down
3 changes: 1 addition & 2 deletions tests/test_fastapi/test_excluding_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fastapi import FastAPI
from httpx import AsyncClient

from tests.lifespan import lifespan, init_tests
from tests.lifespan import init_tests, lifespan
from tests.settings import create_config

base_ormar_config = create_config()
Expand All @@ -31,7 +31,6 @@ class Item(ormar.Model):
create_test_database = init_tests(base_ormar_config)



@app.post("/items/", response_model=Item)
async def create_item(item: Item):
await item.save_related(follow=True, save_all=True)
Expand Down
3 changes: 1 addition & 2 deletions tests/test_fastapi/test_extra_ignore_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from httpx import AsyncClient
from ormar import Extra

from tests.lifespan import lifespan, init_tests
from tests.lifespan import init_tests, lifespan
from tests.settings import create_config

base_ormar_config = create_config()
Expand All @@ -22,7 +22,6 @@ class Item(ormar.Model):
create_test_database = init_tests(base_ormar_config)



@app.post("/item/", response_model=Item)
async def create_item(item: Item):
return await item.save()
Expand Down
4 changes: 1 addition & 3 deletions tests/test_fastapi/test_fastapi_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
from httpx import AsyncClient
from pydantic import Field

from tests.lifespan import lifespan, init_tests
from tests.lifespan import init_tests, lifespan
from tests.settings import create_config


base_ormar_config = create_config()
app = FastAPI(lifespan=lifespan(base_ormar_config))

Expand Down Expand Up @@ -49,7 +48,6 @@ class Item(ormar.Model):
create_test_database = init_tests(base_ormar_config)



@app.get("/items/", response_model=List[Item])
async def get_items():
items = await Item.objects.select_related("categories").all()
Expand Down
4 changes: 1 addition & 3 deletions tests/test_fastapi/test_fastapi_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from fastapi import FastAPI
from httpx import AsyncClient

from tests.lifespan import init_tests, lifespan
from tests.settings import create_config
from tests.lifespan import lifespan, init_tests


base_ormar_config = create_config()
app = FastAPI(lifespan=lifespan(base_ormar_config))
Expand All @@ -32,7 +31,6 @@ class Item(ormar.Model):
create_test_database = init_tests(base_ormar_config)



@app.post("/items/", response_model=Item)
async def create_item(item: Item):
return item
Expand Down
6 changes: 2 additions & 4 deletions tests/test_fastapi/test_inheritance_concrete_fastapi.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import datetime
from typing import List, Optional

import pytest
import ormar
import pytest
from asgi_lifespan import LifespanManager
from fastapi import FastAPI
from httpx import AsyncClient
from ormar.relations.relation_proxy import RelationProxy
from pydantic import computed_field

from tests.lifespan import lifespan, init_tests
from tests.lifespan import init_tests, lifespan
from tests.settings import create_config


base_ormar_config = create_config()
app = FastAPI(lifespan=lifespan(base_ormar_config))

Expand Down Expand Up @@ -137,7 +136,6 @@ class Truck2(Car2):
create_test_database = init_tests(base_ormar_config)



@app.post("/subjects/", response_model=Subject)
async def create_item(item: Subject):
return item
Expand Down
Loading

0 comments on commit 217faae

Please sign in to comment.