File: test_evaluation.py

package info (click to toggle)
python-beanie 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,480 kB
  • sloc: python: 14,427; makefile: 7; sh: 6
file content (80 lines) | stat: -rw-r--r-- 1,845 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from beanie.odm.operators.find.evaluation import (
    Expr,
    JsonSchema,
    Mod,
    RegEx,
    Text,
    Where,
)
from tests.odm.models import Sample


async def test_expr():
    q = Expr({"a": "B"})
    assert q == {"$expr": {"a": "B"}}


async def test_json_schema():
    q = JsonSchema({"a": "B"})
    assert q == {"$jsonSchema": {"a": "B"}}


async def test_mod():
    q = Mod(Sample.integer, 3, 2)
    assert q == {"integer": {"$mod": [3, 2]}}


async def test_regex():
    q = RegEx(Sample.integer, "smth")
    assert q == {"integer": {"$regex": "smth"}}

    q = RegEx(Sample.integer, "smth", "options")
    assert q == {"integer": {"$regex": "smth", "$options": "options"}}


async def test_text():
    q = Text("something")
    assert q == {
        "$text": {
            "$search": "something",
            "$caseSensitive": False,
            "$diacriticSensitive": False,
        }
    }
    q = Text("something", case_sensitive=True)
    assert q == {
        "$text": {
            "$search": "something",
            "$caseSensitive": True,
            "$diacriticSensitive": False,
        }
    }
    q = Text("something", diacritic_sensitive=True)
    assert q == {
        "$text": {
            "$search": "something",
            "$caseSensitive": False,
            "$diacriticSensitive": True,
        }
    }
    q = Text("something", diacritic_sensitive=None)
    assert q == {
        "$text": {
            "$search": "something",
            "$caseSensitive": False,
        }
    }
    q = Text("something", language="test")
    assert q == {
        "$text": {
            "$search": "something",
            "$caseSensitive": False,
            "$diacriticSensitive": False,
            "$language": "test",
        }
    }


async def test_where():
    q = Where("test")
    assert q == {"$where": "test"}