Skip to content

Instantly share code, notes, and snippets.

@SarahElson
Created October 1, 2024 11:11
Show Gist options
  • Save SarahElson/1833ebb1f76fc6ab735a54baa919f6d2 to your computer and use it in GitHub Desktop.
Save SarahElson/1833ebb1f76fc6ab735a54baa919f6d2 to your computer and use it in GitHub Desktop.
Python Asyncio Tutorial: A Complete Guide
import pytest
import aiohttp
import sys
import os
# Add the project directory to the system path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'app')))
from fastapi.testclient import TestClient
from main import app # Import the app from app/main.py
client = TestClient(app)
@pytest.mark.asyncio
async def test_fetch_builds():
async with aiohttp.ClientSession() as session:
response = client.get("/builds/")
assert response.status_code == 200
data = response.json()
assert "dashboard_urls" in data
assert isinstance(data["dashboard_urls"], list)
@pytest.mark.asyncio
async def test_fetch_sessions():
async with aiohttp.ClientSession() as session:
response = client.get("/sessions/")
assert response.status_code == 200
data = response.json()
assert "session_names" in data
assert isinstance(data["session_names"], list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment