Skip to content

Commit

Permalink
Add tests for deconstruct of CountriesField
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphje committed Dec 31, 2016
1 parent 5c37d9f commit ccfe036
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
24 changes: 22 additions & 2 deletions tests/test_countries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
from __future__ import unicode_literals
from django.test import SimpleTestCase
from django.utils import translation

from internationalflavor.countries import CountryField
from internationalflavor.countries import CountryFormField


class CountriesTestCase(SimpleTestCase):
class CountriesFormTestCase(SimpleTestCase):
def test_form_field(self):
field = CountryFormField(countries=['NL', 'BE', 'FR'])
self.assertEqual(set([f[0] for f in field.choices]), set(['BE', 'FR', 'NL']))
Expand All @@ -25,4 +27,22 @@ def test_form_field_render(self):
<option value="CF">Zentralafrikanische Republik</option>
</select>'''

self.assertHTMLEqual(field.widget.render('countries', 'NL'), out)
self.assertHTMLEqual(field.widget.render('countries', 'NL'), out)


class CountriesModelTestCase(SimpleTestCase):
def test_deconstruct_default(self):
# test_instance must be created with the non-default options.
test_inst = CountryField()
name, path, args, kwargs = test_inst.deconstruct()
new_inst = CountryField(*args, **kwargs)
for attr in ('countries', 'exclude', 'choices'):
self.assertEqual(getattr(test_inst, attr), getattr(new_inst, attr))

def test_deconstruct_different(self):
# test_instance must be created with the non-default options.
test_inst = CountryField(countries=['NL', 'BE'], exclude=['BE'])
name, path, args, kwargs = test_inst.deconstruct()
new_inst = CountryField(*args, **kwargs)
for attr in ('countries', 'exclude', 'choices'):
self.assertEqual(getattr(test_inst, attr), getattr(new_inst, attr))
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ envlist =
docs,
{py27,py33,py34}-1.7,
{py27,py33,py34,py35}-1.8
{py27,py34,py35}-{1.9,master}
{py27,py34,py35}-{1.9,1.10,master}

[testenv]
basepython =
Expand Down

0 comments on commit ccfe036

Please sign in to comment.