Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T40464 Upgrade API to python 3.11 #504

Merged
merged 8 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions tests/e2e_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
from httpx import AsyncClient
from motor.motor_asyncio import AsyncIOMotorClient

from fastapi.testclient import TestClient

from api.main import versioned_app
from kernelci.api.models import Node, Regression

Check failure on line 14 in tests/e2e_tests/conftest.py

View workflow job for this annotation

GitHub Actions / Lint

Unable to import 'kernelci.api.models'

Check warning on line 14 in tests/e2e_tests/conftest.py

View workflow job for this annotation

GitHub Actions / Lint

third party import "from kernelci.api.models import Node, Regression" should be placed before "from api.main import versioned_app"

BASE_URL = 'http://api:8000/latest/'
DB_URL = 'mongodb://db:27017'
Expand All @@ -30,12 +28,6 @@
'offset',
}

@pytest.fixture(scope='session')
def test_client():
"""Fixture to get FastAPI Test client instance"""
with TestClient(app=versioned_app, base_url=BASE_URL) as client:
yield client


@pytest.fixture(scope='session')
async def test_async_client():
Expand Down
10 changes: 6 additions & 4 deletions tests/e2e_tests/test_count_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,35 @@
import pytest


@pytest.mark.asyncio
@pytest.mark.dependency(
depends=[
'tests/e2e_tests/test_pipeline.py::test_node_pipeline'],
scope='session')
def test_count_nodes(test_client):
async def test_count_nodes(test_async_client):
"""
Test Case : Test KernelCI API GET /count endpoint
Expected Result :
HTTP Response Code 200 OK
Total number of nodes available
"""
response = test_client.get("count")
response = await test_async_client.get("count")
assert response.status_code == 200
assert response.json() >= 0


@pytest.mark.asyncio
@pytest.mark.dependency(
depends=[
'tests/e2e_tests/test_pipeline.py::test_node_pipeline'],
scope='session')
def test_count_nodes_matching_attributes(test_client):
async def test_count_nodes_matching_attributes(test_async_client):
"""
Test Case : Test KernelCI API GET /count endpoint with attributes
Expected Result :
HTTP Response Code 200 OK
Number of nodes matching attributes
"""
response = test_client.get("count?name=checkout")
response = await test_async_client.get("count?name=checkout")
assert response.status_code == 200
assert response.json() >= 0
7 changes: 5 additions & 2 deletions tests/e2e_tests/test_root_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

"""End-to-end test functions for KernelCI API root handler"""

import pytest

def test_root_endpoint(test_client):

@pytest.mark.asyncio
async def test_root_endpoint(test_async_client):
"""Test root handler"""
response = test_client.get("/latest")
response = await test_async_client.get("/")
assert response.status_code == 200
assert response.json() == {"message": "KernelCI API"}
15 changes: 9 additions & 6 deletions tests/e2e_tests/test_subscribe_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@
import pytest


@pytest.mark.asyncio
@pytest.mark.dependency(
depends=['tests/e2e_tests/test_user_creation.py::test_create_regular_user'],

Check warning on line 14 in tests/e2e_tests/test_subscribe_handler.py

View workflow job for this annotation

GitHub Actions / Lint

line too long (80 > 79 characters)
scope='session')
@pytest.mark.order(3)
def test_subscribe_node_channel(test_client):
async def test_subscribe_node_channel(test_async_client):
"""
Test Case : Test KernelCI API '/subscribe' endpoint with 'node' channel
Expected Result :
HTTP Response Code 200 OK
JSON with subscription 'id' and 'channel' keys
"""
response = test_client.post(
response = await test_async_client.post(
"subscribe/node",
headers={
"Authorization": f"Bearer {pytest.BEARER_TOKEN}" # pylint: disable=no-member

Check warning on line 27 in tests/e2e_tests/test_subscribe_handler.py

View workflow job for this annotation

GitHub Actions / Lint

line too long (89 > 79 characters)
},
)
pytest.node_channel_subscription_id = response.json()['id']
Expand All @@ -32,21 +33,22 @@
assert response.json().get('channel') == 'node'


@pytest.mark.asyncio
@pytest.mark.dependency(
depends=['tests/e2e_tests/test_user_creation.py::test_create_regular_user'],

Check warning on line 38 in tests/e2e_tests/test_subscribe_handler.py

View workflow job for this annotation

GitHub Actions / Lint

line too long (80 > 79 characters)
scope='session')
@pytest.mark.order(3)
def test_subscribe_test_channel(test_client):
async def test_subscribe_test_channel(test_async_client):
"""
Test Case : Test KernelCI API '/subscribe' endpoint with 'test_channel'
Expected Result :
HTTP Response Code 200 OK
JSON with subscription 'id' and 'channel' keys
"""
response = test_client.post(
response = await test_async_client.post(
"subscribe/test_channel",
headers={
"Authorization": f"Bearer {pytest.BEARER_TOKEN}" # pylint: disable=no-member

Check warning on line 51 in tests/e2e_tests/test_subscribe_handler.py

View workflow job for this annotation

GitHub Actions / Lint

line too long (89 > 79 characters)
},
)
pytest.test_channel_subscription_id = response.json()['id']
Expand All @@ -55,22 +57,23 @@
assert response.json().get('channel') == 'test_channel'


@pytest.mark.asyncio
@pytest.mark.dependency(
depends=['tests/e2e_tests/test_user_creation.py::test_create_regular_user'],

Check warning on line 62 in tests/e2e_tests/test_subscribe_handler.py

View workflow job for this annotation

GitHub Actions / Lint

line too long (80 > 79 characters)
scope='session')
@pytest.mark.order(3)
def test_subscribe_user_group_channel(test_client):
async def test_subscribe_user_group_channel(test_async_client):
"""
Test Case : Test KernelCI API '/subscribe' endpoint with 'user_group'
channel
Expected Result :
HTTP Response Code 200 OK
JSON with subscription 'id' and 'channel' keys
"""
response = test_client.post(
response = await test_async_client.post(
"subscribe/user_group",
headers={
"Authorization": f"Bearer {pytest.BEARER_TOKEN}" # pylint: disable=no-member

Check warning on line 76 in tests/e2e_tests/test_subscribe_handler.py

View workflow job for this annotation

GitHub Actions / Lint

line too long (89 > 79 characters)
},
)
pytest.user_group_channel_subscription_id = response.json()['id']
Expand Down
10 changes: 6 additions & 4 deletions tests/e2e_tests/test_unsubscribe_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
import pytest


@pytest.mark.asyncio
@pytest.mark.dependency(
depends=[
'tests/e2e_tests/test_subscribe_handler.py::test_subscribe_node_channel'],

Check warning on line 15 in tests/e2e_tests/test_unsubscribe_handler.py

View workflow job for this annotation

GitHub Actions / Lint

line too long (82 > 79 characters)
scope='session')
@pytest.mark.order("last")
def test_unsubscribe_node_channel(test_client):
async def test_unsubscribe_node_channel(test_async_client):
"""
Test Case : Test KernelCI API '/unsubscribe' endpoint with 'node' channel
Expected Result :
HTTP Response Code 200 OK
"""
response = test_client.post(
response = await test_async_client.post(
f"unsubscribe/{pytest.node_channel_subscription_id}", # pylint: disable=no-member

Check warning on line 25 in tests/e2e_tests/test_unsubscribe_handler.py

View workflow job for this annotation

GitHub Actions / Lint

line too long (90 > 79 characters)
headers={
"Authorization": f"Bearer {pytest.BEARER_TOKEN}" # pylint: disable=no-member
},
Expand All @@ -29,18 +30,19 @@
assert response.status_code == 200


@pytest.mark.asyncio
@pytest.mark.dependency(
depends=[
'tests/e2e_tests/test_subscribe_handler.py::test_subscribe_test_channel'],
scope='session')
@pytest.mark.order("last")
def test_unsubscribe_test_channel(test_client):
async def test_unsubscribe_test_channel(test_async_client):
"""
Test Case : Test KernelCI API '/unsubscribe' endpoint with 'test_channel'
Expected Result :
HTTP Response Code 200 OK
"""
response = test_client.post(
response = await test_async_client.post(
f"unsubscribe/{pytest.test_channel_subscription_id}", # pylint: disable=no-member
headers={
"Authorization": f"Bearer {pytest.BEARER_TOKEN}" # pylint: disable=no-member
Expand Down
10 changes: 6 additions & 4 deletions tests/e2e_tests/test_user_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,17 @@ async def test_create_regular_user(test_async_client):
pytest.BEARER_TOKEN = response.json()['access_token']


@pytest.mark.asyncio
@pytest.mark.dependency(depends=["test_create_regular_user"])
def test_whoami(test_client):
async def test_whoami(test_async_client):
"""
Test Case : Test KernelCI API /whoami endpoint
Expected Result :
HTTP Response Code 200 OK
JSON with 'id', 'email', username', 'groups', 'is_superuser'
'is_verified' and 'is_active' keys
"""
response = test_client.get(
response = await test_async_client.get(
"whoami",
headers={
"Accept": "application/json",
Expand All @@ -140,16 +141,17 @@ def test_whoami(test_client):
assert response.json()['username'] == 'test_user'


@pytest.mark.asyncio
@pytest.mark.dependency(depends=["test_create_regular_user"])
def test_create_user_negative(test_client):
async def test_create_user_negative(test_async_client):
"""
Test Case : Test KernelCI API /user/register endpoint when requested
with regular user's bearer token.
Expected Result :
HTTP Response Code 403 Forbidden
JSON with 'detail' key denoting 'Forbidden' error
"""
response = test_client.post(
response = await test_async_client.post(
"user/register",
headers={
"Accept": "application/json",
Expand Down
Loading