Skip to content

fixtures

django_spire.testing.playwright.fixtures

pytest_configure

Source code in django_spire/testing/playwright/fixtures.py
def pytest_configure(config: Any) -> None:
    del config
    os.environ['DJANGO_ALLOW_ASYNC_UNSAFE'] = 'true'

authenticated_page

Source code in django_spire/testing/playwright/fixtures.py
@pytest.fixture
def authenticated_page(page: Page, live_server: _LiveServer, transactional_db: None) -> Page:
    del transactional_db

    password = b'testpass123'.decode()
    get_user_model().objects.create_user(
        username='testuser', password=password, is_staff=True, is_superuser=True
    )

    login_url = reverse('admin:login')
    index_url = reverse('admin:index')

    page.goto(f'{live_server.url}{login_url}')
    page.fill('input[name="username"]', 'testuser')
    page.fill('input[name="password"]', password)
    page.click('input[type="submit"]')
    page.wait_for_url(f'{live_server.url}{index_url}')

    return page

e2e_user

The superuser a limelight demo signs in as. Override downstream to change role.

Source code in django_spire/testing/playwright/fixtures.py
@pytest.fixture
def e2e_user(transactional_db: None) -> Any:
    """The superuser a limelight demo signs in as. Override downstream to change role."""
    del transactional_db

    return get_user_model().objects.create_superuser(username='limelight')

limelight_application

Limelight's handle on the running app; pair with demo_start.

Source code in django_spire/testing/playwright/fixtures.py
@pytest.fixture
def limelight_application(live_server: _LiveServer) -> DjangoApplication:
    """Limelight's handle on the running app; pair with ``demo_start``."""
    return DjangoApplication(live_server=live_server)

demo_start

Factory for a limelight Demo. Its transcript and screenshots land under .demos/<test name>/ (silent runs write nothing).

def test_something(demo_start):
    demo = demo_start()
    demo.goto('app:page:list')
Source code in django_spire/testing/playwright/fixtures.py
@pytest.fixture
def demo_start(
    page: Page,
    limelight_application: DjangoApplication,
    e2e_user: Any,
    request: pytest.FixtureRequest,
) -> Callable[..., Demo]:
    """
    Factory for a limelight ``Demo``. Its transcript and screenshots land under
    ``.demos/<test name>/`` (silent runs write nothing).

        def test_something(demo_start):
            demo = demo_start()
            demo.goto('app:page:list')
    """

    def start(**kwargs: Any) -> Demo:
        kwargs.setdefault('name', re.sub(r'[^\w.-]+', '_', request.node.name))
        kwargs.setdefault('user', e2e_user)

        return Demo(page, limelight_application, **kwargs)

    return start