From 5b0658a08e220e2e4076f8a836eaf0fe0adadd61 Mon Sep 17 00:00:00 2001 From: Nathan Franklin Date: Thu, 29 Sep 2022 10:25:52 -0500 Subject: [PATCH] Hotfix/project deletion (#104) * User logger from geoapi.log * Add missing db_session.commit after project deletion * Add another delete test Note that this test doesn't catch the regression. Not sure why the db_session.commit isn't needed in the unit test. I don't see it but its like the db_session is configured for auto-commit * Update geoapi/tests/api_tests/test_projects_service.py Co-authored-by: Ian Park Co-authored-by: Ian Park --- geoapi/routes/projects.py | 4 +--- geoapi/services/projects.py | 5 ++--- geoapi/tests/api_tests/test_projects_service.py | 7 +++++++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/geoapi/routes/projects.py b/geoapi/routes/projects.py index ac5ebc96..3b0980bb 100644 --- a/geoapi/routes/projects.py +++ b/geoapi/routes/projects.py @@ -2,7 +2,7 @@ from flask_restplus import Resource, Namespace, fields, inputs from werkzeug.datastructures import FileStorage from werkzeug.utils import secure_filename -from geoapi.log import logging +from geoapi.log import logger from geoapi.schemas import FeatureSchema from geoapi.services.features import FeaturesService from geoapi.services.streetview import StreetviewService @@ -15,8 +15,6 @@ not_anonymous, project_admin_or_creator_permissions) -logger = logging.getLogger(__name__) - api = Namespace('projects', decorators=[jwt_decoder]) ok_response = api.model('OkResponse', { diff --git a/geoapi/services/projects.py b/geoapi/services/projects.py index 0ac4fc22..96e5a785 100644 --- a/geoapi/services/projects.py +++ b/geoapi/services/projects.py @@ -12,11 +12,9 @@ from geoapi.utils.assets import get_project_asset_dir from geoapi.utils.users import is_anonymous from geoapi.tasks.external_data import import_from_agave -from geoapi.log import logging +from geoapi.log import logger from geoapi.exceptions import ApiException, ObservableProjectAlreadyExists -logger = logging.getLogger(__name__) - class ProjectsService: """ @@ -274,6 +272,7 @@ def delete(user: User, projectId: int) -> dict: :return: """ db_session.query(Project).filter(Project.id == projectId).delete() + db_session.commit() assets_folder = get_project_asset_dir(projectId) try: diff --git a/geoapi/tests/api_tests/test_projects_service.py b/geoapi/tests/api_tests/test_projects_service.py index 51b9774a..d7f594cc 100644 --- a/geoapi/tests/api_tests/test_projects_service.py +++ b/geoapi/tests/api_tests/test_projects_service.py @@ -4,6 +4,7 @@ from geoapi.services.projects import ProjectsService from geoapi.models import User +from geoapi.models.project import Project from geoapi.exceptions import ObservableProjectAlreadyExists @@ -22,6 +23,12 @@ def test_create_project(): assert proj.description == "test description" +def test_delete_project(projects_fixture, user1): + ProjectsService.delete(user1, projects_fixture.id) + projects = db_session.query(Project).all() + assert projects == [] + + def test_create_observable_project(userdata, get_system_users_mock, agave_utils_with_geojson_file_mock,