diff --git a/llmsearch/api/blueprint.py b/llmsearch/api/blueprint.py index 953a624..b15d513 100644 --- a/llmsearch/api/blueprint.py +++ b/llmsearch/api/blueprint.py @@ -1,3 +1,3 @@ from flask import Blueprint -bp = Blueprint('api', __name__, url_prefix='/api') +bp = Blueprint("api", __name__, url_prefix="/api") diff --git a/llmsearch/api/file.py b/llmsearch/api/file.py index 1c70c1d..14b1703 100644 --- a/llmsearch/api/file.py +++ b/llmsearch/api/file.py @@ -1,15 +1,17 @@ import os -from flask import (current_app, jsonify, request) +from flask import current_app, jsonify, request import hashlib from werkzeug.utils import secure_filename from env import getenv from .blueprint import bp -@bp.route('/upload', methods=['POST']) + +@bp.route("/upload", methods=["POST"]) def upload(): - return jsonify(message='Search'), 200 + return jsonify(message="Search"), 200 + ALLOWED_EXTENSIONS = { "txt", @@ -69,5 +71,3 @@ def upload_file(): ) else: return jsonify({"error": "File type not allowed"}), 400 - - diff --git a/llmsearch/api/search.py b/llmsearch/api/search.py index 70c83e3..9cfe42c 100644 --- a/llmsearch/api/search.py +++ b/llmsearch/api/search.py @@ -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 diff --git a/llmsearch/app.py b/llmsearch/app.py index dd96797..e20e697 100644 --- a/llmsearch/app.py +++ b/llmsearch/app.py @@ -17,9 +17,10 @@ # Create a custom CLI group -cli = AppGroup('cli') +cli = AppGroup("cli") -@cli.command('config') + +@cli.command("config") def dump_config(): """Show config.""" print("===================================================================") @@ -45,7 +46,7 @@ def create_app(): template_folder=public_path, static_url_path="/", ) - app.config.from_object('config.Config') + app.config.from_object("config.Config") CORS(app) dash_app = Dash( @@ -64,7 +65,9 @@ def create_app(): [ dbc.Row( [ - dbc.Col(html.H1("Simple Dash App", className="text-center")), + dbc.Col( + html.H1("Simple Dash App", className="text-center") + ), dbc.Col( html.P( "This is a simple web app using Flask and Dash.", @@ -98,6 +101,7 @@ def main(): ## print(f"meme_type={meme_type}") from env import getenv + host = getenv("HOST") port = getenv("PORT") app = create_app() diff --git a/llmsearch/db.py b/llmsearch/db.py index 7a14856..402c4d4 100644 --- a/llmsearch/db.py +++ b/llmsearch/db.py @@ -6,6 +6,7 @@ def init_db(app): from models import File, User + __models = [File, User] db.init_app(app) diff --git a/llmsearch/tests/test.py b/llmsearch/tests/test.py new file mode 100644 index 0000000..8379514 --- /dev/null +++ b/llmsearch/tests/test.py @@ -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() diff --git a/llmsearch/web/__init__.py b/llmsearch/web/__init__.py index 4287e41..693e832 100644 --- a/llmsearch/web/__init__.py +++ b/llmsearch/web/__init__.py @@ -1,14 +1,15 @@ from flask import ( - Blueprint, + Blueprint, redirect, render_template_string, request, -send_from_directory, + send_from_directory, session, url_for, - ) +) + +bp = Blueprint("web", __name__, url_prefix="") -bp = Blueprint('web', __name__, url_prefix='') # @web_blueprint.route("/") # def home(): @@ -24,6 +25,7 @@ def serve_react_app(path): return send_from_directory(bp.static_folder, "index.html") + @bp.route("/login", methods=["GET", "POST"]) def login(): if request.method == "POST": @@ -68,5 +70,3 @@ def about():
""" ) - -