Skip to content

Commit

Permalink
Merge pull request #42 from CS222-UIUC/minh/fixes_database
Browse files Browse the repository at this point in the history
Minh/Touch up app.py and fix decorator test
  • Loading branch information
MinhPhan8803 authored Nov 8, 2022
2 parents a8c61b5 + d1bb346 commit 9c3d454
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 78 deletions.
17 changes: 8 additions & 9 deletions src/backend/app.py
Original file line number Diff line number Diff line change
@@ -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__)
Expand Down Expand Up @@ -67,27 +67,26 @@ 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),
args.get("priceSort", type=int),
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)
Expand Down
Binary file modified src/backend/database/database_test.db
Binary file not shown.
24 changes: 24 additions & 0 deletions src/backend/dataholders/mainpage_get.py
Original file line number Diff line number Diff line change
@@ -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]
Empty file.
41 changes: 0 additions & 41 deletions src/backend/tests/test_apt.py

This file was deleted.

1 change: 1 addition & 0 deletions src/backend/tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
28 changes: 0 additions & 28 deletions src/backend/tests/test_review.py

This file was deleted.

3 comments on commit 9c3d454

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCover
app.py910100%
config.py10100%
decorators.py270100%
dataholders
   apt.py90100%
   mainpage_get.py150100%
   review.py70100%
pages
   login.py310100%
   mainpage.py950100%
TOTAL2760100%

Tests Skipped Failures Errors Time
35 0 💤 0 ❌ 0 🔥 0.611s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCover
app.py910100%
config.py10100%
decorators.py270100%
dataholders
   apt.py90100%
   mainpage_get.py150100%
   review.py70100%
pages
   login.py310100%
   mainpage.py950100%
TOTAL2760100%

Tests Skipped Failures Errors Time
35 0 💤 0 ❌ 0 🔥 0.744s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCover
app.py910100%
config.py10100%
decorators.py270100%
dataholders
   apt.py90100%
   mainpage_get.py150100%
   review.py70100%
pages
   login.py310100%
   mainpage.py950100%
TOTAL2760100%

Tests Skipped Failures Errors Time
35 0 💤 0 ❌ 0 🔥 0.904s ⏱️

Please sign in to comment.