# Path: crispy_forms_foundation/layout/base.py
# class Layout(crispy_forms_layout.Layout):
#     pass
# 
# Path: crispy_forms_foundation/layout/buttons.py
# class ButtonGroup(crispy_forms_layout.LayoutObject):
#     """
#     It wraps fields in an element ``<div class="button-group">``.
# 
#     This is where you should put Layout objects that render to form buttons
#     like Submit. It should only hold `HTML` and `BaseInput` inherited objects.
# 
#     Example:
# 
#     .. sourcecode:: python
# 
#         ButtonGroup(
#             Submit('Save', 'Save'),
#             Button('Cancel', 'Cancel'),
#         )
#     """
#     template = "%s/layout/buttongroup.html"
# 
#     def __init__(self, *fields, **kwargs):
#         self.fields = list(fields)
#         self.css_class = kwargs.get('css_class', None)
#         self.css_id = kwargs.get('css_id', None)
#         self.template = kwargs.get('template', self.template)
# 
#     def render(self, form, form_style, context, template_pack=TEMPLATE_PACK):
#         field_list = []
#         template = self.get_template_name(template_pack)
# 
#         for field in self.fields:
#             field_list.append(
#                 render_field(field, form, form_style, context,
#                              template_pack=template_pack)
#             )
# 
#         buttons = render_to_string(template, {
#             'buttongroup': self,
#             'field_list': field_list,
#         })
# 
#         return buttons
# 
# class Button(InputButton):
#     """
#     This is the old Button object that inherit from ``InputButton`` for
#     backward compatibility.
# 
#     If you want to stand for an input button, you are invited to use
#     ``InputButton`` instead to avoid problem when ``ButtonElement`` will
#     become the new ``Button`` object.
#     """
#     pass
# 
# class Submit(InputSubmit):
#     """
#     This is the old Button object that inherit from ``InputSubmit`` for
#     backward compatibility.
# 
#     If you want to stand for an input button, you are invited to use
#     ``InputSubmit`` instead to avoid problem when ``ButtonSubmit`` will
#     become the new ``Submit`` object.
#     """
#     pass
# 
# class ButtonElement(crispy_forms_layout.BaseInput):
#     """
#     Contrary to ``Button``, ButtonElement purpose use a ``<button>`` element
#     to create a clickable form button and accept an argument to add free
#     content inside element.
# 
#     Advantage of ``<button>`` is to accept almost any HTML content inside
#     element.
# 
#     .. sourcecode:: python
# 
#         button = ButtonElement('name', 'value',
#                                content="<span>Press Me!</span>")
# 
#     .. note::
#             * First argument is for ``name`` attribute and also turned into
#               the id for the button;
#             * Second argument is for ``value`` attribute and also for element
#               content if not given;
#             * Third argument is an optional named argument ``content``, if
#               given it will be appended inside element instead of ``value``.
#               Content string is marked as safe so you can put anything you
#               want;
#     """
#     template = "%s/layout/basebutton.html"
#     input_type = 'button'
#     field_classes = 'button'
# 
#     def __init__(self, field, *args, **kwargs):
#         self.content = kwargs.pop('content', None)
#         super(ButtonElement, self).__init__(field, *args, **kwargs)
# 
#     def render(self, form, form_style, context, template_pack=TEMPLATE_PACK):
#         context['button_content'] = self.content
#         return super(ButtonElement, self).render(form, form_style, context,
#                                                  template_pack)
# 
# class ButtonSubmit(ButtonElement):
#     """
#     Create a submit button following the ``ButtonElement`` behaviors:
# 
#     .. sourcecode:: python
# 
#         button = ButtonSubmit('search', 'go-search',
#                               content="<span>Search this site!</span>")
# 
#     """
#     input_type = 'submit'
#     field_classes = 'submit button'
# 
# Path: tests/forms.py
# class BasicInputForm(forms.Form):
#     """
#     Basic form with a single CharField field
#     """
#     simple = forms.CharField(label='Simple text',
#                              widget=forms.TextInput(attrs={'required':''}),
#                              required=True)
# 
#     def save(self, commit=True):
#         return


import os
import pytest
from django.test.html import parse_html
from crispy_forms_foundation.layout import (Layout, ButtonGroup,
                                            Submit, Button,
                                            ButtonElement, ButtonSubmit)
from tests.forms import BasicInputForm


#from tests.utils import write_output


def test_buttongroup(output_test_path, render_output, rendered_template,
                     helper, client):
    form = BasicInputForm()
    pack = helper.template_pack

    helper.layout = Layout(
        'simple',
        ButtonGroup(
            Submit('Save', 'Save'),
            Button('Cancel', 'Cancel'),
        )
    )

    rendered = rendered_template(form, helper=helper)

    attempted = render_output(os.path.join(output_test_path, pack,
                                           "test_buttongroup.html"))
    #write_output(output_test_path, pack, "test_buttongroup.html", rendered)

    assert parse_html(attempted) == parse_html(rendered)


def test_buttonelement(output_test_path, render_output, rendered_template,
                     helper, client):

# Path: crispy_forms_foundation/layout/base.py
# class Layout(crispy_forms_layout.Layout):
#     pass
# 
# Path: crispy_forms_foundation/layout/buttons.py
# class ButtonGroup(crispy_forms_layout.LayoutObject):
#     """
#     It wraps fields in an element ``<div class="button-group">``.
# 
#     This is where you should put Layout objects that render to form buttons
#     like Submit. It should only hold `HTML` and `BaseInput` inherited objects.
# 
#     Example:
# 
#     .. sourcecode:: python
# 
#         ButtonGroup(
#             Submit('Save', 'Save'),
#             Button('Cancel', 'Cancel'),
#         )
#     """
#     template = "%s/layout/buttongroup.html"
# 
#     def __init__(self, *fields, **kwargs):
#         self.fields = list(fields)
#         self.css_class = kwargs.get('css_class', None)
#         self.css_id = kwargs.get('css_id', None)
#         self.template = kwargs.get('template', self.template)
# 
#     def render(self, form, form_style, context, template_pack=TEMPLATE_PACK):
#         field_list = []
#         template = self.get_template_name(template_pack)
# 
#         for field in self.fields:
#             field_list.append(
#                 render_field(field, form, form_style, context,
#                              template_pack=template_pack)
#             )
# 
#         buttons = render_to_string(template, {
#             'buttongroup': self,
#             'field_list': field_list,
#         })
# 
#         return buttons
# 
# class Button(InputButton):
#     """
#     This is the old Button object that inherit from ``InputButton`` for
#     backward compatibility.
# 
#     If you want to stand for an input button, you are invited to use
#     ``InputButton`` instead to avoid problem when ``ButtonElement`` will
#     become the new ``Button`` object.
#     """
#     pass
# 
# class Submit(InputSubmit):
#     """
#     This is the old Button object that inherit from ``InputSubmit`` for
#     backward compatibility.
# 
#     If you want to stand for an input button, you are invited to use
#     ``InputSubmit`` instead to avoid problem when ``ButtonSubmit`` will
#     become the new ``Submit`` object.
#     """
#     pass
# 
# class ButtonElement(crispy_forms_layout.BaseInput):
#     """
#     Contrary to ``Button``, ButtonElement purpose use a ``<button>`` element
#     to create a clickable form button and accept an argument to add free
#     content inside element.
# 
#     Advantage of ``<button>`` is to accept almost any HTML content inside
#     element.
# 
#     .. sourcecode:: python
# 
#         button = ButtonElement('name', 'value',
#                                content="<span>Press Me!</span>")
# 
#     .. note::
#             * First argument is for ``name`` attribute and also turned into
#               the id for the button;
#             * Second argument is for ``value`` attribute and also for element
#               content if not given;
#             * Third argument is an optional named argument ``content``, if
#               given it will be appended inside element instead of ``value``.
#               Content string is marked as safe so you can put anything you
#               want;
#     """
#     template = "%s/layout/basebutton.html"
#     input_type = 'button'
#     field_classes = 'button'
# 
#     def __init__(self, field, *args, **kwargs):
#         self.content = kwargs.pop('content', None)
#         super(ButtonElement, self).__init__(field, *args, **kwargs)
# 
#     def render(self, form, form_style, context, template_pack=TEMPLATE_PACK):
#         context['button_content'] = self.content
#         return super(ButtonElement, self).render(form, form_style, context,
#                                                  template_pack)
# 
# class ButtonSubmit(ButtonElement):
#     """
#     Create a submit button following the ``ButtonElement`` behaviors:
# 
#     .. sourcecode:: python
# 
#         button = ButtonSubmit('search', 'go-search',
#                               content="<span>Search this site!</span>")
# 
#     """
#     input_type = 'submit'
#     field_classes = 'submit button'
# 
# Path: tests/forms.py
# class BasicInputForm(forms.Form):
#     """
#     Basic form with a single CharField field
#     """
#     simple = forms.CharField(label='Simple text',
#                              widget=forms.TextInput(attrs={'required':''}),
#                              required=True)
# 
#     def save(self, commit=True):
#         return


# Path: tests/004_buttons.py
import os
import pytest
from django.test.html import parse_html
from crispy_forms_foundation.layout import (Layout, ButtonGroup,
                                            Submit, Button,
                                            ButtonElement, ButtonSubmit)
from tests.forms import BasicInputForm



#from tests.utils import write_output


def test_buttongroup(output_test_path, render_output, rendered_template,
                     helper, client):
    form = BasicInputForm()
    pack = helper.template_pack

    helper.layout = Layout(
        'simple',
        ButtonGroup(
            Submit('Save', 'Save'),
            Button('Cancel', 'Cancel'),
        )
    )

    rendered = rendered_template(form, helper=helper)

    attempted = render_output(os.path.join(output_test_path, pack,
                                           "test_buttongroup.html"))
    #write_output(output_test_path, pack, "test_buttongroup.html", rendered)

    assert parse_html(attempted) == parse_html(rendered)


def test_buttonelement(output_test_path, render_output, rendered_template,
                     helper, client):

    form = BasicInputForm()