Skip to content

Commit

Permalink
added project cleanup view
Browse files Browse the repository at this point in the history
  • Loading branch information
avikdatta committed Feb 7, 2024
1 parent 48f0ed1 commit fd36a06
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 69 deletions.
2 changes: 1 addition & 1 deletion app/project_cleanup_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def update_trigger_date_for_cleanup(project_cleanup_id: int) -> None:
db.session.rollback()
raise
except Exception as e:
raise ValueError(f"Failed to ad trigger date, error: {e}")
raise ValueError(f"Failed to add trigger date, error: {e}")


class ProjectCleanupPendingView(ModelView):
Expand Down
112 changes: 64 additions & 48 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from .pipeline_trigger_view import PipelineTriggerView
from .index_table_view import ProjectIndexView, SampleIndexView
from .iframe_view import IFrameView
from .project_cleanup_view import ProjectCleanupFinishedView, ProjectCleanupPendingView

"""
Application wide 404 error handler
Expand Down Expand Up @@ -137,6 +138,13 @@ def page_not_found(e):
category_icon="fa-folder-open-o",
icon="fa-upload",
category="Metadata")
appbuilder.\
add_view(
SampleProjectView,
"Latest projects",
category_icon="fa-table",
icon="fa-list-ol",
category="Metadata")
"""
Raw analysis view
"""
Expand Down Expand Up @@ -186,63 +194,71 @@ def page_not_found(e):


"""
Data transfer
Data cleanup
"""
appbuilder.\
add_view(
RDSProjectBackupView,
"Transfer project via RDS",
ProjectCleanupPendingView,
"Cleanup old projects",
category_icon="fa-cubes",
icon="fa-paper-plane",
category="Data transfer")
category="Data cleanup")

appbuilder.\
add_view(
ProjectCleanupFinishedView,
"Removed projects",
category_icon="fa-cubes",
icon="fa-paper-plane",
category="Data cleanup")
"""
Metadata view
"""
appbuilder.\
add_view(
ProjectView,
"Projects",
category_icon="fa-table",
icon="fa-home",
category="Metadata table")
appbuilder.\
add_view_no_menu(SampleView())
appbuilder.\
add_view(
SampleProjectView,
"Samples",
category_icon="fa-table",
icon="fa-list-ol",
category="Metadata table")
appbuilder.\
add_view(
UserView,
"Users",
category_icon="fa-table",
icon="fa-users",
category="Metadata table")
appbuilder.\
add_view(
SeqrunView,
"Sequencing runs",
category_icon="fa-table",
icon="fa-paper-plane-o",
category="Metadata table")
# appbuilder.\
# add_view(
# ProjectView,
# "Projects",
# category_icon="fa-table",
# icon="fa-home",
# category="Metadata table")
# appbuilder.\
# add_view_no_menu(SampleView())
# appbuilder.\
# add_view(
# SampleProjectView,
# "Samples",
# category_icon="fa-table",
# icon="fa-list-ol",
# category="Metadata table")
# appbuilder.\
# add_view(
# UserView,
# "Users",
# category_icon="fa-table",
# icon="fa-users",
# category="Metadata table")
# appbuilder.\
# add_view(
# SeqrunView,
# "Sequencing runs",
# category_icon="fa-table",
# icon="fa-paper-plane-o",
# category="Metadata table")

"""
Index table view
"""
appbuilder.\
add_view(
ProjectIndexView,
"Project index",
category_icon="fa-folder-open-o",
icon="fa-table",
category="Metadata")
appbuilder.\
add_view(
SampleIndexView,
"Sample index",
category_icon="fa-folder-open-o",
icon="fa-table",
category="Metadata")
# appbuilder.\
# add_view(
# ProjectIndexView,
# "Project index",
# category_icon="fa-folder-open-o",
# icon="fa-table",
# category="Metadata")
# appbuilder.\
# add_view(
# SampleIndexView,
# "Sample index",
# category_icon="fa-folder-open-o",
# icon="fa-table",
# category="Metadata")
14 changes: 14 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ def test_client(db):
app.appbuilder.sm.add_permission_view_menu(
"can_list",
"SampleProjectView"))
app.appbuilder.sm.add_permission_role(
admin_role,
app.appbuilder.sm.add_permission_view_menu(
"can_list",
"ProjectCleanupPendingView"))
app.appbuilder.sm.add_permission_role(
admin_role,
app.appbuilder.sm.add_permission_view_menu(
"can_list",
"ProjectCleanupFinishedView"))
app.appbuilder.sm.add_permission_role(
admin_role,
app.appbuilder.sm.add_permission_view_menu(
Expand All @@ -136,6 +146,10 @@ def test_client(db):
admin_role,
app.appbuilder.sm.add_permission_view_menu(
"can_post", "api"))
app.appbuilder.sm.add_permission_role(
admin_role,
app.appbuilder.sm.add_permission_view_menu(
"can_get_project_cleanup_data", "ProjectCleanupApi"))
app.appbuilder.sm.add_permission_role(
admin_role,
app.appbuilder.sm.add_permission_view_menu(
Expand Down
48 changes: 28 additions & 20 deletions tests/test_app_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,28 @@ def test_admin_view(test_client):
assert rv.status_code == 302
rv = test_client.get('/rawmetadatasubmitview/list/')
assert rv.status_code == 302
rv = test_client.get('/projectindexview/list/')
assert rv.status_code == 302
rv = test_client.get('/sampleindexview/list/')
assert rv.status_code == 302
#rv = test_client.get('/projectindexview/list/')
#assert rv.status_code == 302
#rv = test_client.get('/sampleindexview/list/')
#assert rv.status_code == 302
rv = test_client.get('/rawanalysisview/list/')
assert rv.status_code == 302
rv = test_client.get('/analysisview/list/')
assert rv.status_code == 302
rv = test_client.get('/rdsprojectbackupview/list/')
rv = test_client.get('/projectcleanuppendingview/list/')
assert rv.status_code == 302
rv = test_client.get('/projectview/list/')
rv = test_client.get('/projectcleanupfinishedview/list/')
assert rv.status_code == 302
#rv = test_client.get('/rdsprojectbackupview/list/')
#assert rv.status_code == 302
#rv = test_client.get('/projectview/list/')
#assert rv.status_code == 302
rv = test_client.get('/sampleprojectview/list/')
assert rv.status_code == 302
rv = test_client.get('/userview/list/')
assert rv.status_code == 302
rv = test_client.get('/seqrunview/list/')
assert rv.status_code == 302
#rv = test_client.get('/userview/list/')
#assert rv.status_code == 302
#rv = test_client.get('/seqrunview/list/')
#assert rv.status_code == 302
rv = test_client.post("/login/", data=dict(
username='admin',
password='password'
Expand All @@ -53,24 +57,28 @@ def test_admin_view(test_client):
assert rv.status_code == 200
rv = test_client.get('/rawmetadatasubmitview/list/')
assert rv.status_code == 200
rv = test_client.get('/projectindexview/list/')
assert rv.status_code == 200
rv = test_client.get('/sampleindexview/list/')
assert rv.status_code == 200
#rv = test_client.get('/projectindexview/list/')
#assert rv.status_code == 200
#rv = test_client.get('/sampleindexview/list/')
#assert rv.status_code == 200
rv = test_client.get('/rawanalysisview/list/')
assert rv.status_code == 200
rv = test_client.get('/analysisview/list/')
assert rv.status_code == 200
rv = test_client.get('/rdsprojectbackupview/list/')
assert rv.status_code == 200
rv = test_client.get('/projectview/list/')
assert rv.status_code == 200
#rv = test_client.get('/rdsprojectbackupview/list/')
#assert rv.status_code == 200
#rv = test_client.get('/projectview/list/')
#assert rv.status_code == 200
rv = test_client.get('/sampleprojectview/list/')
assert rv.status_code == 200
rv = test_client.get('/userview/list/')
rv = test_client.get('/projectcleanuppendingview/list/')
assert rv.status_code == 200
rv = test_client.get('/seqrunview/list/')
rv = test_client.get('/projectcleanupfinishedview/list/')
assert rv.status_code == 200
#rv = test_client.get('/userview/list/')
#assert rv.status_code == 200
#rv = test_client.get('/seqrunview/list/')
#assert rv.status_code == 200

# def test_view(test_client):
# rv = test_client.get('/admin_home')
Expand Down
47 changes: 47 additions & 0 deletions tests/test_project_cleanup_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os
import requests
from unittest.mock import MagicMock
from app.models import ProjectCleanup
from unittest.mock import patch
from datetime import datetime, timedelta
from app.project_cleanup_view import async_trigger_airflow_cleanup_pipeline

@patch(
'app.project_cleanup_view.trigger_airflow_pipeline',
return_value=requests.patch('https://httpbin.org/patch',
data ={'key': 'value'},
headers={'Content-Type': 'application/json'}))
def test_async_trigger_airflow_cleanup_pipeline(mock_object, db, tmp_path):
project_cleanup1 = \
ProjectCleanup(
user_email='[email protected]',
user_name='e g',
projects='["ProjectA", "ProjectB"]',
deletion_date=datetime.now()+timedelta(days=15),
status='NOT_STARTED',
update_date=datetime.now(),
created_by_fk=1,
changed_by_fk=1)
project_cleanup2 = \
ProjectCleanup(
user_email='[email protected]',
user_name='f h',
projects='["ProjectC", "ProjectD"]',
deletion_date=datetime.now()+timedelta(days=15),
status='NOT_STARTED',
update_date=datetime.now(),
created_by_fk=1,
changed_by_fk=1)
try:
db.session.add(project_cleanup1)
db.session.add(project_cleanup2)
db.session.flush()
db.session.commit()
except:
db.session.rollback()
raise
p = tmp_path / "airflow.json"
os.environ['AIRFLOW_CONF_FILE'] = str(p)
p.write_text('{"url": "url", "username":"username", "password":"password", "test_dag": "test_dag"}')
result = async_trigger_airflow_cleanup_pipeline('test_dag', [{'project_cleanup_id': project_cleanup1.project_cleanup_id}])
assert project_cleanup1.project_cleanup_id in result

0 comments on commit fd36a06

Please sign in to comment.