diff --git a/tests/general/test_pep8.py b/tests/general/test_pep8.py index fa2c8ea..38cc521 100644 --- a/tests/general/test_pep8.py +++ b/tests/general/test_pep8.py @@ -6,6 +6,6 @@ import pycodestyle def test_pep8_conformance(): """Test that we conform to PEP8.""" pep8style = pycodestyle.StyleGuide() - dirs = ["./controllers", "./models", "./scripts", "./tests"] + dirs = ["./controllers", "./models", "./scripts", "./tests", "./utils"] result = pep8style.check_files(dirs) assert result.total_errors == 0 diff --git a/utils/file_utils.py b/utils/file_utils.py index be1830e..cf5c3a8 100644 --- a/utils/file_utils.py +++ b/utils/file_utils.py @@ -13,6 +13,7 @@ def allowed_file(filename) -> bool: return '.' in filename and \ filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS + def save_image(file) -> str | None: """ Saves a given file to disk with a random UUID4 generated filename. Returns the filename as a string. @@ -28,6 +29,7 @@ def save_image(file) -> str | None: file.save(os.path.join(path, filename)) return filename + def create_directory(dir: str): """ Creates the given directory string is not alreay made """ try: @@ -35,6 +37,7 @@ def create_directory(dir: str): except FileExistsError: pass + def remove_file(dir: str): """ Removes a given file if it is present at the given dir """ try: diff --git a/utils/user_utils.py b/utils/user_utils.py index 52c06df..6a5f973 100644 --- a/utils/user_utils.py +++ b/utils/user_utils.py @@ -2,12 +2,13 @@ from flask import session from models.users.user import User from controllers.database.user import UserController + def is_logged_in() -> User | None: """ Returns the user object if the user is logged in Otherwise returns a None type """ user_id = session.get('user_id') - + if user_id is not None: db = UserController() return db.read_id(user_id) @@ -22,4 +23,4 @@ def is_role(role: str) -> bool: return user.role == role # User isn't logged in - return False \ No newline at end of file + return False