<s> from __future__ import absolute_import <EOL> from django . test import TestCase <EOL> from django . test . client import RequestFactory <EOL> from django import forms <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from . . widgy_config import widgy_site <EOL> from . . models import ( <EOL> VariegatedFieldsWidget , VerboseNameLayout , <EOL> VerboseNameLayoutChild , WidgetWithHTMLHelpText , <EOL> ) <EOL> from widgy . widgets import DateTimeWidget , DateWidget , TimeWidget <EOL> from widgy . forms import WidgyFormField <EOL> factory = RequestFactory ( ) <EOL> class TestFormCreation ( TestCase ) : <EOL> def test_field_with_choices ( self ) : <EOL> widget = VariegatedFieldsWidget . add_root ( widgy_site ) <EOL> form_class = widget . get_form_class ( request = None ) ( ) <EOL> self . assertIsInstance ( form_class . fields [ '<STR_LIT>' ] . widget , forms . Select ) <EOL> def test_date_fields ( self ) : <EOL> widget = VariegatedFieldsWidget . add_root ( widgy_site ) <EOL> form_class = widget . get_form_class ( request = None ) ( ) <EOL> self . assertIsInstance ( form_class . fields [ '<STR_LIT:date>' ] . widget , DateWidget ) <EOL> self . assertIsInstance ( form_class . fields [ '<STR_LIT:time>' ] . widget , TimeWidget ) <EOL> self . assertIsInstance ( form_class . fields [ '<STR_LIT>' ] . widget , DateTimeWidget ) <EOL> class TestFieldAsDiv ( TestCase ) : <EOL> def test_field_as_div_allows_html_in_help_text ( self ) : <EOL> widget = WidgetWithHTMLHelpText . add_root ( widgy_site ) <EOL> request = factory . get ( '<STR_LIT:/>' ) <EOL> rendered_form = widget . get_form_template ( request ) <EOL> self . assertIn ( '<STR_LIT>' , rendered_form ) <EOL> class TestWidgyFormField ( TestCase ) : <EOL> def test_content_type_radio_labels ( self ) : <EOL> ct1 = ContentType . objects . get_for_model ( VerboseNameLayout ) <EOL> ct2 = ContentType . objects . get_for_model ( VerboseNameLayoutChild ) <EOL> VerboseNameLayoutChild . _meta . verbose_name = '<STR_LIT>' <EOL> field = WidgyFormField ( <EOL> site = widgy_site , <EOL> queryset = ContentType . objects . filter ( pk__in = [ ct1 . pk , ct2 . pk ] ) . order_by ( '<STR_LIT>' ) , <EOL> ) <EOL> field . conform_to_value ( owner = None , value = None ) <EOL> self . assertSequenceEqual ( list ( field . widget . choices ) , sorted ( [ <EOL> ( ct1 . pk , '<STR_LIT>' ) , <EOL> ( ct2 . pk , '<STR_LIT>' ) , <EOL> ] ) ) </s>
