Skip to content

Commit

Permalink
Remove backaccount form field, increase test coverage to 100%
Browse files Browse the repository at this point in the history
 - The bankaccount form field was created in this PR and since we want to deprecate it in favour of IBAN it should be added.
 - re-add tests for bank account model field
  • Loading branch information
jieter committed Sep 10, 2015
1 parent f6fcd3b commit 57db031
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 21 deletions.
16 changes: 1 addition & 15 deletions localflavor/nl/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
from django import forms

from .nl_provinces import PROVINCE_CHOICES
from .validators import (NLBankAccountNumberFieldValidator,
NLPhoneNumberFieldValidator,
from .validators import (NLPhoneNumberFieldValidator,
NLSoFiNumberFieldValidator, NLZipCodeFieldValidator)


Expand Down Expand Up @@ -58,16 +57,3 @@ class NLSoFiNumberField(forms.CharField):
def __init__(self, *args, **kwargs):
kwargs['max_length'] = 9
super(NLSoFiNumberField, self).__init__(*args, **kwargs)


class NLBankAccountNumberField(forms.CharField):
"""
Since the introduction of IBAN, Dutch bank account numbers are not usable
anymore. Django-localflavor provides :class:`localflavor.generic.IBANFormField`
"""
default_validators = [NLBankAccountNumberFieldValidator()]

def __init__(self, *args, **kwargs):
kwargs['max_length'] = 10

super(NLBankAccountNumberField, self).__init__(*args, **kwargs)
7 changes: 3 additions & 4 deletions localflavor/nl/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import absolute_import, unicode_literals

import six
from django.db import models
from django.utils.translation import ugettext_lazy as _

Expand All @@ -27,11 +26,11 @@ def __init__(self, *args, **kwargs):
super(NLZipCodeField, self).__init__(*args, **kwargs)

def to_python(self, value):
if isinstance(value, six.string_types):
value = super(NLZipCodeField, self).to_python(value)
if value is not None:
value = value.upper().replace(' ', '')
return '%s %s' % (value[:4], value[4:])

return super(NLZipCodeField, self).to_python(value)
return value

def formfield(self, **kwargs):
defaults = {'form_class': forms.NLZipCodeField}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_nl/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ class NLPlaceForm(ModelForm):

class Meta:
model = NLPlace
fields = ('zipcode', 'province', 'sofinr', 'phone', )
fields = ('zipcode', 'province', 'sofinr', 'phone', 'bankaccount')
4 changes: 3 additions & 1 deletion tests/test_nl/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db import models

from localflavor.nl.models import (NLPhoneNumberField, NLProvinceField,
from localflavor.nl.models import (NLBankAccountNumberField,
NLPhoneNumberField, NLProvinceField,
NLSoFiNumberField, NLZipCodeField)


Expand All @@ -11,6 +12,7 @@ class NLPlace(models.Model):

sofinr = NLSoFiNumberField()
phone = NLPhoneNumberField()
bankaccount = NLBankAccountNumberField()

class Meta:
app_label = 'test_nl'
8 changes: 8 additions & 0 deletions tests/test_nl/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def test_NLZipCodeField(self):
field = models.NLZipCodeField()

self.assertEqual(field.to_python('1234AB'), '1234 AB')
self.assertEqual(field.to_python(None), None)

self.assertIsInstance(field.formfield(), forms.NLZipCodeField)

Expand All @@ -94,13 +95,15 @@ def test_NL_model(self):
'province': 'OV',
'sofinr': '123456782',
'phone': '012-3456789',
'bankaccount': '0417164300'
})

self.assertEqual(str(m.zipcode), '2403BW')
self.assertEqual(str(m.province), 'OV')

self.assertEqual(str(m.sofinr), '123456782')
self.assertEqual(str(m.phone), '012-3456789')
self.assertEqual(str(m.bankaccount), '0417164300')

m.clean_fields()

Expand All @@ -110,6 +113,7 @@ def test_NL_model_cleanup(self):
'province': 'OV',
'sofinr': '123456782',
'phone': '012-3456789',
'bankaccount': '0417164300'
})
# zipcode is not quite right, so it should raise an error
self.assertRaises(ValidationError, lambda: m.clean_fields())
Expand Down Expand Up @@ -193,6 +197,7 @@ def test_NL_ModelForm_errors(self):
'province': 'invalid',
'sofinr': 'invalid',
'phone': 'invalid',
'bankaccount': 'invalid',
})

self.assertFalse(form.is_valid())
Expand All @@ -202,12 +207,15 @@ def test_NL_ModelForm_errors(self):
self.assertEqual(form.errors['province'], [invalid_choice])
self.assertEqual(form.errors['sofinr'], ['Enter a valid SoFi number.'])
self.assertEqual(form.errors['phone'], ['Enter a valid phone number.'])
self.assertEqual(form.errors['bankaccount'], ['Enter a valid bank account number.'])

def test_NL_ModelForm_valid(self):
form = NLPlaceForm({
'zipcode': '2233 AB',
'province': 'OV',
'sofinr': '123456782',
'phone': '0623456789',
'bankaccount': '0417164300'
})
print form.errors
self.assertTrue(form.is_valid())

0 comments on commit 57db031

Please sign in to comment.