Skip to main content

iil-testkit

Shared Test Factory Package for all Platform Django reposADR-100

PyPI

Installation

pip install iil-testkit

In requirements-test.txt:

iil-testkit>=0.4.0

With DRF support:

iil-testkit[drf]>=0.4.0

Extras / Optional Dependencies

Extra Additional deps Purpose
drf djangorestframework>=3.14 DRF APIClient fixtures (drf_api_client, drf_auth_client)
django django>=4.2, pytest-django>=4.8 Explicit Django pin (normally pulled transitively)
smoke django, beautifulsoup4>=4.12 HTML smoke assertions

Quick Setup

In your tests/conftest.py:

pytest_plugins = ["iil_testkit.fixtures"]

Factories

# tests/factories.py — import shared, extend repo-specific
from iil_testkit.factories import UserFactory  # noqa: F401
import factory

class MyModelFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = "myapp.MyModel"
    user = factory.SubFactory(UserFactory)

For multi-tenant repos:

from iil_testkit.contrib.tenants import TenantFactory  # noqa: F401

Fixtures

Fixture Description
db_user Standard active user, saved to DB
staff_user User with is_staff=True
admin_user User with is_superuser=True
api_client Unauthenticated Django Client
auth_client Django Client logged in as db_user
staff_client Django Client logged in as staff_user
drf_api_client Unauthenticated DRF APIClient (skips if DRF missing)
drf_auth_client DRF APIClient authenticated as db_user (skips if DRF missing)
def test_should_view_dashboard(auth_client):
    response = auth_client.get("/dashboard/")
    assert response.status_code == 200

def test_should_require_auth(api_client):
    from iil_testkit.assertions import assert_redirects_to_login
    response = api_client.get("/protected/")
    assert_redirects_to_login(response)

Assertion Helpers

from iil_testkit.assertions import (
    assert_redirects_to_login,
    assert_htmx_response,
    assert_no_n_plus_one,
    assert_form_error,
)
Helper Description
assert_redirects_to_login(response) Asserts 301/302 to /login or /accounts/login
assert_htmx_response(response) Asserts no full <html> page in HTMX partial
assert_no_n_plus_one(queries, threshold=5) Asserts query count within threshold
assert_form_error(response, field, message) Asserts form field error in context

Naming Convention Plugin (ADR-057)

Auto-registered when installed. All test functions must follow test_should_*:

Naming convention violations — 1 test(s) must start with 'test_should_':
  tests/test_foo.py::test_login

Opt-out per test:

@pytest.mark.no_naming_convention
def test_legacy_name(): ...

Opt-out globally: pytest --relax-naming

Warn instead of error: iil_naming_mode = "warn" in pyproject.toml

Architecture

See ADR-100.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iil_testkit-0.6.0.tar.gz (46.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iil_testkit-0.6.0-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file iil_testkit-0.6.0.tar.gz.

File metadata

  • Download URL: iil_testkit-0.6.0.tar.gz
  • Upload date:
  • Size: 46.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for iil_testkit-0.6.0.tar.gz
Algorithm Hash digest
SHA256 4ff3f18a90afe0495800285cd39a6357204046750c34585c65f4674177caadf4
MD5 eca29a193b4363995d8a2cdedadcbb5d
BLAKE2b-256 9d0e61aa96f33f7289128d1e513d5103051dcbd91e41a8f442c9545ff3a72dff

See more details on using hashes here.

File details

Details for the file iil_testkit-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: iil_testkit-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 26.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for iil_testkit-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d6c0216e5fb535b569c110b94e2d8e61ce9ea31761918f68ac11793cfef3080f
MD5 6dc03b4189aa2dd0721b9854056ceb47
BLAKE2b-256 f1ffe382c3cc1f7677cf07880a569c3a431b032294fb8878c3e7e38132b3fa25

See more details on using hashes here.

Release history Release notifications | RSS feed

0.6.1

2 files

This release

0.6.0 This release

2 files

0.5.3

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page