Ejemplo n.º 1
0
 def post(self):
     data = UserRegister.parser.parse_args()
     if UserModel.find_by_username(data['username']):
         return {"message": "A user with that name already exists"}, 400
     user = UserModel(**data)
     user.save_to_db()
     return {"message": "User created successfully"}, 201
Ejemplo n.º 2
0
 def test_crud(self):
     with self.app_context():
         user = UserModel("test_username", "test_password")
         self.assertIsNone(user.find_by_username("test_username"))
         self.assertIsNone(user.find_by_id(1))
         user.save_to_db()
         self.assertIsNotNone(user.find_by_username("test_username"))
         self.assertIsNotNone(user.find_by_id(1))