From 4c680eba20bc52aec0528365ff03affe10dae62b Mon Sep 17 00:00:00 2001 From: Aden Krakman Date: Sun, 23 Oct 2022 21:06:11 -0500 Subject: [PATCH] pylint fixes --- src/backend/app.py | 10 ++++++---- src/backend/apt.py | 6 +++++- src/backend/requirements.txt | 3 ++- src/backend/tests/test_app.py | 7 ++++--- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/backend/app.py b/src/backend/app.py index 449b94d41..50025bd20 100644 --- a/src/backend/app.py +++ b/src/backend/app.py @@ -12,6 +12,7 @@ CORS(app) + @app.route("/login", methods=["POST", "GET"]) def login(): """Handles login routing""" @@ -36,6 +37,7 @@ def register(): return result.message, 400 return result.message, 200 + @app.route("/", methods=["POST", "GET"]) @app.route("/home", methods=["POST", "GET"]) def home(): @@ -51,19 +53,19 @@ def home(): print(type(example), example) json_string = apt_schema.dumps(example, many=True) print(json_string) - #pics = mainpage.get_apartments_pictures(len(apts)) + # pics = mainpage.get_apartments_pictures(len(apts)) if not selected: apts = mainpage.apartments_default(len(apts)) return "success", 200 if ("low-high" in selected and "most popular" in selected) or ( - "low-high" in selected and "high-low" in selected and - "most popular" in selected): # if both prices pressed it will sort low-high + "low-high" in selected and "high-low" in selected and "most popular" in selected + ): # if both prices pressed it will sort low-high apts = mainpage.apartments_sorted(len(apts), -1, -1) elif "high-low" in selected and "most popular" in selected: apts = mainpage.apartments_sorted(len(apts), 1, -1) elif "most popular" in selected: apts = mainpage.apartments_sorted(len(apts), 1, 0) - elif "low-high" in selected: # if both prices pressed it will sort low-high + elif "low-high" in selected: # if both prices pressed it will sort low-high apts = mainpage.apartments_sorted(len(apts), -1, 0) elif "high-low" in selected: apts = mainpage.apartments_sorted(len(apts), 1, 0) diff --git a/src/backend/apt.py b/src/backend/apt.py index ff285d49d..cbf47f8a2 100644 --- a/src/backend/apt.py +++ b/src/backend/apt.py @@ -2,6 +2,7 @@ from dataclasses import dataclass from marshmallow import Schema, fields + @dataclass class Apt: """Apt class, stores detail about an apartment""" @@ -13,7 +14,10 @@ class Apt: price_min: int price_max: int + class ObjectSchema(Schema): + """schema for serializing the Apartment JSON""" + apt_id = fields.Int() name = fields.Str() address = fields.Str() @@ -21,4 +25,4 @@ class ObjectSchema(Schema): image = fields.Str() rating = fields.Int() price_min = fields.Int() - price_max = fields.Int() \ No newline at end of file + price_max = fields.Int() diff --git a/src/backend/requirements.txt b/src/backend/requirements.txt index fa141eee7..e809f294a 100644 --- a/src/backend/requirements.txt +++ b/src/backend/requirements.txt @@ -3,4 +3,5 @@ pytest==7.1.3 pylint==2.15.2 coverage==6.4.4 black==22.8.0 -marshmallow==3.14.1 \ No newline at end of file +marshmallow==3.14.1 +flask_cors==1.10.3 \ No newline at end of file diff --git a/src/backend/tests/test_app.py b/src/backend/tests/test_app.py index 337049248..22efdaecf 100644 --- a/src/backend/tests/test_app.py +++ b/src/backend/tests/test_app.py @@ -86,20 +86,22 @@ def test_login_invalid(client): res = client.post("/login", json=log_info) assert res.status_code == 404 + def test_query_invalid(client): """A query is invalid when a query is empty""" query_info = {"q": "", "selected": []} res = client.post("/home", json=query_info) assert res.status_code == 400 + def test_query_none_selected(client): """Test query""" connection = sqlite3.connect("database/database.db") cursor = connection.cursor() cursor.execute( - "INSERT INTO Apartments (apt_name, apt_address, price_min, price_max, link) \ + "INSERT INTO Apartments (apt_name, apt_address, price_min, price_max, link) \ VALUES (?, ?, ?, ?, ?)", - ("smile", "909 S 5th St", 5500, 6500, ""), + ("smile", "909 S 5th St", 5500, 6500, ""), ) connection.commit() query_info = {"q": "smile", "selected": []} @@ -108,4 +110,3 @@ def test_query_none_selected(client): connection.commit() connection.close() assert res.status_code == 200 - \ No newline at end of file