File: test_query.py

package info (click to toggle)
python-odmantic 1.0.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 1,640 kB
  • sloc: python: 8,547; sh: 37; makefile: 34; xml: 13; javascript: 3
file content (40 lines) | stat: -rw-r--r-- 1,132 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from odmantic.query import QueryExpression, SortExpression, asc
from tests.zoo.book_embedded import Book, Publisher
from tests.zoo.tree import TreeKind, TreeModel


def test_embedded_eq():
    pub = Publisher(name="O'Reilly Media", founded=1980, location="CA")
    assert (Book.publisher == pub) == {
        "publisher": {
            "$eq": {"name": "O'Reilly Media", "founded": 1980, "location": "CA"}
        }
    }


def test_embedded_eq_on_subfield():
    assert (Book.publisher.location == "EU") == {"publisher.location": {"$eq": "EU"}}


def test_eq_on_enum():
    assert (TreeModel.kind == TreeKind.BIG) == {"kind": {"$eq": TreeKind.BIG.value}}
    assert (TreeModel.kind == "big") == {"kind": {"$eq": "big"}}


def test_query_repr():
    assert (
        repr(TreeModel.name == "Spruce")
        == "QueryExpression({'name': {'$eq': 'Spruce'}})"
    )


def test_query_empty_repr():
    assert repr(QueryExpression()) == "QueryExpression()"


def test_sort_repr():
    assert repr(asc(TreeModel.name)) == "SortExpression({'name': 1})"


def test_sort_empty_repr():
    assert repr(SortExpression()) == "SortExpression()"