Skip to content

Commit

Permalink
fix sheet restore timeline event status updating (#2070)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Feb 17, 2025
1 parent b741688 commit dba0077
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
26 changes: 19 additions & 7 deletions samplesheets/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
from projectroles.tests.test_views_api import SODARAPIViewTestMixin
from projectroles.utils import build_secret

# Timeline dependency
from timeline.models import TimelineEvent

# Isatemplates dependency
from isatemplates.tests.test_models import (
CookiecutterISATemplateMixin,
Expand Down Expand Up @@ -1279,7 +1282,7 @@ def test_render_no_sheets(self):


class TestSheetVersionRestoreView(SamplesheetsViewTestBase):
"""Tests for the sample sheet version restore view"""
"""Tests for SheetVersionRestoreView"""

def setUp(self):
super().setUp()
Expand All @@ -1291,9 +1294,10 @@ def setUp(self):
)
# Set up helpers
self.cache_backend = get_backend_api('sodar_cache')
self.timeline = get_backend_api('timeline_backend')

def test_render(self):
"""Test rendering the sheet version restore view"""
def test_get(self):
"""Test SheetVersionRestoreView GET"""
with self.login(self.user):
response = self.client.get(
reverse(
Expand All @@ -1304,8 +1308,8 @@ def test_render(self):
self.assertEqual(response.status_code, 200)
self.assertIsNotNone(response.context['sheet_version'])

def test_restore(self):
"""Test restoring sheet version"""
def test_post(self):
"""Test POST"""
sheet_io = SampleSheetIO()
isatab_new = sheet_io.save_isa(
project=self.project,
Expand All @@ -1314,6 +1318,9 @@ def test_restore(self):
)
self.assertEqual(Investigation.objects.count(), 1)
self.assertEqual(ISATab.objects.count(), 2)
self.assertEqual(
TimelineEvent.objects.filter(event_name='sheet_restore').count(), 0
)

with self.login(self.user):
response = self.client.post(
Expand All @@ -1330,9 +1337,14 @@ def test_restore(self):
)
self.assertEqual(Investigation.objects.count(), 1)
self.assertEqual(ISATab.objects.count(), 2)
self.assertEqual(
TimelineEvent.objects.filter(event_name='sheet_restore').count(), 1
)
e = TimelineEvent.objects.filter(event_name='sheet_restore').first()
self.assertEqual(e.get_status().status_type, self.timeline.TL_STATUS_OK)

def test_restore_study_cache(self):
"""Test restoring sheet version with cached study table"""
def test_post_study_cache(self):
"""Test POST with cached study table"""
sheet_io = SampleSheetIO()
isatab_new = sheet_io.save_isa(
project=self.project,
Expand Down
7 changes: 4 additions & 3 deletions samplesheets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2008,7 +2008,8 @@ def get_context_data(self, *args, **kwargs):
return context

def post(self, request, **kwargs):
timeline = get_backend_api('timeline_backend')
if not self.timeline:
self.timeline = get_backend_api('timeline_backend')
tl_event = None
project = self.get_project()
sheet_io = SampleSheetIO(allow_critical=settings.SHEETS_ALLOW_CRITICAL)
Expand Down Expand Up @@ -2036,8 +2037,8 @@ def post(self, request, **kwargs):
)
return redirect(redirect_url)

if timeline:
tl_event = timeline.add_event(
if self.timeline:
tl_event = self.timeline.add_event(
project=project,
app_name=APP_NAME,
user=self.request.user,
Expand Down

0 comments on commit dba0077

Please sign in to comment.