Skip to content

Commit

Permalink
Hotfix/project deletion (#104)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

Co-authored-by: Ian Park <[email protected]>
  • Loading branch information
nathanfranklin and duckonomy authored Sep 29, 2022
1 parent 99ef290 commit 5b0658a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 1 addition & 3 deletions geoapi/routes/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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', {
Expand Down
5 changes: 2 additions & 3 deletions geoapi/services/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions geoapi/tests/api_tests/test_projects_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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,
Expand Down

0 comments on commit 5b0658a

Please sign in to comment.