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

import datetime

{{ time_travel_import }}
import httpretty
import json

import pytest
from django.utils.http import urlencode
from pytest_django.asserts import assertTemplateUsed

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

@httpretty.activate(allow_net_connect=False)
@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.test_client_call_pytest or section.asserts %}
        {% for fixture in section.sql_fixtures %}
        {%- for line in fixture.template_parts %}
        {{ line }}
        {%- endfor %}
        {% endfor %}
        {% for outbound_request in section.outbound_request_frames %}httpretty.register_uri(
            httpretty.{{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 }}),{% else %}
            body={{ outbound_request.response.body.__repr___() }},{% endif %}
            content_type={{ outbound_request.response.content_type.__repr__() }},
        )
        {% endfor %}
        {% if section.test_client_call_pytest %}
        response = {{ section.test_client_call_pytest }}

        assert response.status_code == {{ section.response.status_code }}

        {%- 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 %}
