-
Notifications
You must be signed in to change notification settings - Fork 295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Australian Company Number validator #278
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,8 @@ | |
from django.test import TestCase | ||
|
||
from localflavor.au import forms, models | ||
from localflavor.au.validators import AUBusinessNumberFieldValidator, AUTaxFileNumberFieldValidator | ||
from localflavor.au.validators import (AUBusinessNumberFieldValidator, AUCompanyNumberFieldValidator, | ||
AUTaxFileNumberFieldValidator) | ||
|
||
from .forms import AustralianPlaceForm | ||
from .models import AustralianPlace | ||
|
@@ -195,6 +196,56 @@ def test_raises_error_for_invalid_abn(self): | |
self.assertRaises(ValidationError, lambda: validator(invalid_abn)) | ||
|
||
|
||
class AULocalFlavorAUCompanyNumberFieldValidatorTests(TestCase): | ||
|
||
def test_no_error_for_a_valid_acn(self): | ||
"""Test a valid ACN does not cause an error.""" | ||
valid_acn = '604327504' | ||
|
||
validator = AUCompanyNumberFieldValidator() | ||
|
||
validator(valid_acn) | ||
|
||
def test_raises_error_for_acn_containing_a_letter(self): | ||
"""Test an ACN containing a letter is invalid.""" | ||
invalid_acn = '60432750A' | ||
|
||
validator = AUCompanyNumberFieldValidator() | ||
|
||
self.assertRaises(ValidationError, lambda: validator(invalid_acn)) | ||
|
||
def test_raises_error_for_too_short_acn(self): | ||
"""Test an ACN with fewer than nine digits is invalid.""" | ||
invalid_acn = '60432750' | ||
|
||
validator = AUCompanyNumberFieldValidator() | ||
|
||
self.assertRaises(ValidationError, lambda: validator(invalid_acn)) | ||
|
||
def test_raises_error_for_too_long_acn(self): | ||
"""Test an ACN with more than nine digits is invalid.""" | ||
invalid_acn = '6043275040' | ||
validator = AUCompanyNumberFieldValidator() | ||
self.assertRaises(ValidationError, lambda: validator(invalid_acn)) | ||
|
||
def test_raises_error_for_whitespace(self): | ||
"""Test an ACN can be valid when it contains whitespace.""" | ||
# NB: Form field should strip the whitespace before regex valdation is run. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. valdation -> validation I see that's also in the copy & pasted code so maybe you can also fix the typo there as well. As this comment points out, the whitespace is stripped in the form. It would be nice to have a test for the form as well - at least testing the expected functionality that isn't tested with the validation tests. |
||
invalid_acn = '604 327 504' | ||
|
||
validator = AUCompanyNumberFieldValidator() | ||
|
||
self.assertRaises(ValidationError, lambda: validator(invalid_acn)) | ||
|
||
def test_raises_error_for_invalid_acn(self): | ||
"""Test that an ACN must pass the ATO's validation algorithm.""" | ||
invalid_acn = '604327509' | ||
|
||
validator = AUCompanyNumberFieldValidator() | ||
|
||
self.assertRaises(ValidationError, lambda: validator(invalid_acn)) | ||
|
||
|
||
class AULocalFlavorAUTaxFileNumberFieldValidatorTests(TestCase): | ||
|
||
def test_no_error_for_a_valid_tfn(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to be consistent on the spacing. For instance, some tests have a space between each statement while one has no spaces. The space don't seem to be needed because it's pretty simple code. Feel free to fix the previous tests as well where this was copied from.