Skip to content

Commit dbba6a7

Browse files
committed
chore: splite routes and add tests
1 parent 0838ce0 commit dbba6a7

File tree

7 files changed

+61
-19
lines changed

7 files changed

+61
-19
lines changed

llmsearch/api/blueprint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from flask import Blueprint
22

3-
bp = Blueprint('api', __name__, url_prefix='/api')
3+
bp = Blueprint("api", __name__, url_prefix="/api")

llmsearch/api/file.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import os
22

3-
from flask import (current_app, jsonify, request)
3+
from flask import current_app, jsonify, request
44
import hashlib
55
from werkzeug.utils import secure_filename
66

77
from env import getenv
88
from .blueprint import bp
99

10-
@bp.route('/upload', methods=['POST'])
10+
11+
@bp.route("/upload", methods=["POST"])
1112
def upload():
12-
return jsonify(message='Search'), 200
13+
return jsonify(message="Search"), 200
14+
1315

1416
ALLOWED_EXTENSIONS = {
1517
"txt",
@@ -69,5 +71,3 @@ def upload_file():
6971
)
7072
else:
7173
return jsonify({"error": "File type not allowed"}), 400
72-
73-

llmsearch/api/search.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from flask import jsonify
22
from .blueprint import bp
33

4-
@bp.route('/hello', methods=['GET'])
5-
def search():
6-
return jsonify(message='Search'), 200
74

5+
@bp.route("/hello", methods=["GET"])
6+
def search():
7+
return jsonify(message="Search"), 200

llmsearch/app.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717

1818

1919
# Create a custom CLI group
20-
cli = AppGroup('cli')
20+
cli = AppGroup("cli")
2121

22-
@cli.command('config')
22+
23+
@cli.command("config")
2324
def dump_config():
2425
"""Show config."""
2526
print("===================================================================")
@@ -45,7 +46,7 @@ def create_app():
4546
template_folder=public_path,
4647
static_url_path="/",
4748
)
48-
app.config.from_object('config.Config')
49+
app.config.from_object("config.Config")
4950
CORS(app)
5051

5152
dash_app = Dash(
@@ -64,7 +65,9 @@ def create_app():
6465
[
6566
dbc.Row(
6667
[
67-
dbc.Col(html.H1("Simple Dash App", className="text-center")),
68+
dbc.Col(
69+
html.H1("Simple Dash App", className="text-center")
70+
),
6871
dbc.Col(
6972
html.P(
7073
"This is a simple web app using Flask and Dash.",
@@ -98,6 +101,7 @@ def main():
98101
## print(f"meme_type={meme_type}")
99102

100103
from env import getenv
104+
101105
host = getenv("HOST")
102106
port = getenv("PORT")
103107
app = create_app()

llmsearch/db.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
def init_db(app):
88
from models import File, User
9+
910
__models = [File, User]
1011

1112
db.init_app(app)

llmsearch/tests/test.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import unittest
2+
from app import app # Assuming your Flask app is in app.py
3+
4+
5+
class FlaskAppTestCase(unittest.TestCase):
6+
def setUp(self):
7+
# Set up the test client
8+
self.app = app.test_client()
9+
self.app.testing = True
10+
11+
def test_hello(self):
12+
# Test the /api/hello route
13+
response = self.app.get("/api/hello")
14+
self.assertEqual(response.status_code, 200)
15+
self.assertEqual(response.json, {"message": "Hello, World!"})
16+
17+
def test_greet_default(self):
18+
# Test the /api/greet route with default name
19+
response = self.app.post("/api/greet", json={})
20+
self.assertEqual(response.status_code, 200)
21+
self.assertEqual(response.json, {"message": "Hello, Guest!"})
22+
23+
def test_greet_with_name(self):
24+
# Test the /api/greet route with a name
25+
response = self.app.post("/api/greet", json={"name": "Alice"})
26+
self.assertEqual(response.status_code, 200)
27+
self.assertEqual(response.json, {"message": "Hello, Alice!"})
28+
29+
def test_greet_with_empty_name(self):
30+
# Test the /api/greet route with an empty name
31+
response = self.app.post("/api/greet", json={"name": ""})
32+
self.assertEqual(response.status_code, 200)
33+
self.assertEqual(response.json, {"message": "Hello, !"})
34+
35+
36+
if __name__ == "__main__":
37+
unittest.main()

llmsearch/web/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from flask import (
2-
Blueprint,
2+
Blueprint,
33
redirect,
44
render_template_string,
55
request,
6-
send_from_directory,
6+
send_from_directory,
77
session,
88
url_for,
9-
)
9+
)
10+
11+
bp = Blueprint("web", __name__, url_prefix="")
1012

11-
bp = Blueprint('web', __name__, url_prefix='')
1213

1314
# @web_blueprint.route("/")
1415
# def home():
@@ -24,6 +25,7 @@
2425
def serve_react_app(path):
2526
return send_from_directory(bp.static_folder, "index.html")
2627

28+
2729
@bp.route("/login", methods=["GET", "POST"])
2830
def login():
2931
if request.method == "POST":
@@ -68,5 +70,3 @@ def about():
6870
<p><a href="/">Back to home</a></p>
6971
"""
7072
)
71-
72-

0 commit comments

Comments
 (0)