# 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 }}
{% if base_test_case == "TestCase" %}from django.test import TestCase{% endif %}
from django.utils.http import urlencode
from mocket import mocketize
from mocket.mockhttp import Entry

{% 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 %}
    @mocketize(strict_mode=True)
    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.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 = self.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 %}
            )

            self.assertEqual(response.status_code, {{ section.response.status_code }})
            {%- if section.response_json %}
            self.assertEqual(response.json(), {{ section.response_json }})
            {%- endif %}

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