def testInvalidCheckSum(self): for ssn in self.valid: lis = list(ssn) c = int(lis[-2]) for i in range(10): if c != i: lis[-2] = str(i) self.assertFalse(is_valid(''.join(lis)))
def create_user(): """ Creates a new user in the database given legal data. :return: a json object with an error code. 0 for success, > 0 for error """ data = request.get_json() if any(k not in data for k in ('name', 'password', 'ssn')): return jsonify({'error': error_codes.missing_data}), 400 name, pw, ssn = data['name'], data['password'], data['ssn'] if len(name) == 0 or len(pw) == 0 or len(ssn) == 0: return jsonify({'error': error_codes.empty_data}), 400 if not valid_password(pw): return jsonify({'error': error_codes.invalid_password}), 400 if not is_valid(ssn): return jsonify({'error': error_codes.invalid_ssn}), 400 if db.session.query(User.id).filter_by(ssn=ssn).scalar() is not None: return jsonify({'error': error_codes.user_already_exists}), 400 pw = generate_password_hash(pw, method='sha256') db.session.add( User(open_id=str(uuid.uuid4()), name=name, ssn=ssn, password=pw)) db.session.commit() return jsonify({'error': error_codes.no_error})
def testValidCompanySSNToFail(self): self.assertFalse(is_valid('681201-2890'))
def testInvalidIncorrectDate(self): self.assertFalse(is_valid('330189-1999')) self.assertFalse(is_valid('151389-1999')) self.assertFalse(is_valid('290201-1990'))
def testInvalidWrongCentury(self): self.assertFalse(is_valid('150599-1608')) self.assertFalse(is_valid('150599-1604'))
def testInvalidWrongLength(self): self.assertFalse(is_valid('1231'))
def testInvalidNotString(self): self.assertFalse(is_valid(1012821313))
def testInvalidNone(self): self.assertFalse(is_valid(None))