# Auto generated by Kolo{% if now %} at {{ now }}{% endif %}.
# Kolo version: {{ kolo_version }}
{% if django_version %}# Django version: {{ django_version }}{% endif %}
{%- for trace_id in _traces %}
# Trace ID: {{ trace_id }}
{%- endfor %}

import json
{% for import in value_imports %}{{ import }}
{% endfor %}
{{ time_travel_import }}
import pytest
from django.utils.http import urlencode
from mocket import mocketize
from mocket.mockhttp import Entry
from pytest_django.asserts import assertTemplateUsed

{% for import in imports %}{{ import }}
{% endfor %}

@mocketize(strict_mode=True)
@pytest.mark.django_db()
def {{ test_name }}(client):
    {%- for section in sections %}
    {%- if section.request_timestamp %}
    with {{ time_travel_call }}("{{ section.request_timestamp }}"{{ time_travel_tick }}):{% endif %}
        {%- if section.sql_fixtures or section.outbound_request_frames or section.response or section.asserts %}
        {%- for fixture in section.sql_fixtures %}
        {%- for line in fixture.template_parts %}
        {{ line }}
        {%- endfor %}
        {%- endfor %}
        {%- if section.sql_fixtures %}

        {% endif %}
        {%- for outbound_request in section.outbound_request_frames %}
        Entry.single_register(
            Entry.{{outbound_request.request.method}},
            "{{outbound_request.request.url}}",
            status={{outbound_request.response.status_code}},{% if outbound_request.response.json_body %}
            body=json.dumps({{ outbound_request.response.json_body }}),{% elif outbound_request.response.body != None %}
            body={{ outbound_request.response.body.__repr__() }},{% endif %}{% if outbound_request.response.content_type %}
            headers={"Content-Type": {{ outbound_request.response.content_type.__repr__() }}},{% endif %}
        )
        {% endfor %}
        {%- if section.response %}
        response = client.{{ section.request.method.lower() }}(
            "{{ section.request.path_info }}",
            {{ section.query_params }}{{ section.prettified_request_body }},
            {%- for header, value in section.request_headers.items() %}
            {{ header }}={{ value.__repr__() }},
            {% endfor %}
        )

        assert response.status_code == {{ section.response.status_code }}
        {%- if section.response_json %}
        assert response.json() == {{ section.response_json }}
        {%- endif %}

        {%- for name in section.template_names %}
        assertTemplateUsed(response, {{ name.__repr__() }})
        {%- endfor %}
        {% endif %}
        {%- for fixture in section.asserts %}
        {%- for line in fixture.pytest_template_parts %}
        {{ line }}
        {%- endfor %}
        {%- endfor %}
        {% else %}
        pass
        {% endif %}
    {% endfor %}
