switch to equals in most of the code, fix dependencies, clean tests, make all not relation fields work with type hints
This commit is contained in:
@ -15,10 +15,10 @@ class Child(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(name="child_id", primary_key=True)
|
||||
first_name: ormar.String(name="fname", max_length=100)
|
||||
last_name: ormar.String(name="lname", max_length=100)
|
||||
born_year: ormar.Integer(name="year_born", nullable=True)
|
||||
id = ormar.Integer(name="child_id", primary_key=True)
|
||||
first_name = ormar.String(name="fname", max_length=100)
|
||||
last_name = ormar.String(name="lname", max_length=100)
|
||||
born_year = ormar.Integer(name="year_born", nullable=True)
|
||||
|
||||
|
||||
class ArtistChildren(ormar.Model):
|
||||
@ -34,11 +34,13 @@ class Artist(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(name="artist_id", primary_key=True)
|
||||
first_name: ormar.String(name="fname", max_length=100)
|
||||
last_name: ormar.String(name="lname", max_length=100)
|
||||
born_year: ormar.Integer(name="year")
|
||||
children: ormar.ManyToMany(Child, through=ArtistChildren)
|
||||
id = ormar.Integer(name="artist_id", primary_key=True)
|
||||
first_name = ormar.String(name="fname", max_length=100)
|
||||
last_name = ormar.String(name="lname", max_length=100)
|
||||
born_year = ormar.Integer(name="year")
|
||||
children = ormar.ManyToMany(
|
||||
Child, through=ArtistChildren
|
||||
)
|
||||
|
||||
|
||||
class Album(ormar.Model):
|
||||
@ -47,9 +49,9 @@ class Album(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(name="album_id", primary_key=True)
|
||||
name: ormar.String(name="album_name", max_length=100)
|
||||
artist: ormar.ForeignKey(Artist, name="artist_id")
|
||||
id = ormar.Integer(name="album_id", primary_key=True)
|
||||
name = ormar.String(name="album_name", max_length=100)
|
||||
artist = ormar.ForeignKey(Artist, name="artist_id")
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, scope="module")
|
||||
|
||||
@ -2,6 +2,7 @@ import datetime
|
||||
import os
|
||||
|
||||
import databases
|
||||
import pydantic
|
||||
import pytest
|
||||
import sqlalchemy
|
||||
|
||||
@ -22,14 +23,14 @@ class Example(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=200, default="aaa")
|
||||
created: ormar.DateTime(default=datetime.datetime.now)
|
||||
created_day: ormar.Date(default=datetime.date.today)
|
||||
created_time: ormar.Time(default=time)
|
||||
description: ormar.Text(nullable=True)
|
||||
value: ormar.Float(nullable=True)
|
||||
data: ormar.JSON(default={})
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=200, default="aaa")
|
||||
created = ormar.DateTime(default=datetime.datetime.now)
|
||||
created_day = ormar.Date(default=datetime.date.today)
|
||||
created_time = ormar.Time(default=time)
|
||||
description = ormar.Text(nullable=True)
|
||||
value = ormar.Float(nullable=True)
|
||||
data = ormar.JSON(default={})
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, scope="module")
|
||||
|
||||
@ -38,8 +38,8 @@ class Category(ormar.Model):
|
||||
class Meta(LocalMeta):
|
||||
tablename = "categories"
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=100)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
|
||||
|
||||
class ItemsXCategories(ormar.Model):
|
||||
@ -51,9 +51,11 @@ class Item(ormar.Model):
|
||||
class Meta(LocalMeta):
|
||||
pass
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=100)
|
||||
categories: ormar.ManyToMany(Category, through=ItemsXCategories)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
categories = ormar.ManyToMany(
|
||||
Category, through=ItemsXCategories
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, scope="module")
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
from typing import Optional
|
||||
|
||||
import databases
|
||||
import sqlalchemy
|
||||
from fastapi import FastAPI
|
||||
@ -18,8 +20,8 @@ class Category(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=100)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
|
||||
|
||||
class Item(ormar.Model):
|
||||
@ -28,9 +30,9 @@ class Item(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=100)
|
||||
category: ormar.ForeignKey(Category, nullable=True)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
category = ormar.ForeignKey(Category, nullable=True)
|
||||
|
||||
|
||||
@app.post("/items/", response_model=Item)
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
from typing import Optional
|
||||
|
||||
import databases
|
||||
import pytest
|
||||
import sqlalchemy
|
||||
@ -16,8 +18,8 @@ class Album(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=100)
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
name: str = ormar.String(max_length=100)
|
||||
|
||||
|
||||
class Track(ormar.Model):
|
||||
@ -26,10 +28,10 @@ class Track(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
album: ormar.ForeignKey(Album)
|
||||
title: ormar.String(max_length=100)
|
||||
position: ormar.Integer()
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
album: Optional[Album] = ormar.ForeignKey(Album)
|
||||
title: str = ormar.String(max_length=100)
|
||||
position: int = ormar.Integer()
|
||||
|
||||
|
||||
class Cover(ormar.Model):
|
||||
@ -38,9 +40,9 @@ class Cover(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
album: ormar.ForeignKey(Album, related_name="cover_pictures")
|
||||
title: ormar.String(max_length=100)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
album = ormar.ForeignKey(Album, related_name="cover_pictures")
|
||||
title = ormar.String(max_length=100)
|
||||
|
||||
|
||||
class Organisation(ormar.Model):
|
||||
@ -49,8 +51,12 @@ class Organisation(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
ident: ormar.String(max_length=100, choices=["ACME Ltd", "Other ltd"])
|
||||
id = ormar.Integer(primary_key=True)
|
||||
ident = ormar.String(max_length=100, choices=["ACME Ltd", "Other ltd"])
|
||||
|
||||
|
||||
class Organization(object):
|
||||
pass
|
||||
|
||||
|
||||
class Team(ormar.Model):
|
||||
@ -59,9 +65,9 @@ class Team(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
org: ormar.ForeignKey(Organisation)
|
||||
name: ormar.String(max_length=100)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
org = ormar.ForeignKey(Organisation)
|
||||
name = ormar.String(max_length=100)
|
||||
|
||||
|
||||
class Member(ormar.Model):
|
||||
@ -70,9 +76,9 @@ class Member(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
team: ormar.ForeignKey(Team)
|
||||
email: ormar.String(max_length=100)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
team = ormar.ForeignKey(Team)
|
||||
email = ormar.String(max_length=100)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, scope="module")
|
||||
@ -233,8 +239,8 @@ async def test_fk_filter():
|
||||
|
||||
tracks = (
|
||||
await Track.objects.select_related("album")
|
||||
.filter(album__name="Fantasies")
|
||||
.all()
|
||||
.filter(album__name="Fantasies")
|
||||
.all()
|
||||
)
|
||||
assert len(tracks) == 3
|
||||
for track in tracks:
|
||||
@ -242,8 +248,8 @@ async def test_fk_filter():
|
||||
|
||||
tracks = (
|
||||
await Track.objects.select_related("album")
|
||||
.filter(album__name__icontains="fan")
|
||||
.all()
|
||||
.filter(album__name__icontains="fan")
|
||||
.all()
|
||||
)
|
||||
assert len(tracks) == 3
|
||||
for track in tracks:
|
||||
@ -288,8 +294,8 @@ async def test_multiple_fk():
|
||||
|
||||
members = (
|
||||
await Member.objects.select_related("team__org")
|
||||
.filter(team__org__ident="ACME Ltd")
|
||||
.all()
|
||||
.filter(team__org__ident="ACME Ltd")
|
||||
.all()
|
||||
)
|
||||
assert len(members) == 4
|
||||
for member in members:
|
||||
@ -321,8 +327,8 @@ async def test_pk_filter():
|
||||
|
||||
tracks = (
|
||||
await Track.objects.select_related("album")
|
||||
.filter(position=2, album__name="Test")
|
||||
.all()
|
||||
.filter(position=2, album__name="Test")
|
||||
.all()
|
||||
)
|
||||
assert len(tracks) == 1
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
from typing import List, Union, Optional
|
||||
|
||||
import databases
|
||||
import pytest
|
||||
@ -18,9 +19,9 @@ class Author(ormar.Model):
|
||||
database = database
|
||||
metadata = metadata
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
first_name: ormar.String(max_length=80)
|
||||
last_name: ormar.String(max_length=80)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
first_name = ormar.String(max_length=80)
|
||||
last_name = ormar.String(max_length=80)
|
||||
|
||||
|
||||
class Category(ormar.Model):
|
||||
@ -29,8 +30,8 @@ class Category(ormar.Model):
|
||||
database = database
|
||||
metadata = metadata
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=40)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=40)
|
||||
|
||||
|
||||
class PostCategory(ormar.Model):
|
||||
@ -46,10 +47,12 @@ class Post(ormar.Model):
|
||||
database = database
|
||||
metadata = metadata
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
title: ormar.String(max_length=200)
|
||||
categories: ormar.ManyToMany(Category, through=PostCategory)
|
||||
author: ormar.ForeignKey(Author)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
title = ormar.String(max_length=200)
|
||||
categories = ormar.ManyToMany(
|
||||
Category, through=PostCategory
|
||||
)
|
||||
author= ormar.ForeignKey(Author)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
|
||||
@ -1,13 +1,17 @@
|
||||
# type: ignore
|
||||
import asyncio
|
||||
import datetime
|
||||
import decimal
|
||||
|
||||
import pydantic
|
||||
import pytest
|
||||
import sqlalchemy
|
||||
import typing
|
||||
|
||||
import ormar.fields as fields
|
||||
import ormar
|
||||
from ormar.exceptions import ModelDefinitionError
|
||||
from ormar.models import Model
|
||||
from tests.settings import DATABASE_URL
|
||||
|
||||
metadata = sqlalchemy.MetaData()
|
||||
|
||||
@ -17,18 +21,18 @@ class ExampleModel(Model):
|
||||
tablename = "example"
|
||||
metadata = metadata
|
||||
|
||||
test: fields.Integer(primary_key=True)
|
||||
test_string: fields.String(max_length=250)
|
||||
test_text: fields.Text(default="")
|
||||
test_bool: fields.Boolean(nullable=False)
|
||||
test_float: fields.Float() = None
|
||||
test_datetime: fields.DateTime(default=datetime.datetime.now)
|
||||
test_date: fields.Date(default=datetime.date.today)
|
||||
test_time: fields.Time(default=datetime.time)
|
||||
test_json: fields.JSON(default={})
|
||||
test_bigint: fields.BigInteger(default=0)
|
||||
test_decimal: fields.Decimal(scale=10, precision=2)
|
||||
test_decimal2: fields.Decimal(max_digits=10, decimal_places=2)
|
||||
test = ormar.Integer(primary_key=True)
|
||||
test_string = ormar.String(max_length=250)
|
||||
test_text = ormar.Text(default="")
|
||||
test_bool = ormar.Boolean(nullable=False)
|
||||
test_float: ormar.Float() = None # type: ignore
|
||||
test_datetime = ormar.DateTime(default=datetime.datetime.now)
|
||||
test_date = ormar.Date(default=datetime.date.today)
|
||||
test_time = ormar.Time(default=datetime.time)
|
||||
test_json = ormar.JSON(default={})
|
||||
test_bigint = ormar.BigInteger(default=0)
|
||||
test_decimal = ormar.Decimal(scale=10, precision=2)
|
||||
test_decimal2 = ormar.Decimal(max_digits=10, decimal_places=2)
|
||||
|
||||
|
||||
fields_to_check = [
|
||||
@ -46,11 +50,26 @@ fields_to_check = [
|
||||
|
||||
class ExampleModel2(Model):
|
||||
class Meta:
|
||||
tablename = "example2"
|
||||
tablename = "examples"
|
||||
metadata = metadata
|
||||
|
||||
test: fields.Integer(primary_key=True)
|
||||
test_string: fields.String(max_length=250)
|
||||
test = ormar.Integer(primary_key=True)
|
||||
test_string = ormar.String(max_length=250)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def event_loop():
|
||||
loop = asyncio.get_event_loop()
|
||||
yield loop
|
||||
loop.close()
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, scope="module")
|
||||
async def create_test_database():
|
||||
engine = sqlalchemy.create_engine(DATABASE_URL)
|
||||
metadata.create_all(engine)
|
||||
yield
|
||||
metadata.drop_all(engine)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@ -117,62 +136,64 @@ def test_sqlalchemy_table_is_created(example):
|
||||
assert all([field in example.Meta.table.columns for field in fields_to_check])
|
||||
|
||||
|
||||
def test_no_pk_in_model_definition():
|
||||
with pytest.raises(ModelDefinitionError):
|
||||
|
||||
class ExampleModel2(Model):
|
||||
@typing.no_type_check
|
||||
def test_no_pk_in_model_definition(): # type: ignore
|
||||
with pytest.raises(ModelDefinitionError): # type: ignore
|
||||
class ExampleModel2(Model): # type: ignore
|
||||
class Meta:
|
||||
tablename = "example3"
|
||||
tablename = "example2"
|
||||
metadata = metadata
|
||||
|
||||
test_string: fields.String(max_length=250)
|
||||
test_string = ormar.String(max_length=250) # type: ignore
|
||||
|
||||
|
||||
@typing.no_type_check
|
||||
def test_two_pks_in_model_definition():
|
||||
with pytest.raises(ModelDefinitionError):
|
||||
|
||||
@typing.no_type_check
|
||||
class ExampleModel2(Model):
|
||||
class Meta:
|
||||
tablename = "example3"
|
||||
metadata = metadata
|
||||
|
||||
id: fields.Integer(primary_key=True)
|
||||
test_string: fields.String(max_length=250, primary_key=True)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
test_string = ormar.String(max_length=250, primary_key=True)
|
||||
|
||||
|
||||
@typing.no_type_check
|
||||
def test_setting_pk_column_as_pydantic_only_in_model_definition():
|
||||
with pytest.raises(ModelDefinitionError):
|
||||
|
||||
class ExampleModel2(Model):
|
||||
class Meta:
|
||||
tablename = "example4"
|
||||
metadata = metadata
|
||||
|
||||
test: fields.Integer(primary_key=True, pydantic_only=True)
|
||||
test = ormar.Integer(primary_key=True, pydantic_only=True)
|
||||
|
||||
|
||||
@typing.no_type_check
|
||||
def test_decimal_error_in_model_definition():
|
||||
with pytest.raises(ModelDefinitionError):
|
||||
|
||||
class ExampleModel2(Model):
|
||||
class Meta:
|
||||
tablename = "example5"
|
||||
metadata = metadata
|
||||
|
||||
test: fields.Decimal(primary_key=True)
|
||||
test = ormar.Decimal(primary_key=True)
|
||||
|
||||
|
||||
@typing.no_type_check
|
||||
def test_string_error_in_model_definition():
|
||||
with pytest.raises(ModelDefinitionError):
|
||||
|
||||
class ExampleModel2(Model):
|
||||
class Meta:
|
||||
tablename = "example6"
|
||||
metadata = metadata
|
||||
|
||||
test: fields.String(primary_key=True)
|
||||
test = ormar.String(primary_key=True)
|
||||
|
||||
|
||||
@typing.no_type_check
|
||||
def test_json_conversion_in_model():
|
||||
with pytest.raises(pydantic.ValidationError):
|
||||
ExampleModel(
|
||||
|
||||
@ -22,8 +22,8 @@ class JsonSample(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
test_json: ormar.JSON(nullable=True)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
test_json= ormar.JSON(nullable=True)
|
||||
|
||||
|
||||
class UUIDSample(ormar.Model):
|
||||
@ -32,8 +32,8 @@ class UUIDSample(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.UUID(primary_key=True, default=uuid.uuid4)
|
||||
test_text: ormar.Text()
|
||||
id= ormar.UUID(primary_key=True, default=uuid.uuid4)
|
||||
test_text = ormar.Text()
|
||||
|
||||
|
||||
class User(ormar.Model):
|
||||
@ -42,8 +42,8 @@ class User(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=100, default="")
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100, default="")
|
||||
|
||||
|
||||
class Product(ormar.Model):
|
||||
@ -52,11 +52,11 @@ class Product(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=100)
|
||||
rating: ormar.Integer(minimum=1, maximum=5)
|
||||
in_stock: ormar.Boolean(default=False)
|
||||
last_delivery: ormar.Date(default=datetime.now)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
rating = ormar.Integer(minimum=1, maximum=5)
|
||||
in_stock= ormar.Boolean(default=False)
|
||||
last_delivery= ormar.Date(default=datetime.now)
|
||||
|
||||
|
||||
country_name_choices = ("Canada", "Algeria", "United States")
|
||||
@ -70,12 +70,12 @@ class Country(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(
|
||||
max_length=9, choices=country_name_choices, default="Canada",
|
||||
)
|
||||
taxed: ormar.Boolean(choices=country_taxed_choices, default=True)
|
||||
country_code: ormar.Integer(
|
||||
taxed= ormar.Boolean(choices=country_taxed_choices, default=True)
|
||||
country_code = ormar.Integer(
|
||||
minimum=0, maximum=1000, choices=country_country_code_choices, default=1
|
||||
)
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from typing import List
|
||||
from typing import List, Optional
|
||||
|
||||
import databases
|
||||
import pytest
|
||||
@ -35,8 +35,8 @@ class Category(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=100)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
|
||||
|
||||
class Item(ormar.Model):
|
||||
@ -45,9 +45,9 @@ class Item(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=100)
|
||||
category: ormar.ForeignKey(Category, nullable=True)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
category = ormar.ForeignKey(Category, nullable=True)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, scope="module")
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
from typing import Optional
|
||||
|
||||
import databases
|
||||
import pytest
|
||||
@ -17,8 +18,8 @@ class Department(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True, autoincrement=False)
|
||||
name: ormar.String(max_length=100)
|
||||
id = ormar.Integer(primary_key=True, autoincrement=False)
|
||||
name = ormar.String(max_length=100)
|
||||
|
||||
|
||||
class SchoolClass(ormar.Model):
|
||||
@ -27,8 +28,8 @@ class SchoolClass(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=100)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
|
||||
|
||||
class Category(ormar.Model):
|
||||
@ -37,9 +38,9 @@ class Category(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=100)
|
||||
department: ormar.ForeignKey(Department, nullable=False)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
department= ormar.ForeignKey(Department, nullable=False)
|
||||
|
||||
|
||||
class Student(ormar.Model):
|
||||
@ -48,10 +49,10 @@ class Student(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=100)
|
||||
schoolclass: ormar.ForeignKey(SchoolClass)
|
||||
category: ormar.ForeignKey(Category, nullable=True)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
schoolclass= ormar.ForeignKey(SchoolClass)
|
||||
category= ormar.ForeignKey(Category, nullable=True)
|
||||
|
||||
|
||||
class Teacher(ormar.Model):
|
||||
@ -60,10 +61,10 @@ class Teacher(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=100)
|
||||
schoolclass: ormar.ForeignKey(SchoolClass)
|
||||
category: ormar.ForeignKey(Category, nullable=True)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
schoolclass= ormar.ForeignKey(SchoolClass)
|
||||
category= ormar.ForeignKey(Category, nullable=True)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
|
||||
@ -18,8 +18,8 @@ class Album(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
name: str = ormar.String(max_length=100)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
|
||||
|
||||
class Track(ormar.Model):
|
||||
@ -28,10 +28,10 @@ class Track(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
album: Optional[Album] = ormar.ForeignKey(Album)
|
||||
title: str = ormar.String(max_length=100)
|
||||
position: int = ormar.Integer()
|
||||
id = ormar.Integer(primary_key=True)
|
||||
album= ormar.ForeignKey(Album)
|
||||
title = ormar.String(max_length=100)
|
||||
position = ormar.Integer()
|
||||
|
||||
|
||||
class Cover(ormar.Model):
|
||||
@ -40,9 +40,9 @@ class Cover(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
album: Album = ormar.ForeignKey(Album, related_name="cover_pictures")
|
||||
title: str = ormar.String(max_length=100)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
album= ormar.ForeignKey(Album, related_name="cover_pictures")
|
||||
title = ormar.String(max_length=100)
|
||||
|
||||
|
||||
class Organisation(ormar.Model):
|
||||
@ -51,8 +51,8 @@ class Organisation(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
ident: str = ormar.String(max_length=100, choices=["ACME Ltd", "Other ltd"])
|
||||
id = ormar.Integer(primary_key=True)
|
||||
ident = ormar.String(max_length=100, choices=["ACME Ltd", "Other ltd"])
|
||||
|
||||
|
||||
class Team(ormar.Model):
|
||||
@ -61,9 +61,9 @@ class Team(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
org: Optional[Organisation] = ormar.ForeignKey(Organisation)
|
||||
name: str = ormar.String(max_length=100)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
org= ormar.ForeignKey(Organisation)
|
||||
name = ormar.String(max_length=100)
|
||||
|
||||
|
||||
class Member(ormar.Model):
|
||||
@ -72,9 +72,9 @@ class Member(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
team: Optional[Team] = ormar.ForeignKey(Team)
|
||||
email: str = ormar.String(max_length=100)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
team= ormar.ForeignKey(Team)
|
||||
email = ormar.String(max_length=100)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, scope="module")
|
||||
|
||||
@ -21,8 +21,8 @@ class Model(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.String(primary_key=True, default=key, max_length=8)
|
||||
name: ormar.String(max_length=32)
|
||||
id = ormar.String(primary_key=True, default=key, max_length=8)
|
||||
name = ormar.String(max_length=32)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, scope="function")
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
from typing import Optional
|
||||
|
||||
import databases
|
||||
import pytest
|
||||
import sqlalchemy
|
||||
@ -16,10 +18,10 @@ class Book(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
title: ormar.String(max_length=200)
|
||||
author: ormar.String(max_length=100)
|
||||
genre: ormar.String(
|
||||
id = ormar.Integer(primary_key=True)
|
||||
title = ormar.String(max_length=200)
|
||||
author = ormar.String(max_length=100)
|
||||
genre = ormar.String(
|
||||
max_length=100,
|
||||
default="Fiction",
|
||||
choices=["Fiction", "Adventure", "Historic", "Fantasy"],
|
||||
@ -32,9 +34,9 @@ class ToDo(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
text: ormar.String(max_length=500)
|
||||
completed: ormar.Boolean(default=False)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
text = ormar.String(max_length=500)
|
||||
completed= ormar.Boolean(default=False)
|
||||
|
||||
|
||||
class Category(ormar.Model):
|
||||
@ -43,8 +45,8 @@ class Category(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=500)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=500)
|
||||
|
||||
|
||||
class Note(ormar.Model):
|
||||
@ -53,9 +55,9 @@ class Note(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
text: ormar.String(max_length=500)
|
||||
category: ormar.ForeignKey(Category)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
text = ormar.String(max_length=500)
|
||||
category= ormar.ForeignKey(Category)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, scope="module")
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
from typing import Optional
|
||||
|
||||
import databases
|
||||
import pytest
|
||||
@ -17,8 +18,8 @@ class Department(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True, autoincrement=False)
|
||||
name: ormar.String(max_length=100)
|
||||
id = ormar.Integer(primary_key=True, autoincrement=False)
|
||||
name = ormar.String(max_length=100)
|
||||
|
||||
|
||||
class SchoolClass(ormar.Model):
|
||||
@ -27,9 +28,9 @@ class SchoolClass(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=100)
|
||||
department: ormar.ForeignKey(Department, nullable=False)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
department= ormar.ForeignKey(Department, nullable=False)
|
||||
|
||||
|
||||
class Category(ormar.Model):
|
||||
@ -38,8 +39,8 @@ class Category(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=100)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
|
||||
|
||||
class Student(ormar.Model):
|
||||
@ -48,10 +49,10 @@ class Student(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=100)
|
||||
schoolclass: ormar.ForeignKey(SchoolClass)
|
||||
category: ormar.ForeignKey(Category, nullable=True)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
schoolclass= ormar.ForeignKey(SchoolClass)
|
||||
category= ormar.ForeignKey(Category, nullable=True)
|
||||
|
||||
|
||||
class Teacher(ormar.Model):
|
||||
@ -60,10 +61,10 @@ class Teacher(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=100)
|
||||
schoolclass: ormar.ForeignKey(SchoolClass)
|
||||
category: ormar.ForeignKey(Category, nullable=True)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
schoolclass= ormar.ForeignKey(SchoolClass)
|
||||
category= ormar.ForeignKey(Category, nullable=True)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
from typing import Optional
|
||||
|
||||
import databases
|
||||
import pydantic
|
||||
import pytest
|
||||
@ -16,9 +18,9 @@ class Company(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=100, nullable=False)
|
||||
founded: ormar.Integer(nullable=True)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100, nullable=False)
|
||||
founded = ormar.Integer(nullable=True)
|
||||
|
||||
|
||||
class Car(ormar.Model):
|
||||
@ -27,13 +29,13 @@ class Car(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
manufacturer: ormar.ForeignKey(Company)
|
||||
name: ormar.String(max_length=100)
|
||||
year: ormar.Integer(nullable=True)
|
||||
gearbox_type: ormar.String(max_length=20, nullable=True)
|
||||
gears: ormar.Integer(nullable=True)
|
||||
aircon_type: ormar.String(max_length=20, nullable=True)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
manufacturer= ormar.ForeignKey(Company)
|
||||
name = ormar.String(max_length=100)
|
||||
year = ormar.Integer(nullable=True)
|
||||
gearbox_type = ormar.String(max_length=20, nullable=True)
|
||||
gears = ormar.Integer(nullable=True)
|
||||
aircon_type = ormar.String(max_length=20, nullable=True)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, scope="module")
|
||||
|
||||
@ -20,11 +20,11 @@ class Product(ormar.Model):
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=100)
|
||||
company: ormar.String(max_length=200, server_default="Acme")
|
||||
sort_order: ormar.Integer(server_default=text("10"))
|
||||
created: ormar.DateTime(server_default=func.now())
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
company = ormar.String(max_length=200, server_default="Acme")
|
||||
sort_order = ormar.Integer(server_default=text("10"))
|
||||
created= ormar.DateTime(server_default=func.now())
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
|
||||
@ -21,9 +21,9 @@ class Product(ormar.Model):
|
||||
database = database
|
||||
constraints = [ormar.UniqueColumns("name", "company")]
|
||||
|
||||
id: ormar.Integer(primary_key=True)
|
||||
name: ormar.String(max_length=100)
|
||||
company: ormar.String(max_length=200)
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
company = ormar.String(max_length=200)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
|
||||
Reference in New Issue
Block a user