Ticket #15838: 15838.1.2.diff

File 15838.1.2.diff, 36.0 KB (added by Ramiro Morales, 13 years ago)
  • django/test/testcases.py

    diff --git a/django/test/testcases.py b/django/test/testcases.py
    a b  
    88
    99from django.conf import settings
    1010from django.core import mail
     11from django.core.exceptions import ValidationError
    1112from django.core.management import call_command
    1213from django.core.signals import request_started
    1314from django.core.urlresolvers import clear_url_caches
     15from django.core.validators import EMPTY_VALUES
    1416from django.db import (transaction, connection, connections, DEFAULT_DB_ALIAS,
    1517    reset_queries)
     18from django.forms.fields import CharField
    1619from django.http import QueryDict
    1720from django.test import _doctest as doctest
    1821from django.test.client import Client
     
    271274        return self.assertRaisesRegexp(expected_exception,
    272275                re.escape(expected_message), callable_obj, *args, **kwargs)
    273276
     277    def assertFieldOutput(self, fieldclass, valid, invalid, field_args=None,
     278            field_kwargs=None, empty_value=u''):
     279        """
     280        Asserts that a form field behaves correctly with various inputs.
     281
     282        Args:
     283            fieldclass: the class of the field to be tested.
     284            valid: a dictionary mapping valid inputs to their expected
     285                    cleaned values.
     286            invalid: a dictionary mapping invalid inputs to one or more
     287                    raised error messages.
     288            field_args: the args passed to instantiate the field
     289            field_kwargs: the kwargs passed to instantiate the field
     290            empty_value: the expected clean output for inputs in EMPTY_VALUES
     291
     292        """
     293        if field_args is None:
     294            field_args = []
     295        if field_kwargs is None:
     296            field_kwargs = {}
     297        required = fieldclass(*field_args, **field_kwargs)
     298        optional = fieldclass(*field_args, **dict(field_kwargs, required=False))
     299        # test valid inputs
     300        for input, output in valid.items():
     301            self.assertEqual(required.clean(input), output)
     302            self.assertEqual(optional.clean(input), output)
     303        # test invalid inputs
     304        for input, errors in invalid.items():
     305            with self.assertRaises(ValidationError) as context_manager:
     306                required.clean(input)
     307            self.assertEqual(context_manager.exception.messages, errors)
     308
     309            with self.assertRaises(ValidationError) as context_manager:
     310                optional.clean(input)
     311            self.assertEqual(context_manager.exception.messages, errors)
     312        # test required inputs
     313        error_required = [u'This field is required.']
     314        for e in EMPTY_VALUES:
     315            with self.assertRaises(ValidationError) as context_manager:
     316                required.clean(e)
     317            self.assertEqual(context_manager.exception.messages, error_required)
     318            self.assertEqual(optional.clean(e), empty_value)
     319        # test that max_length and min_length are always accepted
     320        if issubclass(fieldclass, CharField):
     321            field_kwargs.update({'min_length':2, 'max_length':20})
     322            self.assertTrue(isinstance(fieldclass(*field_args, **field_kwargs), fieldclass))
     323
    274324class TransactionTestCase(SimpleTestCase):
    275325    # The class we'll use for the test client self.client.
    276326    # Can be overridden in derived classes.
     
    356406        # be created with the wrong time).
    357407        # To make sure this doesn't happen, get a clean connection at the
    358408        # start of every test.
    359         for connection in connections.all():
    360             connection.close()
     409        for conn in connections.all():
     410            conn.close()
    361411
    362412    def _fixture_teardown(self):
    363413        pass
     
    552602
    553603    def assertNumQueries(self, num, func=None, *args, **kwargs):
    554604        using = kwargs.pop("using", DEFAULT_DB_ALIAS)
    555         connection = connections[using]
     605        conn = connections[using]
    556606
    557         context = _AssertNumQueriesContext(self, num, connection)
     607        context = _AssertNumQueriesContext(self, num, conn)
    558608        if func is None:
    559609            return context
    560610
  • docs/topics/testing.txt

    diff --git a/docs/topics/testing.txt b/docs/topics/testing.txt
    a b  
    11781178
    11791179 * Saving and restoring the Python warning machinery state.
    11801180 * Checking that a callable :meth:`raises a certain exeception <TestCase.assertRaisesMessage>`.
     1181 * :meth:`Testing form field rendering <assertFieldOutput>`.
    11811182
    11821183If you need any of the other more complex and heavyweight Django-specific
    11831184features like:
     
    15221523    failure. Similar to unittest's ``assertRaisesRegexp`` with the difference
    15231524    that ``expected_message`` isn't a regular expression.
    15241525
     1526.. method:: assertFieldOutput(self, fieldclass, valid, invalid, field_args=None, field_kwargs=None, empty_value=u'')
     1527
     1528    Asserts that a form field behaves correctly with various inputs.
     1529
     1530    :param fieldclass: the class of the field to be tested.
     1531    :param valid: a dictionary mapping valid inputs to their expected cleaned
     1532        values.
     1533    :param invalid: a dictionary mapping invalid inputs to one or more raised
     1534        error messages.
     1535    :param field_args: the args passed to instantiate the field.
     1536    :param field_kwargs: the kwargs passed to instantiate the field.
     1537    :param empty_value: the expected clean output for inputs in ``EMPTY_VALUES``.
     1538
    15251539.. method:: TestCase.assertContains(response, text, count=None, status_code=200, msg_prefix='')
    15261540
    15271541    Asserts that a ``Response`` instance produced the given ``status_code`` and
  • tests/regressiontests/forms/localflavor/__init__.py

    diff --git a/tests/regressiontests/forms/localflavor/__init__.py b/tests/regressiontests/forms/localflavor/__init__.py
    a b  
    1 from django.forms import EmailField
    2 from utils import LocalFlavorTestCase
    3 
    4 class AssertFieldOutputTests(LocalFlavorTestCase):
    5 
    6     def test_assert_field_output(self):
    7         error_invalid = [u'Enter a valid e-mail address.']
    8         self.assertFieldOutput(EmailField, {'a@a.com': 'a@a.com'}, {'aaa': error_invalid})
    9         self.assertRaises(AssertionError, self.assertFieldOutput, EmailField, {'a@a.com': 'a@a.com'}, {'aaa': error_invalid + [u'Another error']})
    10         self.assertRaises(AssertionError, self.assertFieldOutput, EmailField, {'a@a.com': 'Wrong output'}, {'aaa': error_invalid})
    11         self.assertRaises(AssertionError, self.assertFieldOutput, EmailField, {'a@a.com': 'a@a.com'}, {'aaa': [u'Come on, gimme some well formatted data, dude.']})
     1#
  • tests/regressiontests/forms/localflavor/ar.py

    diff --git a/tests/regressiontests/forms/localflavor/ar.py b/tests/regressiontests/forms/localflavor/ar.py
    a b  
    11from django.contrib.localflavor.ar.forms import (ARProvinceSelect,
    22    ARPostalCodeField, ARDNIField, ARCUITField)
    33
    4 from utils import LocalFlavorTestCase
     4from django.test import SimpleTestCase
    55
    66
    7 class ARLocalFlavorTests(LocalFlavorTestCase):
     7class ARLocalFlavorTests(SimpleTestCase):
    88    def test_ARProvinceSelect(self):
    99        f = ARProvinceSelect()
    1010        out = u'''<select name="provincias">
  • tests/regressiontests/forms/localflavor/at.py

    diff --git a/tests/regressiontests/forms/localflavor/at.py b/tests/regressiontests/forms/localflavor/at.py
    a b  
    11from django.contrib.localflavor.at.forms import (ATZipCodeField, ATStateSelect,
    22    ATSocialSecurityNumberField)
    33
    4 from utils import LocalFlavorTestCase
     4from django.test import SimpleTestCase
    55
    66
    7 class ATLocalFlavorTests(LocalFlavorTestCase):
     7class ATLocalFlavorTests(SimpleTestCase):
    88    def test_ATStateSelect(self):
    99        f = ATStateSelect()
    1010        out = u'''<select name="bundesland">
  • tests/regressiontests/forms/localflavor/au.py

    diff --git a/tests/regressiontests/forms/localflavor/au.py b/tests/regressiontests/forms/localflavor/au.py
    a b  
    11from django.contrib.localflavor.au.forms import (AUPostCodeField,
    22        AUPhoneNumberField, AUStateSelect)
    33
    4 from utils import LocalFlavorTestCase
     4from django.test import SimpleTestCase
    55
    66
    7 class AULocalFlavorTests(LocalFlavorTestCase):
     7class AULocalFlavorTests(SimpleTestCase):
    88    def test_AUStateSelect(self):
    99        f = AUStateSelect()
    1010        out = u'''<select name="state">
  • tests/regressiontests/forms/localflavor/be.py

    diff --git a/tests/regressiontests/forms/localflavor/be.py b/tests/regressiontests/forms/localflavor/be.py
    a b  
    11from django.contrib.localflavor.be.forms import (BEPostalCodeField,
    22    BEPhoneNumberField, BERegionSelect, BEProvinceSelect)
    33
    4 from utils import LocalFlavorTestCase
     4from django.test import SimpleTestCase
    55
    66
    7 class BELocalFlavorTests(LocalFlavorTestCase):
     7class BELocalFlavorTests(SimpleTestCase):
    88    def test_BEPostalCodeField(self):
    99        error_format = [u'Enter a valid postal code in the range and format 1XXX - 9XXX.']
    1010        valid = {
  • tests/regressiontests/forms/localflavor/br.py

    diff --git a/tests/regressiontests/forms/localflavor/br.py b/tests/regressiontests/forms/localflavor/br.py
    a b  
    22    BRCNPJField, BRCPFField, BRPhoneNumberField, BRStateSelect,
    33    BRStateChoiceField)
    44
    5 from utils import LocalFlavorTestCase
     5from django.test import SimpleTestCase
    66
    77
    8 class BRLocalFlavorTests(LocalFlavorTestCase):
     8class BRLocalFlavorTests(SimpleTestCase):
    99    def test_BRZipCodeField(self):
    1010        error_format = [u'Enter a zip code in the format XXXXX-XXX.']
    1111        valid = {
  • tests/regressiontests/forms/localflavor/ca.py

    diff --git a/tests/regressiontests/forms/localflavor/ca.py b/tests/regressiontests/forms/localflavor/ca.py
    a b  
    44        CAPhoneNumberField, CAProvinceField, CAProvinceSelect,
    55        CASocialInsuranceNumberField)
    66
    7 from utils import LocalFlavorTestCase
     7from django.test import SimpleTestCase
    88
    99
    10 class CALocalFlavorTests(LocalFlavorTestCase):
     10class CALocalFlavorTests(SimpleTestCase):
    1111    def setUp(self):
    1212        self.save_warnings_state()
    1313        warnings.filterwarnings(
  • tests/regressiontests/forms/localflavor/ch.py

    diff --git a/tests/regressiontests/forms/localflavor/ch.py b/tests/regressiontests/forms/localflavor/ch.py
    a b  
    11from django.contrib.localflavor.ch.forms import (CHZipCodeField,
    22    CHPhoneNumberField, CHIdentityCardNumberField, CHStateSelect)
    33
    4 from utils import LocalFlavorTestCase
     4from django.test import SimpleTestCase
    55
    66
    7 class CHLocalFlavorTests(LocalFlavorTestCase):
     7class CHLocalFlavorTests(SimpleTestCase):
    88    def test_CHStateSelect(self):
    99        f = CHStateSelect()
    1010        out = u'''<select name="state">
  • tests/regressiontests/forms/localflavor/cl.py

    diff --git a/tests/regressiontests/forms/localflavor/cl.py b/tests/regressiontests/forms/localflavor/cl.py
    a b  
    11from django.contrib.localflavor.cl.forms import CLRutField, CLRegionSelect
    22
    3 from utils import LocalFlavorTestCase
     3from django.test import SimpleTestCase
    44
    55
    6 class CLLocalFlavorTests(LocalFlavorTestCase):
     6class CLLocalFlavorTests(SimpleTestCase):
    77    def test_CLRegionSelect(self):
    88        f = CLRegionSelect()
    99        out = u'''<select name="foo">
  • tests/regressiontests/forms/localflavor/cn.py

    diff --git a/tests/regressiontests/forms/localflavor/cn.py b/tests/regressiontests/forms/localflavor/cn.py
    a b  
    22
    33from django.contrib.localflavor.cn.forms import (CNProvinceSelect,
    44        CNPostCodeField, CNIDCardField, CNPhoneNumberField, CNCellNumberField)
    5 from utils import LocalFlavorTestCase
     5from django.test import SimpleTestCase
    66
    7 class CNLocalFlavorTests(LocalFlavorTestCase):
     7class CNLocalFlavorTests(SimpleTestCase):
    88    def test_CNProvinceSelect(self):
    99        f = CNProvinceSelect()
    1010        correct_output = u'''<select name="provinces">
  • tests/regressiontests/forms/localflavor/co.py

    diff --git a/tests/regressiontests/forms/localflavor/co.py b/tests/regressiontests/forms/localflavor/co.py
    a b  
    11from django.contrib.localflavor.co.forms import CODepartmentSelect
    22
    3 from utils import LocalFlavorTestCase
     3from django.test import SimpleTestCase
    44
    5 class COLocalFlavorTests(LocalFlavorTestCase):
     5class COLocalFlavorTests(SimpleTestCase):
    66    def test_CODepartmentSelect(self):
    77        d = CODepartmentSelect()
    88        out = u"""<select name="department">
  • tests/regressiontests/forms/localflavor/cz.py

    diff --git a/tests/regressiontests/forms/localflavor/cz.py b/tests/regressiontests/forms/localflavor/cz.py
    a b  
    44    CZRegionSelect, CZBirthNumberField, CZICNumberField)
    55
    66from django.core.exceptions import ValidationError
    7 from utils import LocalFlavorTestCase
     7from django.test import SimpleTestCase
    88
    99
    10 class CZLocalFlavorTests(LocalFlavorTestCase):
     10class CZLocalFlavorTests(SimpleTestCase):
    1111    def setUp(self):
    1212        self.save_warnings_state()
    1313        warnings.filterwarnings(
  • tests/regressiontests/forms/localflavor/de.py

    diff --git a/tests/regressiontests/forms/localflavor/de.py b/tests/regressiontests/forms/localflavor/de.py
    a b  
    11from django.contrib.localflavor.de.forms import (DEZipCodeField, DEStateSelect,
    22    DEIdentityCardNumberField)
    33
    4 from utils import LocalFlavorTestCase
     4from django.test import SimpleTestCase
    55
    66
    7 class DELocalFlavorTests(LocalFlavorTestCase):
     7class DELocalFlavorTests(SimpleTestCase):
    88    def test_DEStateSelect(self):
    99        f = DEStateSelect()
    1010        out = u'''<select name="states">
  • tests/regressiontests/forms/localflavor/ec.py

    diff --git a/tests/regressiontests/forms/localflavor/ec.py b/tests/regressiontests/forms/localflavor/ec.py
    a b  
    11from django.contrib.localflavor.ec.forms import ECProvinceSelect
    22
    3 from utils import LocalFlavorTestCase
     3from django.test import SimpleTestCase
    44
    5 class ECLocalFlavorTests(LocalFlavorTestCase):
     5class ECLocalFlavorTests(SimpleTestCase):
    66    def test_ECProvinceSelect(self):
    77        p = ECProvinceSelect()
    88        out = u"""<select name="province">
  • tests/regressiontests/forms/localflavor/es.py

    diff --git a/tests/regressiontests/forms/localflavor/es.py b/tests/regressiontests/forms/localflavor/es.py
    a b  
    11from django.contrib.localflavor.es.forms import (ESPostalCodeField, ESPhoneNumberField,
    22    ESIdentityCardNumberField, ESCCCField, ESRegionSelect, ESProvinceSelect)
    33
    4 from utils import LocalFlavorTestCase
     4from django.test import SimpleTestCase
    55
    66
    7 class ESLocalFlavorTests(LocalFlavorTestCase):
     7class ESLocalFlavorTests(SimpleTestCase):
    88    def test_ESRegionSelect(self):
    99        f = ESRegionSelect()
    1010        out = u'''<select name="regions">
  • tests/regressiontests/forms/localflavor/fi.py

    diff --git a/tests/regressiontests/forms/localflavor/fi.py b/tests/regressiontests/forms/localflavor/fi.py
    a b  
    11from django.contrib.localflavor.fi.forms import (FIZipCodeField,
    22    FISocialSecurityNumber, FIMunicipalitySelect)
    33
    4 from utils import LocalFlavorTestCase
     4from django.test import SimpleTestCase
    55
    66
    7 class FILocalFlavorTests(LocalFlavorTestCase):
     7class FILocalFlavorTests(SimpleTestCase):
    88    def test_FIMunicipalitySelect(self):
    99        f = FIMunicipalitySelect()
    1010        out = u'''<select name="municipalities">
  • tests/regressiontests/forms/localflavor/fr.py

    diff --git a/tests/regressiontests/forms/localflavor/fr.py b/tests/regressiontests/forms/localflavor/fr.py
    a b  
    11from django.contrib.localflavor.fr.forms import (FRZipCodeField,
    22        FRPhoneNumberField, FRDepartmentSelect)
    33
    4 from utils import LocalFlavorTestCase
     4from django.test import SimpleTestCase
    55
    66
    7 class FRLocalFlavorTests(LocalFlavorTestCase):
     7class FRLocalFlavorTests(SimpleTestCase):
    88    def test_FRZipCodeField(self):
    99        error_format = [u'Enter a zip code in the format XXXXX.']
    1010        valid = {
  • tests/regressiontests/forms/localflavor/gb.py

    diff --git a/tests/regressiontests/forms/localflavor/gb.py b/tests/regressiontests/forms/localflavor/gb.py
    a b  
    11from django.contrib.localflavor.gb.forms import GBPostcodeField
    22
    3 from utils import LocalFlavorTestCase
     3from django.test import SimpleTestCase
    44
    55
    6 class GBLocalFlavorTests(LocalFlavorTestCase):
     6class GBLocalFlavorTests(SimpleTestCase):
    77    def test_GBPostcodeField(self):
    88        error_invalid = [u'Enter a valid postcode.']
    99        valid = {
  • tests/regressiontests/forms/localflavor/generic.py

    diff --git a/tests/regressiontests/forms/localflavor/generic.py b/tests/regressiontests/forms/localflavor/generic.py
    a b  
    22
    33from django.contrib.localflavor.generic.forms import DateField, DateTimeField
    44
    5 from utils import LocalFlavorTestCase
     5from django.test import SimpleTestCase
    66
    77
    8 class GenericLocalFlavorTests(LocalFlavorTestCase):
     8class GenericLocalFlavorTests(SimpleTestCase):
    99    def test_GenericDateField(self):
    1010        error_invalid = [u'Enter a valid date.']
    1111        valid = {
  • tests/regressiontests/forms/localflavor/hr.py

    diff --git a/tests/regressiontests/forms/localflavor/hr.py b/tests/regressiontests/forms/localflavor/hr.py
    a b  
    44    HRLicensePlateField, HRPostalCodeField, HROIBField, HRJMBGField,
    55    HRJMBAGField)
    66
    7 from utils import LocalFlavorTestCase
     7from django.test import SimpleTestCase
    88
    9 class HRLocalFlavorTests(LocalFlavorTestCase):
     9class HRLocalFlavorTests(SimpleTestCase):
    1010    def test_HRCountySelect(self):
    1111        f = HRCountySelect()
    1212        out = u'''<select name="county">
  • tests/regressiontests/forms/localflavor/id.py

    diff --git a/tests/regressiontests/forms/localflavor/id.py b/tests/regressiontests/forms/localflavor/id.py
    a b  
    44    IDPostCodeField, IDNationalIdentityNumberField, IDLicensePlateField,
    55    IDProvinceSelect, IDLicensePlatePrefixSelect)
    66
    7 from utils import LocalFlavorTestCase
     7from django.test import SimpleTestCase
    88
    99
    10 class IDLocalFlavorTests(LocalFlavorTestCase):
     10class IDLocalFlavorTests(SimpleTestCase):
    1111    def setUp(self):
    1212        self.save_warnings_state()
    1313        warnings.filterwarnings(
  • tests/regressiontests/forms/localflavor/ie.py

    diff --git a/tests/regressiontests/forms/localflavor/ie.py b/tests/regressiontests/forms/localflavor/ie.py
    a b  
    11from django.contrib.localflavor.ie.forms import IECountySelect
    22
    3 from utils import LocalFlavorTestCase
     3from django.test import SimpleTestCase
    44
    55
    6 class IELocalFlavorTests(LocalFlavorTestCase):
     6class IELocalFlavorTests(SimpleTestCase):
    77    def test_IECountySelect(self):
    88        f = IECountySelect()
    99        out = u'''<select name="counties">
  • tests/regressiontests/forms/localflavor/il.py

    diff --git a/tests/regressiontests/forms/localflavor/il.py b/tests/regressiontests/forms/localflavor/il.py
    a b  
    11from django.contrib.localflavor.il.forms import (ILPostalCodeField,
    22    ILIDNumberField)
    33
    4 from utils import LocalFlavorTestCase
     4from django.test import SimpleTestCase
    55
    66
    7 class ILLocalFlavorTests(LocalFlavorTestCase):
     7class ILLocalFlavorTests(SimpleTestCase):
    88    def test_ILPostalCodeField(self):
    99        error_format = [u'Enter a postal code in the format XXXXX']
    1010        valid = {
  • tests/regressiontests/forms/localflavor/in_.py

    diff --git a/tests/regressiontests/forms/localflavor/in_.py b/tests/regressiontests/forms/localflavor/in_.py
    a b  
    11from django.contrib.localflavor.in_.forms import (INZipCodeField,
    22    INStateField, INStateSelect, INPhoneNumberField)
    33
    4 from utils import LocalFlavorTestCase
     4from django.test import SimpleTestCase
    55
    66
    77
    8 class INLocalFlavorTests(LocalFlavorTestCase):
     8class INLocalFlavorTests(SimpleTestCase):
    99    def test_INPhoneNumberField(self):
    1010        error_format = [u'Phone numbers must be in 02X-8X or 03X-7X or 04X-6X format.']
    1111        valid = {
  • tests/regressiontests/forms/localflavor/is_.py

    diff --git a/tests/regressiontests/forms/localflavor/is_.py b/tests/regressiontests/forms/localflavor/is_.py
    a b  
    11from django.contrib.localflavor.is_.forms import (ISIdNumberField,
    22    ISPhoneNumberField, ISPostalCodeSelect)
    33
    4 from utils import LocalFlavorTestCase
     4from django.test import SimpleTestCase
    55
    66
    7 class ISLocalFlavorTests(LocalFlavorTestCase):
     7class ISLocalFlavorTests(SimpleTestCase):
    88    def test_ISPostalCodeSelect(self):
    99        f = ISPostalCodeSelect()
    1010        out = u'''<select name="foo">
  • tests/regressiontests/forms/localflavor/it.py

    diff --git a/tests/regressiontests/forms/localflavor/it.py b/tests/regressiontests/forms/localflavor/it.py
    a b  
    11from django.contrib.localflavor.it.forms import (ITZipCodeField, ITRegionSelect,
    22    ITSocialSecurityNumberField, ITVatNumberField)
    33
    4 from utils import LocalFlavorTestCase
     4from django.test import SimpleTestCase
    55
    66
    7 class ITLocalFlavorTests(LocalFlavorTestCase):
     7class ITLocalFlavorTests(SimpleTestCase):
    88    def test_ITRegionSelect(self):
    99        f = ITRegionSelect()
    1010        out = u'''<select name="regions">
  • tests/regressiontests/forms/localflavor/jp.py

    diff --git a/tests/regressiontests/forms/localflavor/jp.py b/tests/regressiontests/forms/localflavor/jp.py
    a b  
    11from django.contrib.localflavor.jp.forms import (JPPostalCodeField,
    22    JPPrefectureSelect)
    33
    4 from utils import LocalFlavorTestCase
     4from django.test import SimpleTestCase
    55
    66
    7 class JPLocalFlavorTests(LocalFlavorTestCase):
     7class JPLocalFlavorTests(SimpleTestCase):
    88    def test_JPPrefectureSelect(self):
    99        f = JPPrefectureSelect()
    1010        out = u'''<select name="prefecture">
  • tests/regressiontests/forms/localflavor/kw.py

    diff --git a/tests/regressiontests/forms/localflavor/kw.py b/tests/regressiontests/forms/localflavor/kw.py
    a b  
    11from django.contrib.localflavor.kw.forms import KWCivilIDNumberField
    22
    3 from utils import LocalFlavorTestCase
     3from django.test import SimpleTestCase
    44
    55
    6 class KWLocalFlavorTests(LocalFlavorTestCase):
     6class KWLocalFlavorTests(SimpleTestCase):
    77    def test_KWCivilIDNumberField(self):
    88        error_invalid = [u'Enter a valid Kuwaiti Civil ID number']
    99        valid = {
  • tests/regressiontests/forms/localflavor/mk.py

    diff --git a/tests/regressiontests/forms/localflavor/mk.py b/tests/regressiontests/forms/localflavor/mk.py
    a b  
    11from django.contrib.localflavor.mk.forms import (
    22    MKIdentityCardNumberField, MKMunicipalitySelect, UMCNField)
    33
    4 from utils import LocalFlavorTestCase
     4from django.test import SimpleTestCase
    55
    66
    7 class MKLocalFlavorTests(LocalFlavorTestCase):
     7class MKLocalFlavorTests(SimpleTestCase):
    88
    99    def test_MKIdentityCardNumberField(self):
    1010        error_invalid  = [u'Identity card numbers must contain either 4 to 7 '
  • tests/regressiontests/forms/localflavor/mx.py

    diff --git a/tests/regressiontests/forms/localflavor/mx.py b/tests/regressiontests/forms/localflavor/mx.py
    a b  
    22from django.contrib.localflavor.mx.forms import (MXZipCodeField, MXRFCField,
    33    MXStateSelect, MXCURPField)
    44
    5 from utils import LocalFlavorTestCase
     5from django.test import SimpleTestCase
    66
    77
    8 class MXLocalFlavorTests(LocalFlavorTestCase):
     8class MXLocalFlavorTests(SimpleTestCase):
    99    def test_MXStateSelect(self):
    1010        f = MXStateSelect()
    1111        out = u'''<select name="state">
  • tests/regressiontests/forms/localflavor/nl.py

    diff --git a/tests/regressiontests/forms/localflavor/nl.py b/tests/regressiontests/forms/localflavor/nl.py
    a b  
    11from django.contrib.localflavor.nl.forms import (NLPhoneNumberField,
    22    NLZipCodeField, NLSoFiNumberField, NLProvinceSelect)
    33
    4 from utils import LocalFlavorTestCase
     4from django.test import SimpleTestCase
    55
    66
    7 class NLLocalFlavorTests(LocalFlavorTestCase):
     7class NLLocalFlavorTests(SimpleTestCase):
    88    def test_NLProvinceSelect(self):
    99        f = NLProvinceSelect()
    1010        out = u'''<select name="provinces">
  • tests/regressiontests/forms/localflavor/pl.py

    diff --git a/tests/regressiontests/forms/localflavor/pl.py b/tests/regressiontests/forms/localflavor/pl.py
    a b  
    11from django.contrib.localflavor.pl.forms import (PLProvinceSelect,
    22    PLCountySelect, PLPostalCodeField, PLNIPField, PLPESELField, PLNationalIDCardNumberField, PLREGONField)
    33
    4 from utils import LocalFlavorTestCase
     4from django.test import SimpleTestCase
    55
    66
    7 class PLLocalFlavorTests(LocalFlavorTestCase):
     7class PLLocalFlavorTests(SimpleTestCase):
    88    def test_PLProvinceSelect(self):
    99        f = PLProvinceSelect()
    1010        out = u'''<select name="voivodeships">
  • tests/regressiontests/forms/localflavor/pt.py

    diff --git a/tests/regressiontests/forms/localflavor/pt.py b/tests/regressiontests/forms/localflavor/pt.py
    a b  
    11from django.contrib.localflavor.pt.forms import PTZipCodeField, PTPhoneNumberField
    22
    3 from utils import LocalFlavorTestCase
     3from django.test import SimpleTestCase
    44
    55
    6 class PTLocalFlavorTests(LocalFlavorTestCase):
     6class PTLocalFlavorTests(SimpleTestCase):
    77    def test_PTZipCodeField(self):
    88        error_format = [u'Enter a zip code in the format XXXX-XXX.']
    99        valid = {
  • tests/regressiontests/forms/localflavor/py.py

    diff --git a/tests/regressiontests/forms/localflavor/py.py b/tests/regressiontests/forms/localflavor/py.py
    a b  
    11from django.contrib.localflavor.py.forms import (PyDepartmentSelect,
    22    PyNumberedDepartmentSelect)
    33
    4 from utils import LocalFlavorTestCase
     4from django.test import SimpleTestCase
    55
    6 class PYLocalFlavorTests(LocalFlavorTestCase):
     6class PYLocalFlavorTests(SimpleTestCase):
    77    def test_PyDepartmentSelect(self):
    88        py = PyDepartmentSelect()
    99        out = u'''<select name="department">
  • tests/regressiontests/forms/localflavor/ro.py

    diff --git a/tests/regressiontests/forms/localflavor/ro.py b/tests/regressiontests/forms/localflavor/ro.py
    a b  
    33    ROCountyField, ROCountySelect, ROIBANField, ROPhoneNumberField,
    44    ROPostalCodeField)
    55
    6 from utils import LocalFlavorTestCase
     6from django.test import SimpleTestCase
    77
    88
    9 class ROLocalFlavorTests(LocalFlavorTestCase):
     9class ROLocalFlavorTests(SimpleTestCase):
    1010    def test_ROCountySelect(self):
    1111        f = ROCountySelect()
    1212        out = u'''<select name="county">
  • tests/regressiontests/forms/localflavor/ru.py

    diff --git a/tests/regressiontests/forms/localflavor/ru.py b/tests/regressiontests/forms/localflavor/ru.py
    a b  
    11from django.contrib.localflavor.ru.forms import *
    22 
    3 from utils import LocalFlavorTestCase
     3from django.test import SimpleTestCase
    44
    55
    6 class RULocalFlavorTests(LocalFlavorTestCase):
     6class RULocalFlavorTests(SimpleTestCase):
    77
    88    def test_RUPassportNumberField(self):
    99        error = [u'Enter a passport number in the format XXXX XXXXXX.']
  • tests/regressiontests/forms/localflavor/se.py

    diff --git a/tests/regressiontests/forms/localflavor/se.py b/tests/regressiontests/forms/localflavor/se.py
    a b  
    44    SEPostalCodeField)
    55import datetime
    66
    7 from utils import LocalFlavorTestCase
     7from django.test import SimpleTestCase
    88
    99
    10 class SELocalFlavorTests(LocalFlavorTestCase):
     10class SELocalFlavorTests(SimpleTestCase):
    1111
    1212    def setUp(self):
    1313        # Mocking datetime.date to make sure
  • tests/regressiontests/forms/localflavor/sk.py

    diff --git a/tests/regressiontests/forms/localflavor/sk.py b/tests/regressiontests/forms/localflavor/sk.py
    a b  
    11from django.contrib.localflavor.sk.forms import (SKRegionSelect,
    22    SKPostalCodeField, SKDistrictSelect)
    33
    4 from utils import LocalFlavorTestCase
     4from django.test import SimpleTestCase
    55
    66
    7 class SKLocalFlavorTests(LocalFlavorTestCase):
     7class SKLocalFlavorTests(SimpleTestCase):
    88    def test_SKRegionSelect(self):
    99        f = SKRegionSelect()
    1010        out = u'''<select name="regions">
  • tests/regressiontests/forms/localflavor/us.py

    diff --git a/tests/regressiontests/forms/localflavor/us.py b/tests/regressiontests/forms/localflavor/us.py
    a b  
    11from django.contrib.localflavor.us.forms import (USZipCodeField,
    22    USPhoneNumberField, USStateField, USStateSelect, USSocialSecurityNumberField)
    33
    4 from utils import LocalFlavorTestCase
     4from django.test import SimpleTestCase
    55
    66
    7 class USLocalFlavorTests(LocalFlavorTestCase):
     7class USLocalFlavorTests(SimpleTestCase):
    88    def test_USStateSelect(self):
    99        f = USStateSelect()
    1010        out = u'''<select name="state">
  • deleted file tests/regressiontests/forms/localflavor/utils.py

    diff --git a/tests/regressiontests/forms/localflavor/utils.py b/tests/regressiontests/forms/localflavor/utils.py
    deleted file mode 100644
    + -  
    1 from __future__ import with_statement
    2 
    3 from django.core.exceptions import ValidationError
    4 from django.core.validators import EMPTY_VALUES
    5 from django.forms.fields import CharField
    6 from django.test.utils import get_warnings_state, restore_warnings_state
    7 from django.utils.unittest import TestCase
    8 
    9 
    10 class LocalFlavorTestCase(TestCase):
    11     # NOTE: These are copied from the TestCase Django uses for tests which
    12     # access the database
    13     def save_warnings_state(self):
    14         self._warnings_state = get_warnings_state()
    15 
    16     def restore_warnings_state(self):
    17         restore_warnings_state(self._warnings_state)
    18 
    19     def assertFieldOutput(self, fieldclass, valid, invalid, field_args=None,
    20             field_kwargs=None, empty_value=u''):
    21         """
    22         Asserts that a field behaves correctly with various inputs.
    23 
    24         Args:
    25             fieldclass: the class of the field to be tested.
    26             valid: a dictionary mapping valid inputs to their expected
    27                     cleaned values.
    28             invalid: a dictionary mapping invalid inputs to one or more
    29                     raised error messages.
    30             field_args: the args passed to instantiate the field
    31             field_kwargs: the kwargs passed to instantiate the field
    32             empty_value: the expected clean output for inputs in EMPTY_VALUES
    33 
    34         """
    35         if field_args is None:
    36             field_args = []
    37         if field_kwargs is None:
    38             field_kwargs = {}
    39         required = fieldclass(*field_args, **field_kwargs)
    40         optional = fieldclass(*field_args, **dict(field_kwargs, required=False))
    41         # test valid inputs
    42         for input, output in valid.items():
    43             self.assertEqual(required.clean(input), output)
    44             self.assertEqual(optional.clean(input), output)
    45         # test invalid inputs
    46         for input, errors in invalid.items():
    47             with self.assertRaises(ValidationError) as context_manager:
    48                 required.clean(input)
    49             self.assertEqual(context_manager.exception.messages, errors)
    50 
    51             with self.assertRaises(ValidationError) as context_manager:
    52                 optional.clean(input)
    53             self.assertEqual(context_manager.exception.messages, errors)
    54         # test required inputs
    55         error_required = [u'This field is required.']
    56         for e in EMPTY_VALUES:
    57             with self.assertRaises(ValidationError) as context_manager:
    58                 required.clean(e)
    59             self.assertEqual(context_manager.exception.messages, error_required)
    60             self.assertEqual(optional.clean(e), empty_value)
    61         # test that max_length and min_length are always accepted
    62         if issubclass(fieldclass, CharField):
    63             field_kwargs.update({'min_length':2, 'max_length':20})
    64             self.assertTrue(isinstance(fieldclass(*field_args, **field_kwargs), fieldclass))
  • tests/regressiontests/forms/localflavor/uy.py

    diff --git a/tests/regressiontests/forms/localflavor/uy.py b/tests/regressiontests/forms/localflavor/uy.py
    a b  
    11from django.contrib.localflavor.uy.forms import UYDepartamentSelect, UYCIField
    22from django.contrib.localflavor.uy.util import get_validation_digit
    33
    4 from utils import LocalFlavorTestCase
     4from django.test import SimpleTestCase
    55
    66
    7 class UYLocalFlavorTests(LocalFlavorTestCase):
     7class UYLocalFlavorTests(SimpleTestCase):
    88    def test_UYDepartmentSelect(self):
    99        f = UYDepartamentSelect()
    1010        out = u'''<select name="departamentos">
  • tests/regressiontests/forms/localflavor/za.py

    diff --git a/tests/regressiontests/forms/localflavor/za.py b/tests/regressiontests/forms/localflavor/za.py
    a b  
    11from django.contrib.localflavor.za.forms import ZAIDField, ZAPostCodeField
    22
    3 from utils import LocalFlavorTestCase
     3from django.test import SimpleTestCase
    44
    55
    6 class ZALocalFlavorTests(LocalFlavorTestCase):
     6class ZALocalFlavorTests(SimpleTestCase):
    77    def test_ZAIDField(self):
    88        error_invalid = [u'Enter a valid South African ID number']
    99        valid = {
  • tests/regressiontests/forms/localflavortests.py

    diff --git a/tests/regressiontests/forms/localflavortests.py b/tests/regressiontests/forms/localflavortests.py
    a b  
    1 from localflavor import AssertFieldOutputTests
    21from localflavor.ar import ARLocalFlavorTests
    32from localflavor.at import ATLocalFlavorTests
    43from localflavor.au import AULocalFlavorTests
  • tests/regressiontests/forms/tests/__init__.py

    diff --git a/tests/regressiontests/forms/tests/__init__.py b/tests/regressiontests/forms/tests/__init__.py
    a b  
    5353    USLocalFlavorTests,
    5454    UYLocalFlavorTests,
    5555    ZALocalFlavorTests,
    56     AssertFieldOutputTests,
    5756)
  • tests/regressiontests/test_utils/tests.py

    diff --git a/tests/regressiontests/test_utils/tests.py b/tests/regressiontests/test_utils/tests.py
    a b  
    11from __future__ import with_statement
    22
     3from django.forms import EmailField
    34from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
    45from django.utils.unittest import skip
    56
     
    139140        self.assertRaisesMessage(ValueError, "[.*x+]y?", func1)
    140141
    141142
     143class AssertFieldOutputTests(SimpleTestCase):
     144
     145    def test_assert_field_output(self):
     146        error_invalid = [u'Enter a valid e-mail address.']
     147        self.assertFieldOutput(EmailField, {'a@a.com': 'a@a.com'}, {'aaa': error_invalid})
     148        self.assertRaises(AssertionError, self.assertFieldOutput, EmailField, {'a@a.com': 'a@a.com'}, {'aaa': error_invalid + [u'Another error']})
     149        self.assertRaises(AssertionError, self.assertFieldOutput, EmailField, {'a@a.com': 'Wrong output'}, {'aaa': error_invalid})
     150        self.assertRaises(AssertionError, self.assertFieldOutput, EmailField, {'a@a.com': 'a@a.com'}, {'aaa': [u'Come on, gimme some well formatted data, dude.']})
     151
     152
    142153__test__ = {"API_TEST": r"""
    143154# Some checks of the doctest output normalizer.
    144155# Standard doctests do fairly
Back to Top