def insert():
    """
    Validates and inserts user
    """
    new_user = request.json 
    user = UserModel(new_user)
    user.validate()
    unique_fields = [{"email"}]
    repository.insert_one_unique_fields(COLLECTION_NAME, user.to_dict(), unique_fields)
    return {"message": "success!"}, 201
 def test_email_no_dot(self):
     no_dot = {"email": "incorrect@emailcom", "name": "correct name"}
     new_user = UserModel(no_dot)
     with self.assertRaises(ValidationException):
         new_user.validate()
 def test_email_space_after_at(self):
     space_after_at = {"email": "incorrect@ email.com", "name": "correct name"}
     new_user = UserModel(space_after_at)
     with self.assertRaises(ValidationException):
         new_user.validate()
 def test_name_number(self):
     number = {"email": "*****@*****.**", "name": "incorrect 234 name"}
     new_user = UserModel(number)
     with self.assertRaises(ValidationException):
         new_user.validate()
 def test_name_double_space(self):
     double_space = {"email": "*****@*****.**", "name": "incorrect  name"}
     new_user = UserModel(double_space)
     with self.assertRaises(ValidationException):
         new_user.validate()
 def test_email_two_ats(self):
     two_ats = {"email": "incorrect@[email protected]", "name": "correct name"}
     new_user = UserModel(two_ats)
     with self.assertRaises(ValidationException):
         new_user.validate()
 def test_correct(self):
     correct = {"email": "*****@*****.**", "name": "correct name"}
     new_user = UserModel(correct)
     self.assertTrue(new_user.validate())