# -*- coding: utf-8 -*- from django.test import TestCase from forms import MXPersonProfileForm class MXLocalFlavorTests(TestCase): def setUp(self): self.form = MXPersonProfileForm({ 'state': 'MIC', 'rfc': 'toma880125kv3', 'curp': 'toma880125hmnrrn02', 'zip_code': '58120', }) def test_get_display_methods(self): """Test that the get_*_display() methods are added to the model instances.""" place = self.form.save() self.assertEqual(place.get_state_display(), u'Michoacán') def test_errors(self): """Test that required MXFields throw appropriate errors.""" form = MXPersonProfileForm({ 'state': 'Invalid state', 'rfc': 'invalid rfc', 'curp': 'invalid curp', 'zip_code': 'xxx', }) self.assertFalse(form.is_valid()) self.assertEqual(form.errors['state'], [u'Select a valid choice. Invalid state is not one of the available choices.']) self.assertEqual(form.errors['rfc'], [u'Enter a valid RFC.']) self.assertEqual(form.errors['curp'], [u'Ensure this value has at least 18 characters (it has 12).', u'Enter a valid CURP.']) self.assertEqual(form.errors['zip_code'], [u'Enter a valid zip code in the format XXXXX.']) def test_field_blank_option(self): """Test that the empty option is there.""" state_select_html = """\ """ self.assertEqual(str(self.form['state']), state_select_html)