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

fix(test): error initializing tests #484

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion python/apps/taiga/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import pytest
import pytest_asyncio
from taiga.base.django.commands import call_django_command
from taiga.events import connect_events_manager

from .fixtures import * # noqa

Expand Down Expand Up @@ -56,6 +55,8 @@ def django_db_setup(django_db_setup, django_db_blocker):

@pytest_asyncio.fixture(scope="session", autouse=True)
async def connect_events_manage_on_startup():
from taiga.events import connect_events_manager

await connect_events_manager()


Expand Down
28 changes: 19 additions & 9 deletions python/apps/taiga/tests/utils/testclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,42 @@
#
# Copyright (c) 2023-present Kaleidos INC

from typing import TYPE_CHECKING

import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient as TestClientBase
from taiga.auth.tokens import AccessToken
from taiga.base.utils.concurrency import run_async_as_sync
from taiga.events import app as events_app
from taiga.main import api as api_app
from taiga.users.models import User

test_app = FastAPI()
test_app.mount("/events/", app=events_app)
test_app.mount("/", app=api_app)
if TYPE_CHECKING:
from taiga.users.models import User


class TestClient(TestClientBase):
def login(self, user: User) -> None:
def login(self, user: "User") -> None:
from taiga.auth.tokens import AccessToken

token = run_async_as_sync(AccessToken.create_for_object(user))
self.headers["Authorization"] = f"Bearer {str(token)}"

def logout(self) -> None:
self.headers.pop("Authorization", None)


def _get_test_app() -> FastAPI:
from taiga.events import app as events_app
from taiga.main import api as api_app

test_app = FastAPI()
test_app.mount("/events/", app=events_app)
test_app.mount("/", app=api_app)

return test_app


@pytest.fixture
def client() -> TestClient:
return TestClient(test_app)
return TestClient(_get_test_app())


@pytest.fixture
Expand Down
Loading