# Path: tests/compat.py
# class RequestFactory:
#     def method(self, method, url, params, body=None, root_path=None, **headers):
#     def get(self, url, params=None, **headers):
#     def post(self, url, params=None, **headers):


import pytest
from tri_struct import merged
from tri_form import Field, Form
from tri_form.compat import render_to_string, format_html, field_defaults_factory, render_template, Template
from .compat import RequestFactory, SafeText
    from django.db import models
    from django.db import models
def test_format_html3():
    assert render_template(RequestFactory().get('/'), Template('{{foo}}'), dict(foo=format_html('{}', format_html('<a href="foo">foo</a>')))) == '<a href="foo">foo</a>'


def test_format_html4():
    actual = render_template(
        RequestFactory().get('/'),
        Template('{{foo}}'),
        dict(
            foo=Form(fields=[Field(name='foo')]),
        )
    )
    print(actual)
    assert '<input type="text" value="" name="foo" id="id_foo"' in actual


def test_format_html5():
    actual = Form(fields=[Field(name='foo')], request=RequestFactory().get('/')).render()
    print(actual)
    assert type(actual) == SafeText


def test_format_html6():
    form = Form(fields=[Field(name='foo')], request=RequestFactory().get('/'))
    actual = form.fields_by_name.foo.render()
    print(actual)
    assert type(actual) == SafeText


def test_render_template():

# Path: tests/compat.py
# class RequestFactory:
#     def method(self, method, url, params, body=None, root_path=None, **headers):
#     def get(self, url, params=None, **headers):
#     def post(self, url, params=None, **headers):


# Path: tests/test_compat.py
import pytest
from tri_struct import merged
from tri_form import Field, Form
from tri_form.compat import render_to_string, format_html, field_defaults_factory, render_template, Template
from .compat import RequestFactory, SafeText
    from django.db import models
    from django.db import models

def test_format_html3():
    assert render_template(RequestFactory().get('/'), Template('{{foo}}'), dict(foo=format_html('{}', format_html('<a href="foo">foo</a>')))) == '<a href="foo">foo</a>'


def test_format_html4():
    actual = render_template(
        RequestFactory().get('/'),
        Template('{{foo}}'),
        dict(
            foo=Form(fields=[Field(name='foo')]),
        )
    )
    print(actual)
    assert '<input type="text" value="" name="foo" id="id_foo"' in actual


def test_format_html5():
    actual = Form(fields=[Field(name='foo')], request=RequestFactory().get('/')).render()
    print(actual)
    assert type(actual) == SafeText


def test_format_html6():
    form = Form(fields=[Field(name='foo')], request=RequestFactory().get('/'))
    actual = form.fields_by_name.foo.render()
    print(actual)
    assert type(actual) == SafeText


def test_render_template():

    actual = render_template(RequestFactory().get('/'), Template('{{foo}}'), dict(foo=1))