def create_users(self): for key, value in users.items(): existing_user = User.query.filter_by(name=key).first() if existing_user is None: user = User(name=key) user.check_password_strength_and_hash_if_ok(value) user.add(user)
def test_incorrect_password_without_symbol(self): name= "USER" password = "******" user = User(name) error, goodPassword = user.check_password_strength_and_hash_if_ok(password) self.assertFalse(goodPassword) self.assertEqual(error, 'The password must include at least one symbol')
def test_incorrect_password_without_lowercase_letter(self): name= "USER" password = "******" user = User(name) error, goodPassword = user.check_password_strength_and_hash_if_ok(password) self.assertFalse(goodPassword) self.assertEqual(error, 'The password must include at least one lowercase letter')
def test_incorrect_password_too_long(self): name= "USER" password = "******"*50 user = User(name) error, goodPassword = user.check_password_strength_and_hash_if_ok(password) self.assertFalse(goodPassword) self.assertEqual(error, 'The password is too long')
def test_check_correct_password_and_verify_the_hash(self): name= "USER" password = "******" user = User(name) error, goodPassword = user.check_password_strength_and_hash_if_ok(password) self.assertTrue(goodPassword, error) password_verified = user.verify_password(password) self.assertTrue(password_verified, "The password could not be verified")
def post(self): """ Users Method to create a new User --- tags: - Users parameters: - in: body name: body schema: id: UserToUpdate properties: name: type: string description: The User name default: "UserName" password: type: string description: The User password default: "P4$sw00rd!" responses: 201: description: The updated area schema: $ref: '#/definitions/Area' """ request_dict = request.get_json() if not request_dict: response = {'user': '******'} return response, status.HTTP_400_BAD_REQUEST errors = user_schema.validate(request_dict) if errors: return errors, status.HTTP_400_BAD_REQUEST name = request_dict['name'] existing_user = User.query.filter_by(name=name).first() if existing_user is not None: response = {'user': '******'} return response, status.HTTP_400_BAD_REQUEST try: user = User(name=name) error_message, password_ok = \ user.check_password_strength_and_hash_if_ok( request_dict['password']) if password_ok: user.add(user) query = User.query.get(user.id) result = user_schema.dump(query).data return result, status.HTTP_201_CREATED else: return {"error": error_message}, status.HTTP_400_BAD_REQUEST except SQLAlchemyError as e: db.session.rollback() resp = {"error": str(e)} return resp, status.HTTP_400_BAD_REQUEST
def test_check_correct_password(self): name= "USER" password = "******" user = User(name) error, goodPassword = user.check_password_strength_and_hash_if_ok(password) self.assertTrue(goodPassword, error)