Merge pull request #312 from sartography/study-is-none-329

Study is none #329
This commit is contained in:
Dan Funk 2021-05-14 16:33:04 -04:00 committed by GitHub
commit 77f7fec5d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -163,7 +163,7 @@ def get_task_events(action = None, workflow = None, study = None):
study = session.query(StudyModel).filter(StudyModel.id == event.study_id).first()
workflow = session.query(WorkflowModel).filter(WorkflowModel.id == event.workflow_id).first()
workflow_meta = WorkflowMetadata.from_workflow(workflow)
if study.status in [StudyStatus.open_for_enrollment, StudyStatus.in_progress]:
if study and study.status in [StudyStatus.open_for_enrollment, StudyStatus.in_progress]:
task_events.append(TaskEvent(event, study, workflow_meta))
return TaskEventSchema(many=True).dump(task_events)

View File

@ -0,0 +1,27 @@
from tests.base_test import BaseTest
from crc import session
from crc.models.user import UserModel
from crc.services.user_service import UserService
from crc.services.workflow_service import WorkflowService
from example_data import ExampleDataLoader
import json
class TestWorkflowApi(BaseTest):
def test_get_task_events(self):
self.load_example_data()
spec = ExampleDataLoader().create_spec('hello_world', 'Hello World', category_id=0, standalone=True, from_tests=True)
user = session.query(UserModel).first()
self.assertIsNotNone(user)
WorkflowService.get_workflow_from_spec(spec.id, user)
rv = self.app.get(f'/v1.0/task_events',
follow_redirects=True,
content_type="application/json",
headers=self.logged_in_headers())
self.assert_success(rv)