def test_michigan(self): dl_state = 'MI' self.assertFalse(is_valid('1234567', dl_state)) self.assertTrue(is_valid('a123456789012', dl_state)) self.assertTrue(is_valid('L123456789012', dl_state)) self.assertFalse(is_valid('a1234567890', dl_state)) self.assertFalse(is_valid('ab1234567', dl_state))
def test_massachusetts(self): dl_state = 'MA' self.assertTrue(is_valid('123456789', dl_state)) self.assertTrue(is_valid('s12345678', dl_state)) self.assertTrue(is_valid('S12345678', dl_state)) self.assertFalse(is_valid('a1234567890', dl_state)) self.assertFalse(is_valid('ab1234567', dl_state))
def test_minnesota(self): dl_state = 'MN' self.assertFalse(is_valid('1234567', dl_state)) self.assertTrue(is_valid('a123456789012', dl_state)) self.assertTrue(is_valid('M123456789012', dl_state)) self.assertFalse(is_valid('a1234567890', dl_state)) self.assertFalse(is_valid('ab1234567', dl_state))
def test_maryland(self): dl_state = 'MD' self.assertFalse(is_valid('1234567', dl_state)) self.assertTrue(is_valid('a123456789012', dl_state)) self.assertTrue(is_valid('M123456789012', dl_state)) self.assertFalse(is_valid('a1234567890', dl_state)) self.assertFalse(is_valid('ab1234567', dl_state))
def test_idaho(self): dl_state = 'ID' self.assertTrue(is_valid('123456789', dl_state)) self.assertTrue(is_valid('ab123456a', dl_state)) self.assertTrue(is_valid('AB123456A', dl_state)) self.assertFalse(is_valid('a12345678', dl_state)) self.assertFalse(is_valid('ab1234', dl_state))
def test_new_hampshire(self): dl_state = 'NH' self.assertFalse(is_valid('123456789', dl_state)) self.assertFalse(is_valid('a12345', dl_state)) self.assertFalse(is_valid('ab1234567', dl_state)) self.assertTrue(is_valid('12abc12345', dl_state)) self.assertTrue(is_valid('12ABC12345', dl_state))
def test_colorado(self): dl_state = 'CO' self.assertTrue(is_valid('123456789', dl_state)) self.assertFalse(is_valid('12345678', dl_state)) self.assertTrue(is_valid('a123456', dl_state)) self.assertTrue(is_valid('A123', dl_state)) self.assertFalse(is_valid('Ab12345', dl_state))
def test_new_jersey(self): dl_state = 'NJ' self.assertFalse(is_valid('123456789', dl_state)) self.assertTrue(is_valid('a12345678901234', dl_state)) self.assertTrue(is_valid('N12345678901234', dl_state)) self.assertFalse(is_valid('a1234567890', dl_state)) self.assertFalse(is_valid('ab1234567', dl_state))
def test_nebraska(self): dl_state = 'NE' self.assertTrue(is_valid('a123456', dl_state)) self.assertTrue(is_valid('a123', dl_state)) self.assertTrue(is_valid('a12345678', dl_state)) self.assertFalse(is_valid('12345678', dl_state)) self.assertFalse(is_valid('12345678a', dl_state))
def test_tennessee(self): dl_state = 'TN' self.assertTrue(is_valid('1234567', dl_state)) self.assertTrue(is_valid('123456789', dl_state)) self.assertFalse(is_valid('ab123', dl_state)) self.assertFalse(is_valid('a123456', dl_state)) self.assertFalse(is_valid('1234567890123', dl_state))
def test_texas(self): dl_state = 'TX' self.assertTrue(is_valid('12345678', dl_state)) self.assertFalse(is_valid('1234567', dl_state)) self.assertFalse(is_valid('ab123', dl_state)) self.assertFalse(is_valid('a123456', dl_state)) self.assertFalse(is_valid('1234567890123', dl_state))
def test_south_carolina(self): dl_state = 'SC' self.assertTrue(is_valid('12345678', dl_state)) self.assertTrue(is_valid('1234567890', dl_state)) self.assertFalse(is_valid('ab123', dl_state)) self.assertFalse(is_valid('a123456', dl_state)) self.assertFalse(is_valid('1234567890123', dl_state))
def test_rhode_island(self): dl_state = 'RI' self.assertTrue(is_valid('1234567', dl_state)) self.assertFalse(is_valid('ab123', dl_state)) self.assertTrue(is_valid('v123456', dl_state)) self.assertTrue(is_valid('V123456', dl_state)) self.assertFalse(is_valid('1234567890123', dl_state))
def test_oregon(self): dl_state = 'OR' self.assertTrue(is_valid('12345678', dl_state)) self.assertTrue(is_valid('a123456', dl_state)) self.assertTrue(is_valid('OR12345', dl_state)) self.assertFalse(is_valid('a12345678', dl_state)) self.assertFalse(is_valid('1234567890123', dl_state))
def test_utah(self): dl_state = 'UT' self.assertTrue(is_valid('1234', dl_state)) self.assertTrue(is_valid('123456789', dl_state)) self.assertFalse(is_valid('ab123', dl_state)) self.assertFalse(is_valid('a123456', dl_state)) self.assertFalse(is_valid('1234567890123', dl_state))
def test_iowa(self): dl_state = 'IA' self.assertTrue(is_valid('123456789', dl_state)) self.assertFalse(is_valid('a12345678', dl_state)) self.assertFalse(is_valid('ab1234567', dl_state)) self.assertTrue(is_valid('123ab1234', 'IA')) self.assertTrue(is_valid('123AB1234', 'IA'))
def test_wisconsin(self): dl_state = 'WI' self.assertTrue(is_valid('a1234567890123', dl_state)) self.assertTrue(is_valid('W1234567890123', dl_state)) self.assertFalse(is_valid('ab123', dl_state)) self.assertFalse(is_valid('a123456', dl_state)) self.assertFalse(is_valid('1234567890123', dl_state))
def test_west_virginia(self): dl_state = 'WV' self.assertTrue(is_valid('1234567', dl_state)) self.assertFalse(is_valid('a12345', dl_state)) self.assertFalse(is_valid('WV123456', dl_state)) self.assertFalse(is_valid('a1234567', dl_state)) self.assertFalse(is_valid('1234567890123', dl_state))
def test_oklahoma(self): dl_state = 'OK' self.assertTrue(is_valid('123456789', dl_state)) self.assertFalse(is_valid('ab123', dl_state)) self.assertTrue(is_valid('a123456789', dl_state)) self.assertTrue(is_valid('O123456789', dl_state)) self.assertFalse(is_valid('1234567890123', dl_state))
def test_arizona(self): dl_state = 'AZ' self.assertFalse(is_valid('1234567', dl_state)) self.assertTrue(is_valid('a12345678', dl_state)) self.assertTrue(is_valid('A12345678', dl_state)) self.assertFalse(is_valid('aB12345', dl_state)) self.assertTrue(is_valid('123456789', dl_state))
def test_montana(self): dl_state = 'MT' self.assertTrue(is_valid('abcdefghi', dl_state)) self.assertTrue(is_valid('1234567890123', dl_state)) self.assertFalse(is_valid('a12345678', dl_state)) self.assertFalse(is_valid('a1234567890', dl_state)) self.assertFalse(is_valid('ab1234567', dl_state))
def test_territories(self): for dl_state in OTHER_STATES: self.assertTrue(is_valid('1234567890', dl_state, True)) self.assertTrue(is_valid('ab123', dl_state, True)) self.assertTrue(is_valid('**-- ', dl_state, True)) self.assertTrue(is_valid('.', dl_state, True)) self.assertTrue(is_valid('icantbelieveijustwroteallthesetests', dl_state, True))
def test_allow_territories(self): dl_num = "doesnt_matter" self.assertRaises(Exception, is_valid, dl_num, "AS", False) self.assertRaises(Exception, is_valid, dl_num, "FM", False) self.assertRaises(Exception, is_valid, dl_num, "AA", False) self.assertTrue(is_valid(dl_num, "AS", True)) self.assertTrue(is_valid(dl_num, "FM", True)) self.assertTrue(is_valid(dl_num, "AA", True))
def test_territories(self): for dl_state in OTHER_STATES: self.assertTrue(is_valid('1234567890', dl_state, True)) self.assertTrue(is_valid('ab123', dl_state, True)) self.assertTrue(is_valid('**-- ', dl_state, True)) self.assertTrue(is_valid('.', dl_state, True)) self.assertTrue( is_valid('icantbelieveijustwroteallthesetests', dl_state, True))
def test_west_virginia(self): dl_state = 'WV' self.assertTrue(is_valid('1234567', dl_state)) self.assertTrue(is_valid('F478888', dl_state)) self.assertTrue(is_valid('A12345', dl_state)) self.assertTrue(is_valid('c123456', dl_state)) self.assertTrue(is_valid('zb12345', dl_state)) self.assertTrue(is_valid('aZ123456', dl_state)) self.assertFalse(is_valid('WV1234567', dl_state)) self.assertFalse(is_valid('a1234567', dl_state)) self.assertFalse(is_valid('12345', dl_state)) self.assertFalse(is_valid('1234567890123', dl_state))
def clean_license_id_number(self): state = self.cleaned_data.get('registered_state') license = self.cleaned_data.get('license_id_number') if not is_valid(license, state): raise forms.ValidationError("License # is not valid for registered state.") return license
def test_missouri(self): dl_state = 'MO' self.assertTrue(is_valid('123456789', dl_state)) self.assertTrue(is_valid('a12345678', dl_state)) self.assertTrue(is_valid('a12345', dl_state)) self.assertTrue(is_valid('A12345678', dl_state)) self.assertTrue(is_valid('A123456', dl_state)) self.assertFalse(is_valid('12345678ab', dl_state)) self.assertFalse(is_valid('123456789a', dl_state)) self.assertFalse(is_valid('ab1234567', dl_state))
def test_nevada(self): dl_state = 'NV' self.assertFalse(is_valid('1234', dl_state)) self.assertTrue(is_valid('1234567890', dl_state)) self.assertTrue(is_valid('x12345678', dl_state)) self.assertTrue(is_valid('X12345678', dl_state)) self.assertFalse(is_valid('a123456', dl_state)) self.assertFalse(is_valid('a12345678', dl_state)) self.assertFalse(is_valid('12345678', dl_state))
def test_new_york(self): dl_state = 'NY' self.assertTrue(is_valid('123456789', dl_state)) self.assertTrue(is_valid('A123456789012345678', dl_state)) self.assertFalse(is_valid('12345678', dl_state)) self.assertFalse(is_valid('1234567890123456', dl_state)) self.assertFalse(is_valid('a1234567', dl_state)) self.assertFalse(is_valid('NEWaYORK', dl_state)) self.assertFalse(is_valid('123456', dl_state))
def test_washington(self): dl_state = 'WA' self.assertTrue(is_valid('abcdefg12345', dl_state)) self.assertTrue(is_valid('ab*****123ab', dl_state)) self.assertTrue(is_valid('WASH*AB12345', dl_state)) self.assertTrue(is_valid('ab*INGT1234b', dl_state)) self.assertFalse(is_valid('ab123', dl_state)) self.assertFalse(is_valid('a123456', dl_state)) self.assertFalse(is_valid('abcd123456789', dl_state))
def test_florida(self): dl_state = 'FL' self.assertFalse(is_valid('1234567', dl_state)) self.assertTrue(is_valid('a123456789012', dl_state)) self.assertTrue(is_valid('C123456789012', dl_state)) self.assertTrue(is_valid('a12', dl_state)) self.assertTrue(is_valid('a1234567890', dl_state)) self.assertFalse(is_valid('ab1234567', dl_state))
def test_virginia(self): dl_state = 'VA' self.assertTrue(is_valid('123456789', dl_state)) self.assertTrue(is_valid('a12345678', dl_state)) self.assertTrue(is_valid('V12345678', dl_state)) self.assertFalse(is_valid('ab123', dl_state)) self.assertFalse(is_valid('a123456', dl_state)) self.assertFalse(is_valid('1234567890123', dl_state))
def test_vermont(self): dl_state = 'VT' self.assertTrue(is_valid('12345678', dl_state)) self.assertTrue(is_valid('1234567a', dl_state)) self.assertTrue(is_valid('1234567A', dl_state)) self.assertFalse(is_valid('ab123', dl_state)) self.assertFalse(is_valid('a123456', dl_state)) self.assertFalse(is_valid('1234567890123', dl_state))