<s> from __future__ import unicode_literals <EOL> try : <EOL> from urllib import parse as urlparse <EOL> except ImportError : <EOL> import urlparse <EOL> from django . forms . models import modelform_factory <EOL> from django . test import TestCase <EOL> from django . utils import safestring <EOL> from django . utils . html import escape <EOL> from django_countries import widgets , countries , fields <EOL> from django_countries . conf import settings <EOL> from django_countries . tests . models import Person <EOL> class TestCountrySelectWidget ( TestCase ) : <EOL> def setUp ( self ) : <EOL> del countries . countries <EOL> self . Form = modelform_factory ( <EOL> Person , fields = [ '<STR_LIT>' ] , <EOL> widgets = { '<STR_LIT>' : widgets . CountrySelectWidget } ) <EOL> def tearDown ( self ) : <EOL> del countries . countries <EOL> def test_not_default_widget ( self ) : <EOL> Form = modelform_factory ( Person , fields = [ '<STR_LIT>' ] ) <EOL> widget = Form ( ) . fields [ '<STR_LIT>' ] . widget <EOL> self . assertFalse ( isinstance ( widget , widgets . CountrySelectWidget ) ) <EOL> def test_render_contains_flag_url ( self ) : <EOL> with self . settings ( COUNTRIES_ONLY = { '<STR_LIT>' : '<STR_LIT>' } ) : <EOL> html = self . Form ( ) . as_p ( ) <EOL> self . assertIn ( escape ( urlparse . urljoin ( <EOL> settings . STATIC_URL , settings . COUNTRIES_FLAG_URL ) ) , html ) <EOL> def test_render ( self ) : <EOL> with self . settings ( COUNTRIES_ONLY = { '<STR_LIT>' : '<STR_LIT>' } ) : <EOL> html = self . Form ( ) . as_p ( ) <EOL> self . assertIn ( fields . Country ( '<STR_LIT>' ) . flag , html ) <EOL> self . assertNotIn ( fields . Country ( '<STR_LIT>' ) . flag , html ) <EOL> def test_render_initial ( self ) : <EOL> with self . settings ( COUNTRIES_ONLY = { '<STR_LIT>' : '<STR_LIT>' } ) : <EOL> html = self . Form ( initial = { '<STR_LIT>' : '<STR_LIT>' } ) . as_p ( ) <EOL> self . assertIn ( fields . Country ( '<STR_LIT>' ) . flag , html ) <EOL> self . assertNotIn ( fields . Country ( '<STR_LIT>' ) . flag , html ) <EOL> def test_render_escaping ( self ) : <EOL> output = widgets . CountrySelectWidget ( ) . render ( '<STR_LIT:test>' , '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT>' , output ) <EOL> self . assertNotIn ( '<STR_LIT>' , output ) <EOL> self . assertTrue ( isinstance ( output , safestring . SafeData ) ) <EOL> def test_render_modelform_instance ( self ) : <EOL> person = Person ( country = '<STR_LIT>' ) <EOL> self . Form ( instance = person ) . as_p ( ) </s>
