15.13. AsyncIO Testing

15.13.1. Case Study

from unittest import TestCase
import httpx


def fetch(path):
    client = httpx.Client(base_url='https://python3.info')
    response = client.get(path)
    return response.text


class WebsiteTest(TestCase):
    def test_index(self):
        html = fetch('/index.html')
        self.assertIn('Python - from None to AI', html)

    def test_license(self):
        html = fetch('/LICENSE.html')
        self.assertIn('Creative Commons Public Licenses', html)
        self.assertIn('Attribution-ShareAlike 4.0 International', html)

    def test_install(self):
        html = fetch('/install.html')
        self.assertIn('Python 3.13', html)
        self.assertIn('PyCharm 2024.2', html)
        self.assertIn('Git 2.47', html)
        self.assertIn('konto na Github', html)
from unittest import IsolatedAsyncioTestCase
import httpx


async def fetch(path):
    client = httpx.AsyncClient(base_url='https://python3.info')
    response = await client.get(path)
    return response.text


class WebsiteTest(IsolatedAsyncioTestCase):
    async def test_index(self):
        html = await fetch('/index.html')
        self.assertIn('Python - from None to AI', html)

    async def test_license(self):
        html = await fetch('/LICENSE.html')
        self.assertIn('Creative Commons Public Licenses', html)
        self.assertIn('Attribution-ShareAlike 4.0 International', html)

    async def test_install(self):
        html = await fetch('/install.html')
        self.assertIn('Python 3.13', html)
        self.assertIn('PyCharm 2024.2', html)
        self.assertIn('Git 2.47', html)
        self.assertIn('konto na Github', html)