def test_validate_c_p_f(self): self.assertTrue(validate_cpf('95524361503')) self.assertTrue(validate_cpf('955.243.615-03')) self.assertTrue(validate_cpf(' 9 5 5 2 4 3 6 1 5 0 3 ')) self.assertFalse(validate_cpf('invalid cpf')) self.assertFalse(validate_cpf('42')) self.assertFalse(validate_cpf('')) self.assertFalse(validate_cpf(None)) self.assertFalse(validate_cpf('15948726375')) # A number with more than 11 digits. Ex: a CNPJ self.assertFalse(validate_cpf('45.997.418/0001-53'))
def on_document__validate(self, widget, value): # this will allow the user to use an empty value to this field if self.document.is_empty(): return if self.cpf.get_active() and not validate_cpf(value): return ValidationError(_(u"The CPF is not valid.")) elif self.cnpj.get_active() and not validate_cnpj(value): return ValidationError(_(u"The CNPJ is not valid."))
def test_validate_c_p_f(self): self.failUnless(validate_cpf('95524361503')) self.failUnless(validate_cpf('955.243.615-03')) self.failUnless(validate_cpf(' 9 5 5 2 4 3 6 1 5 0 3 ')) self.failIf(validate_cpf('invalid cpf')) self.failIf(validate_cpf('42')) self.failIf(validate_cpf('')) self.failIf(validate_cpf(None)) self.failIf(validate_cpf('15948726375'))
def test_validate_c_p_f(self): self.assertTrue(validate_cpf('95524361503')) self.assertTrue(validate_cpf('955.243.615-03')) self.assertTrue(validate_cpf(' 9 5 5 2 4 3 6 1 5 0 3 ')) self.assertFalse(validate_cpf('invalid cpf')) self.assertFalse(validate_cpf('42')) self.assertFalse(validate_cpf('')) self.assertFalse(validate_cpf(None)) self.assertFalse(validate_cpf('15948726375'))
def post(self, store): data = self.get_json() client_name = data.get('client_name') client_document = data.get('client_document') address_info = data.get('address') log.debug("POST /client station: %s payload: %s", self.get_current_station(store), data) # We should change the api callsite so that city_location is inside the address if address_info: address_info.setdefault('city_location', data.get('city_location')) if not client_name: log.error('no client_name provided: %s', data) return {'message': 'no client_name provided'}, 400 if not client_document: log.error('no client_document provided: %s', data) return {'message': 'no client_document provided'}, 400 if not validate_cpf(client_document): log.error('invalid client_document provided: %s', data) return {'message': 'invalid client_document provided'}, 400 if not address_info: # Note that city location is validated when creating the address log.error('no address provided: %s', data) return {'message': 'no address provided'}, 400 client = self.get_client(store, client_document) if client: log.error('client with cpf %s already exists', client_document) return { 'message': 'A client with this CPF already exists', 'data': { 'id': client.id, } }, 200 client = self.create_client(store, client_name, client_document, address_info) return { 'message': 'Client created', 'data': { 'id': client.id, } }, 201
def validate(self, value): return validate_cpf(value)