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

Application configuration and context to run pytest? #276

Open
khteh opened this issue Feb 21, 2025 · 0 comments
Open

Application configuration and context to run pytest? #276

khteh opened this issue Feb 21, 2025 · 0 comments

Comments

@khteh
Copy link

khteh commented Feb 21, 2025

import pytest, sys, asyncio
from hypercorn.config import Config
from hypercorn.asyncio import serve
from os.path import dirname, join, abspath
from src.app import create_app
#from src.main import app
from quart_cors import cors
sys.path.insert(0, abspath(join(dirname(__file__), '../src')))
from common.Authentication import Authentication
pytest_plugins = ('pytest_asyncio',)
@pytest.fixture
async def app_context():
    config = Config()
    config.bind = ["localhost:4433"]
    config.insecure_bind = ["localhost:8080"]
    config.worker_class = "asyncio"
    config.alt_svc_headers = ["h3=\":443\"; ma=3600, h3-29=\":443\"; ma=3600"]
    config.loglevel = "DEBUG"
    config.quic_bind = ["localhost:4433"]
    app = create_app()
    app = cors(app, allow_credentials=True, allow_origin="https://localhost:4433")
    asyncio.run(serve(app, config))
    async with app.app_context():
       yield

@pytest.mark.asyncio
async def test_tokengeneration_pass(app_context):
    """ JWT token generation should pass with valid user input parameter """
    token = Authentication.generate_token("test_user")
    assert type(token) is str
    assert token != ""

Error:

E           RuntimeError: Not within an app context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant