wip pc problems backup

This commit is contained in:
collerek
2021-03-14 19:09:34 +01:00
parent 1c63b1c80f
commit 6d0a5477cd
12 changed files with 268 additions and 184 deletions

View File

@ -5,6 +5,7 @@ import pytest
import sqlalchemy
import ormar
from ormar.exceptions import QueryDefinitionError
from tests.settings import DATABASE_URL
database = databases.Database(DATABASE_URL)
@ -67,8 +68,7 @@ async def test_min_method():
await sample_data()
assert await Book.objects.min("year") == 1920
result = await Book.objects.min(["year", "ranking"])
assert result == (1920, 1)
assert dict(result) == dict(year=1920, ranking=1)
assert result == dict(year=1920, ranking=1)
assert await Book.objects.min("title") == "Book 1"
@ -76,8 +76,7 @@ async def test_min_method():
result = await Author.objects.select_related("books").min(
["books__year", "books__ranking"]
)
assert result == (1920, 1)
assert dict(result) == dict(books__year=1920, books__ranking=1)
assert result == dict(books__year=1920, books__ranking=1)
assert (
await Author.objects.select_related("books")
@ -93,8 +92,7 @@ async def test_max_method():
await sample_data()
assert await Book.objects.max("year") == 1930
result = await Book.objects.max(["year", "ranking"])
assert result == (1930, 5)
assert dict(result) == dict(year=1930, ranking=5)
assert result == dict(year=1930, ranking=5)
assert await Book.objects.max("title") == "Book 3"
@ -102,8 +100,7 @@ async def test_max_method():
result = await Author.objects.select_related("books").max(
["books__year", "books__ranking"]
)
assert result == (1930, 5)
assert dict(result) == dict(books__year=1930, books__ranking=5)
assert result == dict(books__year=1930, books__ranking=5)
assert (
await Author.objects.select_related("books")
@ -119,17 +116,16 @@ async def test_sum_method():
await sample_data()
assert await Book.objects.sum("year") == 5773
result = await Book.objects.sum(["year", "ranking"])
assert result == (5773, 9)
assert dict(result) == dict(year=5773, ranking=9)
assert result == dict(year=5773, ranking=9)
assert await Book.objects.sum("title") == 0.0
with pytest.raises(QueryDefinitionError):
await Book.objects.sum("title")
assert await Author.objects.select_related("books").sum("books__year") == 5773
result = await Author.objects.select_related("books").sum(
["books__year", "books__ranking"]
)
assert result == (5773, 9)
assert dict(result) == dict(books__year=5773, books__ranking=9)
assert result == dict(books__year=5773, books__ranking=9)
assert (
await Author.objects.select_related("books")
@ -143,24 +139,21 @@ async def test_sum_method():
async def test_avg_method():
async with database:
await sample_data()
assert round(await Book.objects.avg("year"), 2) == 1924.33
assert round(float(await Book.objects.avg("year")), 2) == 1924.33
result = await Book.objects.avg(["year", "ranking"])
assert (round(result[0], 2), result[1]) == (1924.33, 3.0)
result_dict = dict(result)
assert round(result_dict.get("year"), 2) == 1924.33
assert result_dict.get("ranking") == 3.0
assert round(float(result.get("year")), 2) == 1924.33
assert result.get("ranking") == 3.0
assert await Book.objects.avg("title") == 0.0
with pytest.raises(QueryDefinitionError):
await Book.objects.avg("title")
result = await Author.objects.select_related("books").avg("books__year")
assert round(result, 2) == 1924.33
assert round(float(result), 2) == 1924.33
result = await Author.objects.select_related("books").avg(
["books__year", "books__ranking"]
)
assert (round(result[0], 2), result[1]) == (1924.33, 3.0)
result_dict = dict(result)
assert round(result_dict.get("books__year"), 2) == 1924.33
assert result_dict.get("books__ranking") == 3.0
assert round(float(result.get("books__year")), 2) == 1924.33
assert result.get("books__ranking") == 3.0
assert (
await Author.objects.select_related("books")
@ -179,4 +172,6 @@ async def test_queryset_method():
assert await author.books.max("year") == 1930
assert await author.books.sum("ranking") == 9
assert await author.books.avg("ranking") == 3.0
assert await author.books.max(["year", "title"]) == (1930, "Book 3")
assert await author.books.max(["year", "title"]) == dict(
year=1930, title="Book 3"
)