# 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

{% if base_test_case == "TestCase" %}from django.test import TestCase{% endif %}
from django.utils.http import urlencode

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

class {{ test_class }}({{base_test_case}}):
    {% if custom_unittest_setup %}
    {# Jinja does weird stuff with multiline strings, so we need the filter to guarantee we get our desired indent #}
    {% filter indent(4, true) %}
{{ custom_unittest_setup }}
    {% endfilter %}
    {% endif %}
    @httpretty.activate(allow_net_connect=False)
    def {{ test_name }}(self):
        {% 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 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 %}
            response = {{ section.test_client_call }}

            self.assertEqual(response.status_code, {{ section.response.status_code }})

            {%- for name in section.template_names %}
            self.assertTemplateUsed(response, {{ name.__repr__() }})
            {%- endfor %}
            {% endif %}

            {% for fixture in section.asserts %}
            {%- for line in fixture.template_parts %}
            {{ line }}
            {%- endfor %}
            {% endfor %}
            {% else %}
            pass
            {% endif %}
        {% endfor %}
