From ea25116d1c70eadf153167b724932841ce3945dc Mon Sep 17 00:00:00 2001 From: Michael Pilosov Date: Sat, 18 Mar 2023 17:21:35 -0600 Subject: [PATCH] working app --- .gitignore | 2 ++ Dockerfile | 2 +- app/{init.py => __init__.py} | 0 app/routes.py | 3 +++ login_user.sh | 16 ++++++++++++++++ signup_user.sh | 16 ++++++++++++++++ test_app.sh | 13 ++++++++++--- 7 files changed, 48 insertions(+), 4 deletions(-) rename app/{init.py => __init__.py} (100%) create mode 100755 login_user.sh create mode 100755 signup_user.sh mode change 100644 => 100755 test_app.sh diff --git a/.gitignore b/.gitignore index f8b73e7..272f2a0 100644 --- a/.gitignore +++ b/.gitignore @@ -138,3 +138,5 @@ dmypy.json # Cython debug symbols cython_debug/ +# Project-specific files +cookies.txt diff --git a/Dockerfile b/Dockerfile index ca662c5..4dff50e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,4 +9,4 @@ COPY app app EXPOSE 5000 -CMD ["flask", "run", "--host=0.0.0.0"] +CMD ["flask", "run", "--debug", "--host=0.0.0.0"] diff --git a/app/init.py b/app/__init__.py similarity index 100% rename from app/init.py rename to app/__init__.py diff --git a/app/routes.py b/app/routes.py index 848ecb1..141892a 100644 --- a/app/routes.py +++ b/app/routes.py @@ -20,6 +20,9 @@ def process_request(): # Process image, text, and blocks as needed + # log to flask log the blocks list. + app.logger.info(blocks) + app.logger.info(text) return jsonify(success=True) @app.route('/signup', methods=['GET', 'POST']) diff --git a/login_user.sh b/login_user.sh new file mode 100755 index 0000000..7b77f1d --- /dev/null +++ b/login_user.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +if [ "$#" -ne 2 ]; then + echo "Usage: ./login_user.sh " + exit 1 +fi + +USERNAME="$1" +PASSWORD="$2" + +curl -X POST \ + -H "Content-Type: application/x-www-form-urlencoded" \ + -c cookies.txt \ + -d "username=${USERNAME}&password=${PASSWORD}" \ + http://localhost:5000/login + diff --git a/signup_user.sh b/signup_user.sh new file mode 100755 index 0000000..6d4a22f --- /dev/null +++ b/signup_user.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +if [ "$#" -ne 2 ]; then + echo "Usage: ./signup_user.sh " + exit 1 +fi + +USERNAME="$1" +PASSWORD="$2" + +curl -X POST \ + -H "Content-Type: application/x-www-form-urlencoded" \ + -c cookies.txt \ + -d "username=${USERNAME}&password=${PASSWORD}" \ + http://localhost:5000/signup + diff --git a/test_app.sh b/test_app.sh old mode 100644 new mode 100755 index 8aa4082..8b1ff6f --- a/test_app.sh +++ b/test_app.sh @@ -1,14 +1,21 @@ #!/bin/bash -if [ "$#" -ne 1 ]; then - echo "Usage: ./test_app.sh " +if [ "$#" -ne 3 ]; then + echo "Usage: ./test_app.sh " exit 1 fi -IMAGE_PATH="$1" +USERNAME="$1" +PASSWORD="$2" +IMAGE_PATH="$3" + +# Signup and login the user to get the session cookie +./signup_user.sh "${USERNAME}" "${PASSWORD}" +./login_user.sh "${USERNAME}" "${PASSWORD}" curl -X POST \ -H "Content-Type: multipart/form-data" \ + -b cookies.txt \ -F "image=@${IMAGE_PATH}" \ -F "text=Sample Text" \ -F "blocks=Block 1" \