-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
61 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from flask import Blueprint | ||
|
||
bp = Blueprint('api', __name__, url_prefix='/api') | ||
bp = Blueprint("api", __name__, url_prefix="/api") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from flask import jsonify | ||
from .blueprint import bp | ||
|
||
@bp.route('/hello', methods=['GET']) | ||
def search(): | ||
return jsonify(message='Search'), 200 | ||
|
||
@bp.route("/hello", methods=["GET"]) | ||
def search(): | ||
return jsonify(message="Search"), 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
def init_db(app): | ||
from models import File, User | ||
|
||
__models = [File, User] | ||
|
||
db.init_app(app) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import unittest | ||
from app import app # Assuming your Flask app is in app.py | ||
|
||
|
||
class FlaskAppTestCase(unittest.TestCase): | ||
def setUp(self): | ||
# Set up the test client | ||
self.app = app.test_client() | ||
self.app.testing = True | ||
|
||
def test_hello(self): | ||
# Test the /api/hello route | ||
response = self.app.get("/api/hello") | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response.json, {"message": "Hello, World!"}) | ||
|
||
def test_greet_default(self): | ||
# Test the /api/greet route with default name | ||
response = self.app.post("/api/greet", json={}) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response.json, {"message": "Hello, Guest!"}) | ||
|
||
def test_greet_with_name(self): | ||
# Test the /api/greet route with a name | ||
response = self.app.post("/api/greet", json={"name": "Alice"}) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response.json, {"message": "Hello, Alice!"}) | ||
|
||
def test_greet_with_empty_name(self): | ||
# Test the /api/greet route with an empty name | ||
response = self.app.post("/api/greet", json={"name": ""}) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response.json, {"message": "Hello, !"}) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters