Skip to content

1.16.0

Compare
Choose a tag to compare
@dantownsend dantownsend released this 08 Aug 13:02
· 34 commits to master since this release

Added custom async TestCase subclasses, to help with testing.

For example AsyncTransactionTest, which wraps each test in a transaction automatically:

class TestBandEndpoint(AsyncTransactionTest):

    async def test_band_response(self):
        """
        Make sure the endpoint returns a 200.
        """
        # This data automatically gets removed from the database when the
        # test finishes:
        band = Band({Band.name: "Pythonistas"})
        await band.save()

        # Using an API testing client, like httpx:
        response = await client.get(f"/bands/{band.id}/")
        self.assertEqual(response.status_code, 200)

And AsyncTableTest, which automatically creates and drops tables:

class TestBand(AsyncTableTest):

    # These tables automatically get created and dropped:
    tables = [Band]

    async def test_band(self):
        ...