forked from kernelci/kernelci-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconftest.py
48 lines (36 loc) · 1.2 KB
/
conftest.py
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
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# Copyright (C) 2023 Collabora Limited
# Author: Jeny Sadadia <jeny.sadadia@collabora.com>
"""pytest fixtures for KernelCI API end-to-end tests"""
import pytest
from httpx import AsyncClient
from motor.motor_asyncio import AsyncIOMotorClient
from api.main import app
BASE_URL = 'http://api:8000/latest/'
DB_URL = 'mongodb://db:27017'
DB_NAME = 'kernelci'
db_client = AsyncIOMotorClient(DB_URL)
db = db_client[DB_NAME]
@pytest.fixture(scope='session')
async def test_async_client():
"""Fixture to get Test client for asynchronous tests"""
async with AsyncClient(app=app, base_url=BASE_URL) as client:
await app.router.startup()
yield client
await app.router.shutdown()
async def db_create(collection, obj):
"""Database create method"""
delattr(obj, 'id')
col = db[collection]
res = await col.insert_one(obj.dict(by_alias=True))
obj.id = res.inserted_id
return obj
@pytest.fixture(scope='session')
def event_loop():
"""Get an instance of the default event loop using database client.
The event loop will be used for all async tests.
"""
loop = db_client.get_io_loop()
yield loop
loop.close()