diff --git a/src/backend/app.py b/src/backend/app.py index 42148ee58..6173966af 100644 --- a/src/backend/app.py +++ b/src/backend/app.py @@ -1,12 +1,12 @@ """ This is a module docstring """ import json import dataclasses -from collections import namedtuple from werkzeug.datastructures import MultiDict from flask import Flask, request from flask_cors import CORS from pages.login import Login from pages.mainpage import MainPage +from dataholders.mainpage_get import GetRequestType, Params # from logging import FileHandler, WARNING app = Flask(__name__) @@ -67,20 +67,14 @@ def mainpage_get(mainpage_obj: MainPage, args: MultiDict): - Getting reviews of an apartment - Getting pictures of an apartment """ - action_type = namedtuple( - "action_type", ["is_search", "is_populate", "is_review", "is_pictures"] - ) - action = action_type( + action = GetRequestType( args.get("search", default=False, type=bool), args.get("populate", default=False, type=bool), args.get("review", default=False, type=bool), args.get("pictures", default=False, type=bool), ) - params = namedtuple( - "params", ["num_apts", "apt_id", "search_query", "price_sort", "rating_sort"] - ) - param = params( + param = Params( args.get("numApts", type=int), args.get("aptId", type=int), args.get("searchQuery", type=str), @@ -88,6 +82,11 @@ def mainpage_get(mainpage_obj: MainPage, args: MultiDict): args.get("ratingSort", type=int), ) + return mainpage_process_get(mainpage_obj, action, param) + + +def mainpage_process_get(mainpage_obj: MainPage, action: GetRequestType, param: Params): + """Process the get requests""" query_result = "" if action.is_search is True and param.search_query is not None: apts = mainpage_obj.search_apartments(param.search_query) diff --git a/src/backend/database/database_test.db b/src/backend/database/database_test.db index 1b1b8e6d5..fce928f4d 100644 Binary files a/src/backend/database/database_test.db and b/src/backend/database/database_test.db differ diff --git a/src/backend/dataholders/mainpage_get.py b/src/backend/dataholders/mainpage_get.py new file mode 100644 index 000000000..68efbbf6e --- /dev/null +++ b/src/backend/dataholders/mainpage_get.py @@ -0,0 +1,24 @@ +"""Contains dataclasses for mainpage get requests""" +from dataclasses import dataclass +from typing import Union + + +@dataclass +class GetRequestType: + """Specific action of the request""" + + is_search: bool + is_populate: bool + is_review: bool + is_pictures: bool + + +@dataclass +class Params: + """Other request parameters""" + + num_apts: Union[int, None] + apt_id: Union[int, None] + search_query: Union[str, None] + rating_sort: Union[int, None] + price_sort: Union[int, None] diff --git a/src/backend/tests/pytest-coverage.txt b/src/backend/tests/pytest-coverage.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/backend/tests/test_apt.py b/src/backend/tests/test_apt.py deleted file mode 100644 index d1b6735dd..000000000 --- a/src/backend/tests/test_apt.py +++ /dev/null @@ -1,41 +0,0 @@ -"""Test apt.py""" -from dataholders.apt import Apt - - -class TestApt: - """Test Apt class""" - - sample_id = 0 - sample_name = "Sherman Hall" - sample_address = "909 S 5th St" - sample_rating = 3 - sample_price_min = 5500 - sample_price_max = 6500 - sample_apt = Apt( - sample_id, - sample_name, - sample_address, - sample_rating, - sample_price_min, - sample_price_max, - ) - - def test_name(self): - """Test class stores correct name""" - assert self.sample_name == self.sample_apt.name - - def test_address(self): - """Test class stores correct address""" - assert self.sample_address == self.sample_apt.address - - def test_rating(self): - """Test class stores correct rating""" - assert self.sample_rating == self.sample_apt.rating - - def test_price_min(self): - """Test class stores correct min price""" - assert self.sample_price_min == self.sample_apt.price_min - - def test_price_max(self): - """Test class stores correct max price""" - assert self.sample_price_max == self.sample_apt.price_max diff --git a/src/backend/tests/test_decorators.py b/src/backend/tests/test_decorators.py index 16c9ddc3d..6c3aab039 100644 --- a/src/backend/tests/test_decorators.py +++ b/src/backend/tests/test_decorators.py @@ -14,6 +14,7 @@ def insert_review(): ) +@decorators.use_test def test_use_database_raise_exception(): """use_database correctly raises an exception""" connection = sqlite3.connect("database/database_test.db") diff --git a/src/backend/tests/test_review.py b/src/backend/tests/test_review.py deleted file mode 100644 index 61b14daa4..000000000 --- a/src/backend/tests/test_review.py +++ /dev/null @@ -1,28 +0,0 @@ -"""Test review.py""" -from dataholders.review import Review - - -class TestReview: - """Test Review class""" - - sample_username = "Minh Phan" - sample_date = "2022-10-07" - sample_comment = "Decent hall" - sample_vote = True - sample_review = Review(sample_username, sample_date, sample_comment, sample_vote) - - def test_username(self): - """Test class stores correct username""" - assert self.sample_username == self.sample_review.username - - def test_date(self): - """Test class stores correct date""" - assert self.sample_date == self.sample_review.date - - def test_comment(self): - """Test class stores correct comment""" - assert self.sample_comment == self.sample_review.comment - - def test_vote(self): - """Test class stores correct vote""" - assert self.sample_vote == self.sample_review.vote