File: test_views.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 (28 lines) | stat: -rw-r--r-- 934 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
from tests.odm.views import ViewForTest, ViewForTestWithLink


class TestViews:
    async def test_simple(self, documents):
        await documents(number=15)
        results = await ViewForTest.all().to_list()
        assert len(results) == 6

    async def test_aggregate(self, documents):
        await documents(number=15)
        results = await ViewForTest.aggregate(
            [
                {"$set": {"test_field": 1}},
                {"$match": {"$expr": {"$lt": ["$number", 12]}}},
            ]
        ).to_list()
        assert len(results) == 3
        assert results[0]["test_field"] == 1

    async def test_link(self, documents_with_links):
        await documents_with_links()
        results = await ViewForTestWithLink.all().to_list()
        for document in results:
            await document.fetch_all_links()

        for i, document in enumerate(results):
            assert document.link.test_int == i