Assertion Helpers

djangosdk.testing.assertions provides helper functions that produce clear, descriptive failure messages when agent behavior does not match expectations.

assert_prompt_sent

Assert that the agent sent a prompt containing a given substring to the provider.

from djangosdk.testing.assertions import assert_prompt_sent
from djangosdk.testing.fakes import FakeProvider, override_ai_provider

def test_prompt_contains_order_id():
    fake = FakeProvider(text="Order found.")

    with override_ai_provider(fake):
        agent.handle("What is the status of order #XYZ789?")

    assert_prompt_sent(fake, "XYZ789")

Raises AssertionError with a descriptive message showing all prompts received if the substring is not found.

assert_tool_called

Assert that the agent triggered a specific tool with the expected arguments.

from djangosdk.testing.assertions import assert_tool_called

fake = FakeProvider(
    text="Done.",
    tool_calls=[{"id": "1", "name": "cancel_order", "arguments": {"order_id": "XYZ"}}],
)

with override_ai_provider(fake):
    agent.handle("Cancel order XYZ")

assert_tool_called(fake, "cancel_order", order_id="XYZ")

assert_model_used

Assert that every provider call used a specific model.

assert_system_prompt_contains

Assert that the system prompt sent to the provider contains a given substring.

Full Test Example

Last updated

Was this helpful?