Date: Mon, 13 May 2024 15:40:01 +0200
Subject: [PATCH 04/18] =?UTF-8?q?=F0=9F=92=8E=20remove=20unused=20import?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
tracex_project/tracex/tests/test_utils.py | 2 --
1 file changed, 2 deletions(-)
diff --git a/tracex_project/tracex/tests/test_utils.py b/tracex_project/tracex/tests/test_utils.py
index 475ed4a5..f73f161c 100644
--- a/tracex_project/tracex/tests/test_utils.py
+++ b/tracex_project/tracex/tests/test_utils.py
@@ -1,6 +1,4 @@
"""Test cases for utils."""
-import os
-
from django.db.models import Q
from django.test import TestCase
import pandas as pd
From 352b312a15015278a1fafa77067733e228cbb04e Mon Sep 17 00:00:00 2001
From: Pit Buttchereit <116184086+PitButtchereit@users.noreply.github.com>
Date: Tue, 14 May 2024 14:06:46 +0200
Subject: [PATCH 05/18] =?UTF-8?q?=E2=9C=A8update=20orchestrator=20tests?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../extraction/tests/test_orchestrator.py | 106 ++++++++++++++++--
1 file changed, 99 insertions(+), 7 deletions(-)
diff --git a/tracex_project/extraction/tests/test_orchestrator.py b/tracex_project/extraction/tests/test_orchestrator.py
index e2dc1bde..3d19826f 100644
--- a/tracex_project/extraction/tests/test_orchestrator.py
+++ b/tracex_project/extraction/tests/test_orchestrator.py
@@ -1,8 +1,18 @@
"""Test cases for the Orchestrator class."""
-from django.test import TestCase
+import pandas as pd
+from django.contrib.sessions.middleware import SessionMiddleware
+from django.test import TestCase, RequestFactory
from extraction.logic.orchestrator import ExtractionConfiguration, Orchestrator
-from extraction.logic.modules import ActivityLabeler
+from extraction.logic.modules import (
+ Preprocessor,
+ ActivityLabeler,
+)
+
+
+class MockConfiguration:
+ """Mock configuration class for testing purposes."""
+ modules = ["Preprocessor", "Cohort Tagger", "ActivityLabeler", "TimeExtractor", "EventTypeClassifier"]
class OrchestratorTests(TestCase):
@@ -10,9 +20,19 @@ class OrchestratorTests(TestCase):
fixtures = ["tracex_project/extraction/fixtures/prompts_fixture.json"]
+ def setUp(self):
+ """Set up method that gets called before every tests are executed."""
+ self.factory = RequestFactory()
+ self.orchestrator = Orchestrator()
+
+ self.orchestrator.get_configuration = lambda: MockConfiguration() # pylint: disable=unnecessary-lambda
+
+ def tearDown(self):
+ """Tear down method that gets called after every test is executed."""
+ Orchestrator.reset_instance()
+
def test_single_instance_creation(self):
"""Tests if two initialized orchestrators are the same instance."""
- Orchestrator.reset_instance()
orchestrator1 = Orchestrator()
orchestrator2 = Orchestrator()
@@ -20,7 +40,6 @@ def test_single_instance_creation(self):
def test_consistent_object_state(self):
"""Tests if the state of the orchestrator instance is the same for two instances."""
- Orchestrator.reset_instance()
orchestrator1 = Orchestrator()
orchestrator2 = Orchestrator()
orchestrator1.data = "test_data"
@@ -29,7 +48,6 @@ def test_consistent_object_state(self):
def test_get_instance_method(self):
"""Tests if the get_instance method returns the same instance and if a new instance is the same instance."""
- Orchestrator.reset_instance()
Orchestrator()
orchestrator1 = Orchestrator.get_instance()
orchestrator2 = Orchestrator.get_instance()
@@ -40,7 +58,6 @@ def test_get_instance_method(self):
def test_reset_instance(self):
"""Tests if reset_instance resets the instance for all objects."""
- Orchestrator.reset_instance()
orchestrator1 = Orchestrator()
Orchestrator.reset_instance()
orchestrator2 = Orchestrator()
@@ -49,7 +66,6 @@ def test_reset_instance(self):
def test_set_configuration(self):
"""Tests if the set_configuration method correctly updates the Orchestrators instance's configuration."""
- Orchestrator.reset_instance()
config = ExtractionConfiguration()
orchestrator = Orchestrator(config)
new_config = ExtractionConfiguration()
@@ -81,3 +97,79 @@ def test_initialize_modules(self):
self.assertIsInstance(modules['activity_labeling'], ActivityLabeler)
self.assertEqual(modules['activity_labeling'].name, "Activity Labeler")
+
+ def test_run(self):
+ """Tests if the run method correctly return a dataframe. Execution of ActivityLabeler and Preprocessor is
+ necessary since the run method makes assumptions on how the patient journey looks like."""
+ Orchestrator.reset_instance()
+ config = ExtractionConfiguration(
+ patient_journey="This is a test patient journey. This is some description about how I fell and and "
+ "recovered in the end.",
+ )
+ config.update(
+ modules={
+ "preprocessing": Preprocessor,
+ "activity_labeling": ActivityLabeler,
+ }
+ )
+ orchestrator = Orchestrator(configuration=config)
+ orchestrator.run()
+
+ self.assertIsNot(orchestrator.get_data(), None)
+ self.assertIsInstance(orchestrator.get_data(), pd.DataFrame)
+
+ def test_set_db_objects_id(self):
+ """Test if the set_db_objects_id method correctly sets the object ID."""
+ object_name = "test_object"
+ object_id = 123
+
+ self.orchestrator.set_db_objects_id(object_name, object_id)
+
+ self.assertEqual(self.orchestrator.db_objects_id[object_name], object_id)
+
+ def test_get_db_objects_id(self):
+ """Test if the get_db_objects_id method returns the correct object ID."""
+ object_name = "test_object"
+ object_id = 456
+
+ self.orchestrator.set_db_objects_id(object_name, object_id)
+ retrieved_id = self.orchestrator.get_db_objects_id(object_name)
+
+ self.assertEqual(retrieved_id, object_id)
+
+ def test_get_db_objects_id_key_error(self):
+ """Test if the get_db_objects_id method raises a KeyError when the object name is not found."""
+ object_name = "non_existent_object"
+
+ with self.assertRaises(KeyError):
+ self.orchestrator.get_db_objects_id(object_name)
+
+ def test_update_progress_with_view(self):
+ """Tests if the progress of the views are updated correctly."""
+ request = self.factory.get("/extraction/filter")
+ middleware = SessionMiddleware(lambda req: req)
+ middleware.process_request(request)
+ request.session.save()
+
+ class MockView:
+ """Mock View class for testing purposes."""
+ def __init__(self, request):
+ self.request = request
+
+ view = MockView(request)
+ current_step = 2
+ module_name = "Activity Labeler"
+
+ self.orchestrator.update_progress(view, current_step, module_name)
+
+ self.assertEqual(request.session["progress"], 40) # 2/5 = 0.4 * 100 = 40
+ self.assertEqual(request.session["status"], module_name)
+
+ def test_update_progress_without_view(self):
+ """Tests if the progress of the views are updated correctly."""
+ current_step = 2
+ module_name = "Activity Labeler"
+
+ self.orchestrator.update_progress(None, current_step, module_name)
+
+ # No assertions needed since the method should just return without updating the session
From 729eb6c11317608abb1fe36f0ea22e782695e5e2 Mon Sep 17 00:00:00 2001
From: Pit Buttchereit <116184086+PitButtchereit@users.noreply.github.com>
Date: Wed, 15 May 2024 13:46:47 +0200
Subject: [PATCH 06/18] =?UTF-8?q?=F0=9F=92=8E=20update=20comments?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
tracex_project/extraction/tests/test_orchestrator.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tracex_project/extraction/tests/test_orchestrator.py b/tracex_project/extraction/tests/test_orchestrator.py
index 3d19826f..94b59ee1 100644
--- a/tracex_project/extraction/tests/test_orchestrator.py
+++ b/tracex_project/extraction/tests/test_orchestrator.py
@@ -21,7 +21,7 @@ class OrchestratorTests(TestCase):
fixtures = ["tracex_project/extraction/fixtures/prompts_fixture.json"]
def setUp(self):
- """Set up method that gets called before every tests are executed."""
+ """Set up method that gets called everytime before tests are executed."""
self.factory = RequestFactory()
self.orchestrator = Orchestrator()
From 819153e6c1c4fc5b4a0b2778eb5dab98ba71e1b5 Mon Sep 17 00:00:00 2001
From: Pit Buttchereit <116184086+PitButtchereit@users.noreply.github.com>
Date: Fri, 17 May 2024 11:57:22 +0200
Subject: [PATCH 07/18] =?UTF-8?q?=F0=9F=92=8E=20update=20comments?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
tracex_project/extraction/tests/test_orchestrator.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tracex_project/extraction/tests/test_orchestrator.py b/tracex_project/extraction/tests/test_orchestrator.py
index 94b59ee1..de25555e 100644
--- a/tracex_project/extraction/tests/test_orchestrator.py
+++ b/tracex_project/extraction/tests/test_orchestrator.py
@@ -20,14 +20,14 @@ class OrchestratorTests(TestCase):
fixtures = ["tracex_project/extraction/fixtures/prompts_fixture.json"]
- def setUp(self):
+ def setUp(self): # pylint: disable=invalid-name
"""Set up method that gets called everytime before tests are executed."""
self.factory = RequestFactory()
self.orchestrator = Orchestrator()
self.orchestrator.get_configuration = lambda: MockConfiguration() # pylint: disable=unnecessary-lambda
- def tearDown(self):
+ def tearDown(self): # pylint: disable=invalid-name
"""Tear down method that gets called after every test is executed."""
Orchestrator.reset_instance()
From c3aa3780da76e9f761354aef685fb5e745026509 Mon Sep 17 00:00:00 2001
From: Pit Buttchereit <116184086+PitButtchereit@users.noreply.github.com>
Date: Fri, 17 May 2024 12:24:20 +0200
Subject: [PATCH 08/18] =?UTF-8?q?=E2=9C=A8add=20test=5Fviews=20for=20extra?=
=?UTF-8?q?ction=20app?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../extraction/tests/test_modules.py | 2 +-
tracex_project/extraction/tests/test_views.py | 35 +++++++++++++++++++
2 files changed, 36 insertions(+), 1 deletion(-)
create mode 100644 tracex_project/extraction/tests/test_views.py
diff --git a/tracex_project/extraction/tests/test_modules.py b/tracex_project/extraction/tests/test_modules.py
index 48c5f2e4..d6aa188e 100644
--- a/tracex_project/extraction/tests/test_modules.py
+++ b/tracex_project/extraction/tests/test_modules.py
@@ -1,4 +1,4 @@
-"""Test cases for the extraction app."""
+"""Test cases for the modules in the extraction app."""
from django.test import TestCase
import pandas as pd
diff --git a/tracex_project/extraction/tests/test_views.py b/tracex_project/extraction/tests/test_views.py
new file mode 100644
index 00000000..eed9cb58
--- /dev/null
+++ b/tracex_project/extraction/tests/test_views.py
@@ -0,0 +1,35 @@
+"""Test cases for the views of the extraction app."""
+from django.test import TestCase
+from django.urls import reverse
+
+
+class JourneyInputSelectViewTests(TestCase):
+ """Test cases for the JourneyInputSelectView."""
+ def test_view_get_request(self):
+ """Tests that the view URL exists and is accessible by passing a GET request."""
+ response = self.client.get(reverse("choose_input_method"))
+
+ self.assertEqual(response.status_code, 200)
+
+ def test_view_post_request(self):
+ """
+ Test that a POST request to the view returns a method not allowed error since the JourneyInputSelectView
+ is a simple TemplateView that does not handle POST request.
+ """
+ response = self.client.post(reverse('choose_input_method'))
+
+ self.assertEqual(response.status_code, 405)
+
+ def test_view_uses_correct_template(self):
+ """Tests that the view uses the correct template."""
+ response = self.client.get(reverse("choose_input_method"))
+
+ self.assertTemplateUsed(response, "choose_input_method.html")
+
+ def test_view_context_data(self):
+ """Test that the view doesn't pass any context data."""
+ response = self.client.get(reverse('choose_input_method'))
+
+ self.assertFalse('context_data_key' in response.context)
+
+
From 0bdb9694ca90ebab3f59fc694c153621abc0192a Mon Sep 17 00:00:00 2001
From: Pit Buttchereit <116184086+PitButtchereit@users.noreply.github.com>
Date: Fri, 17 May 2024 14:15:52 +0200
Subject: [PATCH 09/18] =?UTF-8?q?=E2=9C=A8add=20more=20view=20tests?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
tracex_project/extraction/tests/test_views.py | 82 +++++++++++++++++--
1 file changed, 75 insertions(+), 7 deletions(-)
diff --git a/tracex_project/extraction/tests/test_views.py b/tracex_project/extraction/tests/test_views.py
index eed9cb58..64e0a38a 100644
--- a/tracex_project/extraction/tests/test_views.py
+++ b/tracex_project/extraction/tests/test_views.py
@@ -1,35 +1,103 @@
"""Test cases for the views of the extraction app."""
-from django.test import TestCase
-from django.urls import reverse
+from unittest import mock
+
+from django.core.files.uploadedfile import SimpleUploadedFile
+from django.test import TestCase, Client
+from django.urls import reverse, resolve
+
+from extraction.forms import (
+ JourneyUploadForm,
+)
+from extraction.models import (
+ PatientJourney,
+)
+from extraction.views import (
+ JourneyInputSelectView,
+ JourneyUploadView,
+)
class JourneyInputSelectViewTests(TestCase):
"""Test cases for the JourneyInputSelectView."""
+
+ def setUp(self): # pylint: disable=invalid-name
+ """Set up method that gets called everytime before tests are executed."""
+ self.url = reverse('choose_input_method')
+
def test_view_get_request(self):
"""Tests that the view URL exists and is accessible by passing a GET request."""
- response = self.client.get(reverse("choose_input_method"))
+ response = self.client.get(self.url)
+ resolver = resolve(self.url)
self.assertEqual(response.status_code, 200)
+ self.assertEqual(resolver.func.view_class, JourneyInputSelectView)
def test_view_post_request(self):
"""
Test that a POST request to the view returns a method not allowed error since the JourneyInputSelectView
is a simple TemplateView that does not handle POST request.
"""
- response = self.client.post(reverse('choose_input_method'))
+ response = self.client.post(self.url)
self.assertEqual(response.status_code, 405)
def test_view_uses_correct_template(self):
"""Tests that the view uses the correct template."""
- response = self.client.get(reverse("choose_input_method"))
+ response = self.client.get(self.url)
- self.assertTemplateUsed(response, "choose_input_method.html")
+ self.assertTemplateUsed(response, 'choose_input_method.html')
def test_view_context_data(self):
"""Test that the view doesn't pass any context data."""
- response = self.client.get(reverse('choose_input_method'))
+ response = self.client.get(self.url)
self.assertFalse('context_data_key' in response.context)
+class JourneyUploadViewTests(TestCase):
+ """Test cases for the JourneyUploadView."""
+
+ def setUp(self): # pylint: disable=invalid-name
+ """Set up method that gets called everytime before tests are executed."""
+ self.client = Client()
+ self.url = reverse('journey_upload')
+
+ def test_view_get_request(self):
+ """Tests that the view URL exists and is accessible by passing a GET request."""
+ response = self.client.get(self.url)
+ resolver = resolve(self.url)
+
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(resolver.func.view_class, JourneyUploadView)
+
+ def test_view_uses_correct_template(self):
+ """Tests that the view uses the correct template."""
+ response = self.client.get(self.url)
+
+ self.assertTemplateUsed(response, 'upload_journey.html')
+
+ def test_view_uses_correct_form(self):
+ """Tests that the view uses the correct form."""
+ response = self.client.get(self.url)
+
+ self.assertIsInstance(response.context['form'], JourneyUploadForm)
+
+ def test_view_post_valid_form(self):
+ """
+ Test that posting a valid form with a file upload successfully creates
+ a new model instance with the uploaded content and redirects to the correct success URL.
+ """
+ file_content = 'This is a test patient journey.'
+ uploaded_file = SimpleUploadedFile('test.txt', file_content.encode('utf-8'))
+ form_data = {'name': 'Test Journey', 'file': uploaded_file}
+
+ response = self.client.post(self.url, form_data, format='multipart')
+ # Response Code 200 means that the form validation failed and same view is rendered
+ if response.status_code == 200:
+ print(response.context['form'].errors)
+ mock_journey = PatientJourney.manager.first()
+
+ self.assertEqual(response.status_code, 302) # Response Code 302 means that the form was successfully submitted
+ self.assertEqual(PatientJourney.manager.count(), 1)
+ self.assertEqual(mock_journey.patient_journey, file_content)
+ self.assertRedirects(response, reverse('journey_details', kwargs={'pk': mock_journey.id}))
From 58e0e9a7b724402c800ef0414823fedcfc068c0f Mon Sep 17 00:00:00 2001
From: Pit Buttchereit <116184086+PitButtchereit@users.noreply.github.com>
Date: Mon, 20 May 2024 14:43:44 +0200
Subject: [PATCH 10/18] =?UTF-8?q?=E2=9C=A8add=20more=20view=20tests?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
tracex_project/extraction/tests/test_views.py | 285 +++++++++++++++++-
1 file changed, 279 insertions(+), 6 deletions(-)
diff --git a/tracex_project/extraction/tests/test_views.py b/tracex_project/extraction/tests/test_views.py
index 64e0a38a..e0be9f32 100644
--- a/tracex_project/extraction/tests/test_views.py
+++ b/tracex_project/extraction/tests/test_views.py
@@ -1,12 +1,16 @@
"""Test cases for the views of the extraction app."""
-from unittest import mock
+import json
+from django import forms
from django.core.files.uploadedfile import SimpleUploadedFile
-from django.test import TestCase, Client
+from django.test import TestCase, Client, RequestFactory
from django.urls import reverse, resolve
from extraction.forms import (
JourneyUploadForm,
+ JourneySelectForm,
+ FilterForm,
+ ResultForm
)
from extraction.models import (
PatientJourney,
@@ -14,6 +18,10 @@
from extraction.views import (
JourneyInputSelectView,
JourneyUploadView,
+ JourneySelectView,
+ JourneyDetailView,
+ JourneyFilterView,
+ ResultView,
)
@@ -82,6 +90,12 @@ def test_view_uses_correct_form(self):
self.assertIsInstance(response.context['form'], JourneyUploadForm)
+ def test_view_context_data(self):
+ """Test that the view doesn't pass any context data."""
+ response = self.client.get(self.url)
+
+ self.assertFalse('context_data_key' in response.context)
+
def test_view_post_valid_form(self):
"""
Test that posting a valid form with a file upload successfully creates
@@ -91,13 +105,272 @@ def test_view_post_valid_form(self):
uploaded_file = SimpleUploadedFile('test.txt', file_content.encode('utf-8'))
form_data = {'name': 'Test Journey', 'file': uploaded_file}
- response = self.client.post(self.url, form_data, format='multipart')
- # Response Code 200 means that the form validation failed and same view is rendered
- if response.status_code == 200:
- print(response.context['form'].errors)
+ response = self.client.post(self.url, data=form_data, format='multipart')
mock_journey = PatientJourney.manager.first()
self.assertEqual(response.status_code, 302) # Response Code 302 means that the form was successfully submitted
self.assertEqual(PatientJourney.manager.count(), 1)
self.assertEqual(mock_journey.patient_journey, file_content)
self.assertRedirects(response, reverse('journey_details', kwargs={'pk': mock_journey.id}))
+
+ def test_view_post_invalid_form(self):
+ """Tests that posting an invalid form (without a file) returns the same page with a form error."""
+ form_data = {}
+ response = self.client.post(self.url, data=form_data)
+
+ self.assertEqual(response.status_code, 200)
+ self.assertFormError(response, 'form', 'file', 'This field is required.')
+
+
+class JourneySelectViewTests(TestCase):
+ """Test cases for the JourneySelectView."""
+
+ def setUp(self): # pylint: disable=invalid-name
+ """Set up method that gets called everytime before tests are executed."""
+ self.client = Client()
+ self.url = reverse('journey_select')
+
+ def test_view_get_request(self):
+ """Tests that the view URL exists and is accessible by passing a GET request."""
+ response = self.client.get(self.url)
+ resolver = resolve(self.url)
+
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(resolver.func.view_class, JourneySelectView)
+
+ def test_view_uses_correct_template(self):
+ """Tests that the view uses the correct template."""
+ response = self.client.get(self.url)
+
+ self.assertTemplateUsed(response, 'select_journey.html')
+
+ def test_view_uses_correct_form(self):
+ """Tests that the view uses the correct form."""
+ response = self.client.get(self.url)
+
+ self.assertIsInstance(response.context['form'], JourneySelectForm)
+
+ def test_view_context_data(self):
+ """Test that the view passes no context data."""
+ response = self.client.get(self.url)
+
+ self.assertFalse('context_data_key' in response.context)
+
+ def test_view_post_valid_form(self):
+ """
+ Test that posting a valid form by selecting an existing patient journey redirects to the correct success URL.
+ """
+ mock_journey = PatientJourney.manager.create(name='Test Journey',
+ patient_journey='This is a test patient journey.')
+ form_data = {'selected_patient_journey': mock_journey.name}
+ response = self.client.post(self.url, data=form_data, format='multipart')
+
+ self.assertEqual(response.status_code, 302) # Response Code 302 means that the form was successfully submitted
+ self.assertEqual(mock_journey.name, form_data['selected_patient_journey'])
+ self.assertRedirects(response, reverse('journey_details', kwargs={'pk': mock_journey.id}))
+
+ def test_view_post_invalid_form(self):
+ """Tests that posting an invalid form (without selecting a file) returns the same page with a form error."""
+ form_data = {}
+ response = self.client.post(self.url, data=form_data)
+
+ self.assertEqual(response.status_code, 200)
+ self.assertFormError(response, 'form', 'selected_patient_journey', 'This field is required.')
+
+
+class JourneyDetailViewTests(TestCase):
+ """Test cases for the JourneyDetailView."""
+
+ def setUp(self): # pylint: disable=invalid-name
+ """Set up method that gets called everytime before tests are executed."""
+ self.client = Client()
+ self.mock_journey = PatientJourney.manager.create(name='Test Journey',
+ patient_journey='This is a test patient journey.')
+ self.url = reverse('journey_details', kwargs={'pk': self.mock_journey.pk})
+
+ def test_view_get_request(self):
+ """Tests that the view URL exists and is accessible by passing a GET request."""
+ response = self.client.get(self.url)
+ resolver = resolve(self.url)
+
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(resolver.func.view_class, JourneyDetailView)
+
+ def test_uses_correct_template(self):
+ """Tests that the view uses the correct template."""
+ response = self.client.get(self.url)
+
+ self.assertTemplateUsed(response, 'journey_details.html')
+
+ def test_view_context_data(self):
+ """Test that the view passes the correct context data."""
+ response = self.client.get(self.url)
+
+ self.assertIn('patient_journey', response.context)
+ self.assertEqual(response.context['patient_journey'], self.mock_journey)
+ self.assertEqual(self.client.session.get('patient_journey_id'), self.mock_journey.id)
+
+ def test_view_without_patient_journey(self):
+ """Test that requesting a patient journey that does not exist returns a 404 error."""
+ response = self.client.get(reverse('journey_details', kwargs={'pk': 999}))
+
+ self.assertEqual(response.status_code, 404)
+
+ def test_post_method_redirect(self):
+ """Test that a POST request to the view redirects to the same page."""
+ # Perform a GET request to set up session data
+ response = self.client.get(self.url)
+
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(self.client.session['patient_journey_id'], self.mock_journey.id)
+
+ # Perform a POST request to the same view
+ response = self.client.post(self.url)
+
+ self.assertEqual(response.status_code, 302)
+ self.assertRedirects(response, reverse('journey_filter'))
+
+
+class JourneyFilterViewTests(TestCase):
+ """Test cases for the JourneyFilterView."""
+
+ fixtures = ["tracex_project/extraction/fixtures/prompts_fixture.json"]
+
+ @staticmethod
+ def dummy_get_response():
+ """This is a dummy function to satisfy the get_response parameter of the SessionMiddleware."""
+ return None
+
+ def setUp(self): # pylint: disable=invalid-name
+ """Set up method that gets called everytime before tests are executed."""
+ self.client = Client()
+ self.mock_journey = PatientJourney.manager.create(name='Test Journey',
+ patient_journey='This is a test patient journey.')
+ self.url = reverse('journey_filter')
+ self.factory = RequestFactory()
+
+ def test_view_get_request(self):
+ """Tests that the view URL exists and is accessible by passing a GET request."""
+ response = self.client.get(self.url)
+ resolver = resolve(self.url)
+
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(resolver.func.view_class, JourneyFilterView)
+
+ def test_uses_correct_template(self):
+ """Tests that the view uses the correct template."""
+ response = self.client.get(self.url)
+
+ self.assertTemplateUsed(response, 'filter_journey.html')
+
+ def test_view_uses_correct_form(self):
+ """Tests that the view uses the correct form."""
+ response = self.client.get(self.url)
+
+ self.assertIsInstance(response.context['form'], FilterForm)
+
+ def test_get_context_data(self):
+ """Test that the `is_comparing` context variable is added correctly in the `get_context_data` method."""
+ request = self.factory.get(self.url)
+ request.session = {}
+ view = JourneyFilterView()
+ view.request = request
+ context = view.get_context_data()
+
+ self.assertIn('is_comparing', context)
+
+ # Non-deterministic test since orchestrator is executed
+ def test_form_valid(self):
+ """Test that a valid form submission redirects to the correct URL."""
+ form_data = {
+ 'modules_required': ['activity_labeling'],
+ 'modules_optional': ['preprocessing', 'event_type_classification'],
+ 'event_types': ['Symptom Onset', 'Symptom Offset'],
+ 'locations': ['Home', 'Hospital', 'Doctors', 'N/A'],
+ 'activity_key': 'event_type',
+ }
+ # Set up session data
+ session = self.client.session
+ session['is_comparing'] = False
+ session.save()
+
+ # Submit the form using the test client
+ response = self.client.post(self.url, data=form_data)
+
+ self.assertEqual(response.status_code, 302)
+ self.assertRedirects(response, reverse('result'))
+
+ def test_get_ajax(self):
+ """
+ Test the `get` method when an AJAX request is made.
+ Ensure that the correct JSON response is returned with the progress and status information.
+ """
+ request = self.factory.get(self.url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
+ request.session = {'progress': 50, 'status': 'running'}
+ view = JourneyFilterView()
+ view.request = request
+ response = view.get(request)
+
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(json.loads(response.content), {'progress': 50, 'status': 'running'})
+
+
+class ResultViewTests(TestCase):
+ """Test cases for the ResultView."""
+ def setUp(self): # pylint: disable=invalid-name
+ """Set up method that gets called everytime before tests are executed."""
+ self.client = Client()
+ self.mock_journey = PatientJourney.manager.create(name='Test Journey',
+ patient_journey='This is a test patient journey.')
+ self.session = self.client.session
+ self.session['selected_modules'] = ['activity_labeling']
+ self.session.save()
+ self.url = reverse('result')
+
+ def test_view_get_request(self):
+ """Tests that the view URL exists and is accessible by passing a GET request."""
+ response = self.client.get(self.url)
+ resolver = resolve(self.url)
+
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(resolver.func.view_class, ResultView)
+
+ def test_uses_correct_template(self):
+ """Tests that the view uses the correct template."""
+ response = self.client.get(self.url)
+
+ self.assertTemplateUsed(response, 'result.html')
+
+ def test_uses_correct_form(self):
+ """Tests that the view uses the correct form."""
+ response = self.client.get(self.url)
+
+ self.assertIsInstance(response.context['form'], ResultForm)
+
+ def test_get_form_kwargs(self):
+ """Tests that correct form kwargs are passed to the form."""
+ response = self.client.get(self.url)
+
+ self.assertEqual(response.status_code, 200)
+
+ form = response.context['form']
+
+ self.assertIsInstance(form, ResultForm)
+ self.assertEqual((form.initial['selected_modules']), self.session['selected_modules'])
+
+ def test_get_context_data(self):
+ """Tests that the view fetches the correct context data."""
+ response = self.client.get(self.url)
+
+ self.assertEqual(response.status_code, 200)
+
+ context = response.context
+
+ self.assertIn('form', context)
+ self.assertIsInstance(context['form'], ResultForm)
+ self.assertIn('journey', context)
+ self.assertEqual(context['journey'], self.mock_journey.patient_journey)
+ self.assertIn('dfg_img', context)
+ self.assertIn('trace_table', context)
+ self.assertIn('all_dfg_img', context)
+ self.assertIn('event_log_table', context)
From cabb0719ed7e2b62f91ba922acfcf4e1b8896de8 Mon Sep 17 00:00:00 2001
From: Pit Buttchereit <116184086+PitButtchereit@users.noreply.github.com>
Date: Mon, 20 May 2024 14:44:23 +0200
Subject: [PATCH 11/18] remove unused import
---
tracex_project/extraction/tests/test_views.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/tracex_project/extraction/tests/test_views.py b/tracex_project/extraction/tests/test_views.py
index e0be9f32..fedc18e6 100644
--- a/tracex_project/extraction/tests/test_views.py
+++ b/tracex_project/extraction/tests/test_views.py
@@ -1,7 +1,6 @@
"""Test cases for the views of the extraction app."""
import json
-from django import forms
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase, Client, RequestFactory
from django.urls import reverse, resolve
From b045152f9746e6966adde16e4444e1a761454a10 Mon Sep 17 00:00:00 2001
From: Pit Buttchereit <116184086+PitButtchereit@users.noreply.github.com>
Date: Tue, 21 May 2024 10:06:46 +0200
Subject: [PATCH 12/18] =?UTF-8?q?=F0=9F=90=9B=20fix=20keyword=20arguments?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
tracex_project/extraction/tests/test_views.py | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/tracex_project/extraction/tests/test_views.py b/tracex_project/extraction/tests/test_views.py
index fedc18e6..75a443a9 100644
--- a/tracex_project/extraction/tests/test_views.py
+++ b/tracex_project/extraction/tests/test_views.py
@@ -118,7 +118,13 @@ def test_view_post_invalid_form(self):
response = self.client.post(self.url, data=form_data)
self.assertEqual(response.status_code, 200)
- self.assertFormError(response, 'form', 'file', 'This field is required.')
+ self.assertFormError(
+ response=response,
+ form='form',
+ field='file',
+ errors='This field is required.',
+ msg_prefix='Invalid form submission'
+ )
class JourneySelectViewTests(TestCase):
@@ -174,7 +180,13 @@ def test_view_post_invalid_form(self):
response = self.client.post(self.url, data=form_data)
self.assertEqual(response.status_code, 200)
- self.assertFormError(response, 'form', 'selected_patient_journey', 'This field is required.')
+ self.assertFormError(
+ response=response,
+ form='form',
+ field='selected_patient_journey',
+ errors='This field is required.',
+ msg_prefix='Invalid form submission'
+ )
class JourneyDetailViewTests(TestCase):
From ec00e6a8e5499a1d2eef4d936e93e1398dd51c7a Mon Sep 17 00:00:00 2001
From: Pit Buttchereit <116184086+PitButtchereit@users.noreply.github.com>
Date: Tue, 21 May 2024 10:07:01 +0200
Subject: [PATCH 13/18] =?UTF-8?q?=F0=9F=92=8E=20add=20spacing?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
tracex_project/tracex/views.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tracex_project/tracex/views.py b/tracex_project/tracex/views.py
index 3f4867df..06db54b5 100644
--- a/tracex_project/tracex/views.py
+++ b/tracex_project/tracex/views.py
@@ -10,6 +10,7 @@
from django.urls import reverse_lazy
from tracex.forms import ApiKeyForm
+
class TracexLandingPage(TemplateView):
"""View for the landing page of the tracex app."""
template_name = "landing_page.html"
@@ -44,6 +45,7 @@ def get_context_data(self, **kwargs):
return context
+
class ResetApiKey(RedirectView):
"""View for the resetting the API key."""
From 41c8af690fe991dc5eedd854d5502f38807fc07a Mon Sep 17 00:00:00 2001
From: Pit Buttchereit <116184086+PitButtchereit@users.noreply.github.com>
Date: Tue, 21 May 2024 10:35:08 +0200
Subject: [PATCH 14/18] =?UTF-8?q?=F0=9F=90=9B=20fix=20cohort=20database=20?=
=?UTF-8?q?bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
tracex_project/db.sqlite3 | Bin 356352 -> 356352 bytes
.../extraction/fixtures/prompts_fixture.json | 6 +-
.../extraction/logic/orchestrator.py | 2 +-
.../extraction/tests/test_orchestrator.py | 2 +-
.../tracex/fixtures/dataframe_fixtures.json | 746 ++++++++++++++++--
5 files changed, 676 insertions(+), 80 deletions(-)
diff --git a/tracex_project/db.sqlite3 b/tracex_project/db.sqlite3
index 3cd604e19d54b8c5b39440fe90c83349715804a7..03d2a224e664f4f4cd6d1ee47536361856f4e479 100644
GIT binary patch
delta 1787
zcmah}UrbY17{BM-+ZIUMTY*{yalmjQPQf^Cop?{!|
z8L`OBL=#Oj@55q3_Tcs)8LXRkzAPhq+JoEFm@Ljjvnn?
zcYgWuo$q|#?|gIjv~%~g=V~{J2!b4xY)~>xvdib&j4}~vPrknzUc%8Bw?ehHZ$37HCY+bI@Tgb8cviy
z>r4fbY@DBB10jBlPo@JAHW6l%PfsZ}oA*^$H6+4;IGm|v;NuGMl)$H?5Uoq
z!CFuT2o3XaGup0g$=_&y6X^1!VGG!m?=gG|T0bT}-3?!xN*4U~-0^j`Kcu
zVkBgt4>kG6i9^|-aXJ+43J#4Xs4Sge`{T~>OgGilyMK1l(?uUJWINNNiO}oMrNY=q
zx}9QZBSjV(`5)@bQ2Y<6e#me^dF~fnS1mzXg|zIIRp57!O4WWu-KmP?E0!7yBynGv
zuUqbEYC^q$oUlY@$GAzJVpy8DgqW!aHyupIX4yn^%s3q_EH2Odsn(Uhgg
ze^qu@)GUE(WePb8paST`pFRZJ6{xPfPE@RbTL4Pn&MN3olpLVs&~z2tqtQy$4Nd7N4l-VM#KLQ%6C;>!JKE$qxU$0|VAS(4kJpBNhRicOn5f%I3BZG)7
zp^tC@%)y%SzhoBG3DpT@Q5;`D;l~`T#phv4p<@`Z@Jc#(bet`5?iv`TTk*kuBUN0eG=_uF%n#I-A@NZztH9qkOl@d&_
z(}BSMdJYtY&AyOqF6O^oSPTNC@as{~E?|qWOYTX_bpb}0TYy_i&x8T8v|}A7$mFT(
zXQ6ogENZOWT&})^;J@KF@iqJ-{35=H&)^aDB}olu)WVs)aP7E8UnbR}PBI5S#f9}G
zqiNf~v~FNpHZZ$3FwM_1x}9YRKx%6dq}HCua%_6WUh{abe68r)P|6|^%A``#AHT4I
zZUqxU%?dhvJgvpNGxnFsmNgPKGR1gOgsqGBx~JR}AGJ6M-$XQQ3T1l7V&icK7q?g<
zt{CU{_+r_l)kB0H|FP%gX(ky{Zg;iJds1fS#QQ7gCc}k&u%@tS?kXnPZ#
zl2;%o8b_3V`DQdOG(5yUD{A-yD8`N0MW~e?q(qE$-?<$9?#ooUyoe2A6^;E4<&uCJ
z+v?vvk1@i(6c#E8D*gb|m4GCFr>L@F9kBR2nneE|?2`vtRKhzXD-O?rA}?8kxQ&qg
zjBDhoP6U4kuT;OMZc;6)I;9?ys-0|3SB~Hg;0M6YNJ;b`7z_;BT>)>W-*0zy`skA%qrT6Nq`kNLX7nT&O0#_6yR+lko3Ffn4G&3&1)Gd-#gFyjFSkqiw_
z4fsiYG}F!bdb0X7;k5eQLvHJkg(Nw@F~gZ>W4$TP$t1@~R}XzC5-?im{k~pCAMA{U
zUGBk%BQi$zrFtALr^m~A`}mlNIl%Xg+r!2*9~=(*%;9Xr#dTY`?*7R>)9AD_8i|Gn
zo~no@XsdmM?HzNwz0%Mf^>QgsYAPOe9(41Zo#BTDoZTZ61B32a--}gL9CDYA$Ta@}
DBbx!9
delta 2896
zcmbVOZEPE79e?g@*GZK4^5(RO8+NPgC0S#~FR`6Vo3_rIoy5+2oF)jev+uEe>Ag62
z=eG*UUD_}Kt+Xm*{xG3dnzT)VOeq15egLhXU>{%#QW4S+RE$jn0WBLs2sDZ3;y6TW
z0upz6?w$kf-hHc;w?%!kX61pz^
z`AuW}+>XonJKfIt=0cmkQ%7N?JGbx_ox|L@`3uLFv6f9&&nc{9bG+yKSl4%*KfX}(
zyPfE=258s#;=&^1@rf>P0>-%MIoDFbIzKPRf*yHrC`#qyYvJKh|FRfe;O1wkM9}Y^
z498svPSM)5~K6Zl}A~?)2JS9@6FP_fY*_x5Mf4QhthNcvjeZT-tj&7+6;J*mnlR
zpO95J@plvtIKNZ-@*fDZ8Fl+>(Bp!krY;E@>IQ*nWV80}8NBW$itcgkX8YE-mH0KV
z$tj;q!7FrT^{S5(ByYl-PSd@~zN9zDGqGgf&NsFSpVYQgeFRMJn;x3pGrg-e-o<`a
zb$hy6{pc<13r1Z_wN*84V-GR)H}|lMMh&pu#~%4~4RwE2jZd(Lbai
zw{;JS&Gsrp)(*^INX)W~-9_;<2b;T(lD3>JOIr_g6L3%a`J=R(yN;69cb27~%+ZSs
zS~{u#1}qjcumprW3zfqDOXF^QPSbxDwINZ6XJnZbg;yWx+SIm7_#b;FK|KJ(pNU=K
z9pc->t3;7lB^FHItnvPTH_FQg)y2~`BQoa)V3pnQ;VPLv^6AakseDy84mwH1+81_dl7
zMKY0*P%IJ&vox34b6DQa(YjhH%<0+EX!bl@MhNY8&D6_Hy0R1zV1ua%j5G92c
z3WwJ$0`X(PA^^G%k3|vqQv}+c;tj}3il@8DA(3OW)rb`Dpxx4Lt{ASo_rdk!Ocb@D
z@HkWhLkR48$^p%=X8u206REcUHy&^#SS&k;e}GwRJqK381sgjcR6Xk@om
zky@V;qXOM-I}jhXRvC$XvS;(i)q(x;7-!o#1_127X7eBvBzOxOXt$foE?O(TRNmcW
z**wa_ivtd=M6Ksa+i&aCVv}8~9w_jNs+Ovz?jwZevt{8yMCB-&o@JtmBPwabbDB1)q=yRWHQZADH-q0`GuUd^cj)?e@Y3(saZ9c7Bt>BxHieFH
zaPLoEvR=nqFl*`Db$s_kQY&4OO5DIntcHPkd5vS0K)Upm4ZNfD!Uo=o*-BS8@KMZP
zda!|aHsirwvZn{zu#~W`;vIf!C^IVm5?-ro$HeH#CaC}G>WQ&?N6ZCe*DM%by<5odU4{3;V1buyRHH#aCnip8k)opKCTmZWscr`gmK{&{L!R&@t2d=(w=caBbIATt8zrM6S;TSiiqFK`B|6
zSMj=;c+8dJ2VI7N>{
z0v(idCFxDmT%I27TRNOZMBwjt_Bnj+K9Ae~gC{y{?=Ym(@t}6@M2(IwJ$nxSq5AVD
z`ZsZv_vpWcSAXY1^$Fl<|5Z?Z#;5-aURi4Ol>SbopZ4G*N8^bYbI;m7CJw?R;O-740AY|
U$H&BGy1wBRy+Jj+VE7mDZvrDyIRF3v
diff --git a/tracex_project/extraction/fixtures/prompts_fixture.json b/tracex_project/extraction/fixtures/prompts_fixture.json
index b062e2c7..09fa7093 100644
--- a/tracex_project/extraction/fixtures/prompts_fixture.json
+++ b/tracex_project/extraction/fixtures/prompts_fixture.json
@@ -558,10 +558,10 @@
}
],
[
- "gender",
+ "sex",
{
"role": "system",
- "content": "You are an expert in text understanding and your job is to take a given text about an illness and to extract the gender of the author. If the gender isn't clear, you should take the context into account. Only if the context doesn't help, you should return 'N/A'."
+ "content": "You are an expert in text understanding and your job is to take a given text about an illness and to extract the sex of the author. If the sex isn't clear, you should take the context into account. Only if the context doesn't help, you should return 'N/A'."
},
{
"role": "user",
@@ -608,7 +608,7 @@
"age",
{
"role": "system",
- "content": "You are an expert in text understanding and your job is to take a given text about an illness and to extract the age of the author. If the gender isn't clear, you should take the context into account. Young means 25, middle aged 50 and old 75. Only if the context doesn't help, you should return 'N/A'."
+ "content": "You are an expert in text understanding and your job is to take a given text about an illness and to extract the age of the author. If the sex isn't clear, you should take the context into account. Young means 25, middle aged 50 and old 75. Only if the context doesn't help, you should return 'N/A'."
},
{
"role": "user",
diff --git a/tracex_project/extraction/logic/orchestrator.py b/tracex_project/extraction/logic/orchestrator.py
index 5faa46a5..1cb1ab2f 100644
--- a/tracex_project/extraction/logic/orchestrator.py
+++ b/tracex_project/extraction/logic/orchestrator.py
@@ -243,7 +243,7 @@ def set_default_values(self):
if "cohort_tagging" not in config_modules:
cohort_default_values = {
"age": None,
- "gender": None,
+ "sex": None,
"origin": None,
"condition": None,
"preexisting_condition": None,
diff --git a/tracex_project/extraction/tests/test_orchestrator.py b/tracex_project/extraction/tests/test_orchestrator.py
index de25555e..569e2f20 100644
--- a/tracex_project/extraction/tests/test_orchestrator.py
+++ b/tracex_project/extraction/tests/test_orchestrator.py
@@ -162,7 +162,7 @@ def __init__(self, request):
self.orchestrator.update_progress(view, current_step, module_name)
- self.assertEqual(request.session["progress"], 40) # 2/5 = 0.4 * 100 = 40
+ self.assertEqual(request.session["progress"], 33)
self.assertEqual(request.session["status"], module_name)
def test_update_progress_without_view(self):
diff --git a/tracex_project/tracex/fixtures/dataframe_fixtures.json b/tracex_project/tracex/fixtures/dataframe_fixtures.json
index 00d25f92..00dcb6a1 100644
--- a/tracex_project/tracex/fixtures/dataframe_fixtures.json
+++ b/tracex_project/tracex/fixtures/dataframe_fixtures.json
@@ -127,12 +127,69 @@
"patient_journey": "I am very sick. I need help. I have Covid-19. I am in the hospital. I am in the ICU. I am on a ventilator. Please send help quickly."
}
},
+{
+ "model": "extraction.trace",
+ "pk": 6,
+ "fields": {
+ "patient_journey": 98,
+ "last_modified": "2024-04-05T13:22:12.197"
+ }
+},
+{
+ "model": "extraction.trace",
+ "pk": 7,
+ "fields": {
+ "patient_journey": 99,
+ "last_modified": "2024-04-05T14:11:38.748"
+ }
+},
+{
+ "model": "extraction.trace",
+ "pk": 8,
+ "fields": {
+ "patient_journey": 100,
+ "last_modified": "2024-04-05T14:19:44.225"
+ }
+},
+{
+ "model": "extraction.trace",
+ "pk": 33,
+ "fields": {
+ "patient_journey": 114,
+ "last_modified": "2024-04-16T13:11:24.692"
+ }
+},
+{
+ "model": "extraction.trace",
+ "pk": 34,
+ "fields": {
+ "patient_journey": 115,
+ "last_modified": "2024-04-25T13:43:20.276"
+ }
+},
+{
+ "model": "extraction.trace",
+ "pk": 35,
+ "fields": {
+ "patient_journey": 116,
+ "last_modified": "2024-04-25T13:46:36.629"
+ }
+},
+{
+ "model": "extraction.trace",
+ "pk": 36,
+ "fields": {
+ "patient_journey": 118,
+ "last_modified": "2024-04-25T13:54:01.875"
+ }
+},
{
"model": "extraction.cohort",
"pk": 38,
"fields": {
+ "trace": null,
"age": null,
- "gender": null,
+ "sex": null,
"origin": null,
"condition": "Concussion",
"preexisting_condition": null
@@ -142,8 +199,9 @@
"model": "extraction.cohort",
"pk": 39,
"fields": {
+ "trace": null,
"age": 27,
- "gender": "male",
+ "sex": null,
"origin": null,
"condition": "Anxiety",
"preexisting_condition": "Anxiety"
@@ -153,8 +211,9 @@
"model": "extraction.cohort",
"pk": 40,
"fields": {
+ "trace": null,
"age": null,
- "gender": null,
+ "sex": null,
"origin": null,
"condition": "Covid-19",
"preexisting_condition": null
@@ -164,8 +223,9 @@
"model": "extraction.cohort",
"pk": 41,
"fields": {
+ "trace": null,
"age": null,
- "gender": "male",
+ "sex": null,
"origin": null,
"condition": "Covid-19",
"preexisting_condition": null
@@ -175,8 +235,9 @@
"model": "extraction.cohort",
"pk": 42,
"fields": {
+ "trace": null,
"age": null,
- "gender": "male",
+ "sex": null,
"origin": null,
"condition": "Covid-19",
"preexisting_condition": null
@@ -186,8 +247,9 @@
"model": "extraction.cohort",
"pk": 43,
"fields": {
+ "trace": null,
"age": null,
- "gender": "female",
+ "sex": null,
"origin": null,
"condition": "Covid-19",
"preexisting_condition": null
@@ -197,8 +259,9 @@
"model": "extraction.cohort",
"pk": 44,
"fields": {
+ "trace": null,
"age": null,
- "gender": "male",
+ "sex": null,
"origin": null,
"condition": "Covid-19",
"preexisting_condition": null
@@ -208,8 +271,9 @@
"model": "extraction.cohort",
"pk": 45,
"fields": {
+ "trace": null,
"age": null,
- "gender": "male",
+ "sex": null,
"origin": null,
"condition": "Covid-19",
"preexisting_condition": null
@@ -219,76 +283,14 @@
"model": "extraction.cohort",
"pk": 46,
"fields": {
+ "trace": null,
"age": null,
- "gender": null,
+ "sex": null,
"origin": null,
"condition": "I appreciate your understanding. If you have any further details or specific dates related to the Covid-19 diagnosis, please provide them so we can accurately determine the illness.",
"preexisting_condition": null
}
},
-{
- "model": "extraction.trace",
- "pk": 6,
- "fields": {
- "patient_journey": 98,
- "cohort": null,
- "last_modified": "2024-04-05T13:22:12.197"
- }
-},
-{
- "model": "extraction.trace",
- "pk": 7,
- "fields": {
- "patient_journey": 99,
- "cohort": null,
- "last_modified": "2024-04-05T14:11:38.748"
- }
-},
-{
- "model": "extraction.trace",
- "pk": 8,
- "fields": {
- "patient_journey": 100,
- "cohort": null,
- "last_modified": "2024-04-05T14:19:44.225"
- }
-},
-{
- "model": "extraction.trace",
- "pk": 33,
- "fields": {
- "patient_journey": 114,
- "cohort": null,
- "last_modified": "2024-04-16T13:11:24.692"
- }
-},
-{
- "model": "extraction.trace",
- "pk": 34,
- "fields": {
- "patient_journey": 115,
- "cohort": null,
- "last_modified": "2024-04-25T13:43:20.276"
- }
-},
-{
- "model": "extraction.trace",
- "pk": 35,
- "fields": {
- "patient_journey": 116,
- "cohort": null,
- "last_modified": "2024-04-25T13:46:36.629"
- }
-},
-{
- "model": "extraction.trace",
- "pk": 36,
- "fields": {
- "patient_journey": 118,
- "cohort": null,
- "last_modified": "2024-04-25T13:54:01.875"
- }
-},
{
"model": "extraction.event",
"pk": 175,
@@ -2164,10 +2166,10 @@
}
],
[
- "gender",
+ "sex",
{
"role": "system",
- "content": "You are an expert in text understanding and your job is to take a given text about an illness and to extract the gender of the author. If the gender isn't clear, you should take the context into account. Only if the context doesn't help, you should return 'N/A'."
+ "content": "You are an expert in text understanding and your job is to take a given text about an illness and to extract the sex of the author. If the sex isn't clear, you should take the context into account. Only if the context doesn't help, you should return 'N/A'."
},
{
"role": "user",
@@ -2214,7 +2216,7 @@
"age",
{
"role": "system",
- "content": "You are an expert in text understanding and your job is to take a given text about an illness and to extract the age of the author. If the gender isn't clear, you should take the context into account. Young means 25, middle aged 50 and old 75. Only if the context doesn't help, you should return 'N/A'."
+ "content": "You are an expert in text understanding and your job is to take a given text about an illness and to extract the age of the author. If the sex isn't clear, you should take the context into account. Young means 25, middle aged 50 and old 75. Only if the context doesn't help, you should return 'N/A'."
},
{
"role": "user",
@@ -2939,5 +2941,599 @@
"correctness_confidence": "0.97",
"last_modified": "2024-04-25T13:54:01.869"
}
+},
+{
+ "model": "extraction.metric",
+ "pk": 75,
+ "fields": {
+ "event": 175,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:18:59.940"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 76,
+ "fields": {
+ "event": 176,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:19:34.892"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 77,
+ "fields": {
+ "event": 177,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:19:45.732"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 78,
+ "fields": {
+ "event": 178,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:19:53.952"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 79,
+ "fields": {
+ "event": 179,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:20:03.339"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 80,
+ "fields": {
+ "event": 180,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:20:24.660"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 81,
+ "fields": {
+ "event": 181,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:20:34.232"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 82,
+ "fields": {
+ "event": 182,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:20:41.546"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 83,
+ "fields": {
+ "event": 183,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:20:48.133"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 84,
+ "fields": {
+ "event": 184,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:20:54.712"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 85,
+ "fields": {
+ "event": 185,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:21:02.596"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 86,
+ "fields": {
+ "event": 186,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:21:10.550"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 87,
+ "fields": {
+ "event": 187,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:21:18.297"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 88,
+ "fields": {
+ "event": 188,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:22:15.031"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 89,
+ "fields": {
+ "event": 189,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:22:19.924"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 90,
+ "fields": {
+ "event": 190,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:22:30.676"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 91,
+ "fields": {
+ "event": 191,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:22:39.831"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 92,
+ "fields": {
+ "event": 192,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:22:51.281"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 93,
+ "fields": {
+ "event": 193,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:23:04.694"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 94,
+ "fields": {
+ "event": 194,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:23:14.196"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 95,
+ "fields": {
+ "event": 195,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:23:21.310"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 96,
+ "fields": {
+ "event": 196,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:23:28.465"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 97,
+ "fields": {
+ "event": 197,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:23:37.692"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 98,
+ "fields": {
+ "event": 198,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:23:47.789"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 99,
+ "fields": {
+ "event": 199,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:23:56.157"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 100,
+ "fields": {
+ "event": 200,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:24:05.528"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 101,
+ "fields": {
+ "event": 201,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:24:14.094"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 102,
+ "fields": {
+ "event": 202,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:24:23.377"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 103,
+ "fields": {
+ "event": 203,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:24:30.738"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 104,
+ "fields": {
+ "event": 204,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:24:43.382"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 105,
+ "fields": {
+ "event": 205,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:25:03.164"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 106,
+ "fields": {
+ "event": 206,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:25:13.567"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 107,
+ "fields": {
+ "event": 207,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:25:23.211"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 108,
+ "fields": {
+ "event": 208,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:25:29.763"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 109,
+ "fields": {
+ "event": 209,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:25:38.621"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 110,
+ "fields": {
+ "event": 210,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:25:45.744"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 111,
+ "fields": {
+ "event": 211,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:25:55.219"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 112,
+ "fields": {
+ "event": 212,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:26:04.606"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 113,
+ "fields": {
+ "event": 213,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:26:44.474"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 114,
+ "fields": {
+ "event": 214,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:26:51.506"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 115,
+ "fields": {
+ "event": 215,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:26:58.361"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 116,
+ "fields": {
+ "event": 216,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:27:16.551"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 117,
+ "fields": {
+ "event": 217,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:27:22.754"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 118,
+ "fields": {
+ "event": 218,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:27:31.086"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 119,
+ "fields": {
+ "event": 704,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:27:40.120"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 120,
+ "fields": {
+ "event": 705,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:27:50.433"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 121,
+ "fields": {
+ "event": 706,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:27:59.563"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 122,
+ "fields": {
+ "event": 707,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:28:15.697"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 123,
+ "fields": {
+ "event": 708,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:29:00.786"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 124,
+ "fields": {
+ "event": 709,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:29:10.127"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 125,
+ "fields": {
+ "event": 710,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:29:18.267"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 126,
+ "fields": {
+ "event": 711,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:29:30.601"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 127,
+ "fields": {
+ "event": 712,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:29:45.238"
+ }
+},
+{
+ "model": "extraction.metric",
+ "pk": 128,
+ "fields": {
+ "event": 713,
+ "activity_relevance": "High Relevance",
+ "timestamp_correctness": true,
+ "correctness_confidence": "1.00",
+ "last_modified": "2024-05-13T10:29:53.790"
+ }
}
]
From fa94ad35d5c49549f68caa0937d509a1eaab0721 Mon Sep 17 00:00:00 2001
From: Pit Buttchereit <116184086+PitButtchereit@users.noreply.github.com>
Date: Wed, 22 May 2024 10:16:59 +0200
Subject: [PATCH 15/18] =?UTF-8?q?=F0=9F=90=9B=20fix=20bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
tracex_project/extraction/tests/test_views.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tracex_project/extraction/tests/test_views.py b/tracex_project/extraction/tests/test_views.py
index 75a443a9..74ffae7a 100644
--- a/tracex_project/extraction/tests/test_views.py
+++ b/tracex_project/extraction/tests/test_views.py
@@ -328,6 +328,9 @@ def test_get_ajax(self):
class ResultViewTests(TestCase):
"""Test cases for the ResultView."""
+
+ fixtures = ["tracex_project/tracex/fixtures/dataframe_fixtures.json"]
+
def setUp(self): # pylint: disable=invalid-name
"""Set up method that gets called everytime before tests are executed."""
self.client = Client()
From a9ed06306fc3275cb3eb09766e96a5985b303abf Mon Sep 17 00:00:00 2001
From: Pit Buttchereit <116184086+PitButtchereit@users.noreply.github.com>
Date: Thu, 23 May 2024 18:13:05 +0200
Subject: [PATCH 16/18] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor=20test=5Fut?=
=?UTF-8?q?ils?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
tracex_project/tracex/tests/test_utils.py | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/tracex_project/tracex/tests/test_utils.py b/tracex_project/tracex/tests/test_utils.py
index f73f161c..b5d0bc47 100644
--- a/tracex_project/tracex/tests/test_utils.py
+++ b/tracex_project/tracex/tests/test_utils.py
@@ -11,7 +11,7 @@ class ConversionTests(TestCase):
"""Test cases for the conversion class inside the utils module."""
def test_prepare_df_for_xes_conversion(self):
- """Tests if the dataframe contains the correct column name for xes conversion"""
+ """Test if the DataFrame contains the correct column name for XES conversion"""
data = {
"case:concept:name": [1, 1],
"activity": ["fell ill", "went to the doctor"],
@@ -28,7 +28,7 @@ def test_prepare_df_for_xes_conversion(self):
self.assertIsInstance(df_renamed["time:timestamp"][0], str)
def test_rename_columns(self):
- """Tests if the columns are correctly renamed before displaying them."""
+ """Test if the columns are correctly renamed before displaying them."""
data = {
"case:concept:name": [1, 1],
"activity": ["fell ill", "went to the doctor"],
@@ -53,7 +53,7 @@ def test_rename_columns(self):
self.assertIn("Location", df_renamed.columns)
def test_create_html_table_from_df(self):
- """Tests if the html table is correctly created from the dataframe."""
+ """Test if the HTML table is correctly created from the DataFrame."""
data = {
"case:concept:name": [1, 1],
"activity": ["fell ill", "went to the doctor"],
@@ -65,7 +65,7 @@ def test_create_html_table_from_df(self):
self.assertIn("
Date: Thu, 23 May 2024 18:19:54 +0200
Subject: [PATCH 17/18] =?UTF-8?q?=F0=9F=92=8Eupdate=20docstrings=20in=20te?=
=?UTF-8?q?st=5Fmodules.py?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
tracex_project/extraction/tests/test_modules.py | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/tracex_project/extraction/tests/test_modules.py b/tracex_project/extraction/tests/test_modules.py
index d6aa188e..f6c7c3d6 100644
--- a/tracex_project/extraction/tests/test_modules.py
+++ b/tracex_project/extraction/tests/test_modules.py
@@ -16,7 +16,7 @@ class ActivityLabelerTests(TestCase):
fixtures = ["tracex_project/extraction/fixtures/prompts_fixture.json"]
def test_execute_return_value(self):
- """Tests if the return value of the execute method always is a dataframe and if column name is as expected."""
+ """Test if the return value of the execute method is a DataFrame and if the column name is as expected."""
test_data = ["I fell ill yesterday.", "I went to the doctor today."]
activity_labeler = ActivityLabeler()
result = activity_labeler.execute(patient_journey_sentences=test_data)
@@ -32,7 +32,7 @@ class TimeExtractorTests(TestCase):
fixtures = ["tracex_project/extraction/fixtures/prompts_fixture.json"]
def test_execute_return_value(self):
- """Tests if the return value of the execute method is always a dataframe and if column names are as expected."""
+ """Test if the return value of the execute method is a DataFrame and if the column names are as expected."""
data = {"activity": ["fell ill"], "sentence_id": ["1"]}
patient_journey = ["I fell ill on June 5 and recovered on June 7."]
input_dataframe = pd.DataFrame(data)
@@ -47,7 +47,7 @@ def test_execute_return_value(self):
self.assertIn("time:duration", result.columns)
def test_return_value_is_datetime(self):
- """Tests if returned dataframe columns are of type datetime."""
+ """Test if the returned DataFrame columns are of type datetime."""
data = {"activity": ["fell ill"], "sentence_id": ["1"]}
patient_journey = ["I fell ill on June 5 and recovered on June 7."]
input_dataframe = pd.DataFrame(data)
@@ -60,7 +60,7 @@ def test_return_value_is_datetime(self):
self.assertTrue((result["time:end_timestamp"].apply(lambda x: isinstance(x, pd.Timestamp))).all())
def test_processing_downwards(self):
- """Tests if the post-processing function is correctly applied to the dataframe downwards."""
+ """Test if the post-processing function is correctly applied to the DataFrame downwards."""
data = {"activity": ["fell ill", "had fever"], "sentence_id": ["1", "2"]}
patient_journey = ["I fell ill on June 5 and recovered on June 7. After that I had fever."]
input_dataframe = pd.DataFrame(data)
@@ -73,7 +73,7 @@ def test_processing_downwards(self):
self.assertTrue((result["time:end_timestamp"].apply(lambda x: isinstance(x, pd.Timestamp))).all())
def test_post_processing_upwards(self):
- """Tests if the post-processing function is correctly applied to the dataframe upwards."""
+ """Test if the post-processing function is correctly applied to the DataFrame upwards."""
data = {"activity": ["had fever", "fell ill",], "sentence_id": ["1", "2"]}
patient_journey = ["I had fever. After that I fell ill on June 5 and recovered on June 7."]
input_dataframe = pd.DataFrame(data)
@@ -92,7 +92,7 @@ class EventTypeClassifierTests(TestCase):
fixtures = ["tracex_project/extraction/fixtures/prompts_fixture.json"]
def test_execute_return_value(self):
- """Tests if the return value of the execute method is always a dataframe and if column name is as expected."""
+ """Test if the return value of the execute method is a DataFrame and if the column name is as expected."""
test_data = {
"activity": "fell ill",
"time:timestamp": "20220601T0000",
@@ -113,7 +113,7 @@ class LocationExtractorTests(TestCase):
fixtures = ["tracex_project/extraction/fixtures/prompts_fixture.json"]
def test_execute_return_value(self):
- """Tests if the return value of the execute method is always a dataframe and if column name is as expected."""
+ """Test if the return value of the execute method is a DataFrame and if the column name is as expected."""
test_data = {
"activity": "fell ill",
"time:timestamp": "20220601T0000",
From 0f74a91d23fcfb57b19f5d8a60ece42c237eba38 Mon Sep 17 00:00:00 2001
From: Pit Buttchereit <116184086+PitButtchereit@users.noreply.github.com>
Date: Thu, 23 May 2024 18:40:49 +0200
Subject: [PATCH 18/18] =?UTF-8?q?=F0=9F=92=8Eimplement=20suggestions?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../extraction/tests/test_orchestrator.py | 56 ++++++++---------
tracex_project/extraction/tests/test_views.py | 61 +++++++++----------
2 files changed, 57 insertions(+), 60 deletions(-)
diff --git a/tracex_project/extraction/tests/test_orchestrator.py b/tracex_project/extraction/tests/test_orchestrator.py
index 569e2f20..2b44081c 100644
--- a/tracex_project/extraction/tests/test_orchestrator.py
+++ b/tracex_project/extraction/tests/test_orchestrator.py
@@ -32,14 +32,14 @@ def tearDown(self): # pylint: disable=invalid-name
Orchestrator.reset_instance()
def test_single_instance_creation(self):
- """Tests if two initialized orchestrators are the same instance."""
+ """Test if two initialized orchestrators are the same instance."""
orchestrator1 = Orchestrator()
orchestrator2 = Orchestrator()
self.assertIs(orchestrator1, orchestrator2)
def test_consistent_object_state(self):
- """Tests if the state of the orchestrator instance is the same for two instances."""
+ """Test if the state of the orchestrator instance is the same for two instances."""
orchestrator1 = Orchestrator()
orchestrator2 = Orchestrator()
orchestrator1.data = "test_data"
@@ -47,7 +47,7 @@ def test_consistent_object_state(self):
self.assertEqual(orchestrator1.data, orchestrator2.data)
def test_get_instance_method(self):
- """Tests if the get_instance method returns the same instance and if a new instance is the same instance."""
+ """Test if the get_instance method returns the same instance and if a new instance is the same instance."""
Orchestrator()
orchestrator1 = Orchestrator.get_instance()
orchestrator2 = Orchestrator.get_instance()
@@ -57,7 +57,7 @@ def test_get_instance_method(self):
self.assertIs(orchestrator1, orchestrator3)
def test_reset_instance(self):
- """Tests if reset_instance resets the instance for all objects."""
+ """Test if reset_instance resets the instance for all objects."""
orchestrator1 = Orchestrator()
Orchestrator.reset_instance()
orchestrator2 = Orchestrator()
@@ -65,29 +65,29 @@ def test_reset_instance(self):
self.assertIsNot(orchestrator1, orchestrator2)
def test_set_configuration(self):
- """Tests if the set_configuration method correctly updates the Orchestrators instance's configuration."""
- config = ExtractionConfiguration()
- orchestrator = Orchestrator(config)
- new_config = ExtractionConfiguration()
- orchestrator.set_configuration(new_config)
+ """Test if the set_configuration method correctly updates the Orchestrators instance's configuration."""
+ configuration = ExtractionConfiguration()
+ orchestrator = Orchestrator(configuration)
+ new_configuration = ExtractionConfiguration()
+ orchestrator.set_configuration(new_configuration)
- self.assertIs(orchestrator.configuration, new_config)
+ self.assertIs(orchestrator.configuration, new_configuration)
def test_singleton_with_configuration(self):
- """Tests that the Orchestrator's configuration remains unchanged with subsequent instantiations."""
+ """Test that the Orchestrator's configuration remains unchanged with subsequent instantiations."""
Orchestrator.reset_instance()
- config1 = ExtractionConfiguration()
- orchestrator1 = Orchestrator(config1)
- config2 = ExtractionConfiguration()
- orchestrator2 = Orchestrator(config2)
+ configuration_1 = ExtractionConfiguration()
+ orchestrator1 = Orchestrator(configuration_1)
+ configuration_2 = ExtractionConfiguration()
+ orchestrator2 = Orchestrator(configuration_2)
self.assertIs(orchestrator1.configuration, orchestrator2.configuration)
def test_initialize_modules(self):
- """Tests if initialize_modules correctly initializes a module."""
+ """Test if initialize_modules correctly initializes a module."""
Orchestrator.reset_instance()
- config = ExtractionConfiguration()
- orchestrator = Orchestrator(configuration=config)
+ configuration = ExtractionConfiguration()
+ orchestrator = Orchestrator(configuration=configuration)
orchestrator.configuration.update(
modules={
"activity_labeling": ActivityLabeler,
@@ -99,20 +99,20 @@ def test_initialize_modules(self):
self.assertEqual(modules['activity_labeling'].name, "Activity Labeler")
def test_run(self):
- """Tests if the run method correctly return a dataframe. Execution of ActivityLabeler and Preprocessor is
+ """Test if the run method correctly returns a dataframe. Execution of ActivityLabeler and Preprocessor is
necessary since the run method makes assumptions on how the patient journey looks like."""
Orchestrator.reset_instance()
- config = ExtractionConfiguration(
- patient_journey="This is a test patient journey. This is some description about how I fell and and "
+ configuration = ExtractionConfiguration(
+ patient_journey="This is a test patient journey. This is some description about how I fell ill and "
"recovered in the end.",
)
- config.update(
+ configuration.update(
modules={
"preprocessing": Preprocessor,
"activity_labeling": ActivityLabeler,
}
)
- orchestrator = Orchestrator(configuration=config)
+ orchestrator = Orchestrator(configuration=configuration)
orchestrator.run()
self.assertIsNot(orchestrator.get_data(), None)
@@ -145,16 +145,16 @@ def test_get_db_objects_id_key_error(self):
self.orchestrator.get_db_objects_id(object_name)
def test_update_progress_with_view(self):
- """Tests if the progress of the views are updated correctly."""
+ """Test if the progress of the views are updated correctly."""
request = self.factory.get("/extraction/filter")
- middleware = SessionMiddleware(lambda req: req)
+ middleware = SessionMiddleware(lambda _request: _request)
middleware.process_request(request)
request.session.save()
class MockView:
"""Mock View class for testing purposes."""
- def __init__(self, request):
- self.request = request
+ def __init__(self, _request):
+ self.request = _request
view = MockView(request)
current_step = 2
@@ -166,7 +166,7 @@ def __init__(self, request):
self.assertEqual(request.session["status"], module_name)
def test_update_progress_without_view(self):
- """Tests if the progress of the views are updated correctly."""
+ """Test if the progress of the views are updated correctly."""
current_step = 2
module_name = "Activity Labeler"
diff --git a/tracex_project/extraction/tests/test_views.py b/tracex_project/extraction/tests/test_views.py
index 74ffae7a..be3eafc0 100644
--- a/tracex_project/extraction/tests/test_views.py
+++ b/tracex_project/extraction/tests/test_views.py
@@ -32,7 +32,7 @@ def setUp(self): # pylint: disable=invalid-name
self.url = reverse('choose_input_method')
def test_view_get_request(self):
- """Tests that the view URL exists and is accessible by passing a GET request."""
+ """Test that the view URL exists and is accessible by passing a GET request."""
response = self.client.get(self.url)
resolver = resolve(self.url)
@@ -41,15 +41,16 @@ def test_view_get_request(self):
def test_view_post_request(self):
"""
- Test that a POST request to the view returns a method not allowed error since the JourneyInputSelectView
- is a simple TemplateView that does not handle POST request.
+ Test that a POST request to the view returns a method not allowed error.
+
+ The JourneyInputSelectView is a simple TemplateView that does not handle POST request.
"""
response = self.client.post(self.url)
self.assertEqual(response.status_code, 405)
def test_view_uses_correct_template(self):
- """Tests that the view uses the correct template."""
+ """Test that the view uses the correct template."""
response = self.client.get(self.url)
self.assertTemplateUsed(response, 'choose_input_method.html')
@@ -65,12 +66,12 @@ class JourneyUploadViewTests(TestCase):
"""Test cases for the JourneyUploadView."""
def setUp(self): # pylint: disable=invalid-name
- """Set up method that gets called everytime before tests are executed."""
+ """Set up test client and URL."""
self.client = Client()
self.url = reverse('journey_upload')
def test_view_get_request(self):
- """Tests that the view URL exists and is accessible by passing a GET request."""
+ """Test that the view URL exists and is accessible by passing a GET request."""
response = self.client.get(self.url)
resolver = resolve(self.url)
@@ -78,13 +79,13 @@ def test_view_get_request(self):
self.assertEqual(resolver.func.view_class, JourneyUploadView)
def test_view_uses_correct_template(self):
- """Tests that the view uses the correct template."""
+ """Test that the view uses the correct template."""
response = self.client.get(self.url)
self.assertTemplateUsed(response, 'upload_journey.html')
def test_view_uses_correct_form(self):
- """Tests that the view uses the correct form."""
+ """Test that the view uses the correct form."""
response = self.client.get(self.url)
self.assertIsInstance(response.context['form'], JourneyUploadForm)
@@ -113,7 +114,7 @@ def test_view_post_valid_form(self):
self.assertRedirects(response, reverse('journey_details', kwargs={'pk': mock_journey.id}))
def test_view_post_invalid_form(self):
- """Tests that posting an invalid form (without a file) returns the same page with a form error."""
+ """Test that posting an invalid form (without a file) returns the same page with a form error."""
form_data = {}
response = self.client.post(self.url, data=form_data)
@@ -131,7 +132,7 @@ class JourneySelectViewTests(TestCase):
"""Test cases for the JourneySelectView."""
def setUp(self): # pylint: disable=invalid-name
- """Set up method that gets called everytime before tests are executed."""
+ """Set up test client and URL."""
self.client = Client()
self.url = reverse('journey_select')
@@ -144,13 +145,13 @@ def test_view_get_request(self):
self.assertEqual(resolver.func.view_class, JourneySelectView)
def test_view_uses_correct_template(self):
- """Tests that the view uses the correct template."""
+ """Test that the view uses the correct template."""
response = self.client.get(self.url)
self.assertTemplateUsed(response, 'select_journey.html')
def test_view_uses_correct_form(self):
- """Tests that the view uses the correct form."""
+ """Test that the view uses the correct form."""
response = self.client.get(self.url)
self.assertIsInstance(response.context['form'], JourneySelectForm)
@@ -175,7 +176,7 @@ def test_view_post_valid_form(self):
self.assertRedirects(response, reverse('journey_details', kwargs={'pk': mock_journey.id}))
def test_view_post_invalid_form(self):
- """Tests that posting an invalid form (without selecting a file) returns the same page with a form error."""
+ """Test that posting an invalid form (without selecting a file) returns the same page with a form error."""
form_data = {}
response = self.client.post(self.url, data=form_data)
@@ -193,14 +194,14 @@ class JourneyDetailViewTests(TestCase):
"""Test cases for the JourneyDetailView."""
def setUp(self): # pylint: disable=invalid-name
- """Set up method that gets called everytime before tests are executed."""
+ """Set up test client, a mock patient journey and the URL."""
self.client = Client()
self.mock_journey = PatientJourney.manager.create(name='Test Journey',
patient_journey='This is a test patient journey.')
self.url = reverse('journey_details', kwargs={'pk': self.mock_journey.pk})
def test_view_get_request(self):
- """Tests that the view URL exists and is accessible by passing a GET request."""
+ """Test that the view URL exists and is accessible by passing a GET request."""
response = self.client.get(self.url)
resolver = resolve(self.url)
@@ -208,7 +209,7 @@ def test_view_get_request(self):
self.assertEqual(resolver.func.view_class, JourneyDetailView)
def test_uses_correct_template(self):
- """Tests that the view uses the correct template."""
+ """Test that the view uses the correct template."""
response = self.client.get(self.url)
self.assertTemplateUsed(response, 'journey_details.html')
@@ -228,7 +229,7 @@ def test_view_without_patient_journey(self):
self.assertEqual(response.status_code, 404)
def test_post_method_redirect(self):
- """Test that a POST request to the view redirects to the same page."""
+ """Test that a POST request to the view redirects to the JourneyFilterView."""
# Perform a GET request to set up session data
response = self.client.get(self.url)
@@ -247,13 +248,8 @@ class JourneyFilterViewTests(TestCase):
fixtures = ["tracex_project/extraction/fixtures/prompts_fixture.json"]
- @staticmethod
- def dummy_get_response():
- """This is a dummy function to satisfy the get_response parameter of the SessionMiddleware."""
- return None
-
def setUp(self): # pylint: disable=invalid-name
- """Set up method that gets called everytime before tests are executed."""
+ """Set up test client, a mock patient journey, the URL and a factory that sends requests to the view."""
self.client = Client()
self.mock_journey = PatientJourney.manager.create(name='Test Journey',
patient_journey='This is a test patient journey.')
@@ -261,7 +257,7 @@ def setUp(self): # pylint: disable=invalid-name
self.factory = RequestFactory()
def test_view_get_request(self):
- """Tests that the view URL exists and is accessible by passing a GET request."""
+ """Test that the view URL exists and is accessible by passing a GET request."""
response = self.client.get(self.url)
resolver = resolve(self.url)
@@ -269,13 +265,13 @@ def test_view_get_request(self):
self.assertEqual(resolver.func.view_class, JourneyFilterView)
def test_uses_correct_template(self):
- """Tests that the view uses the correct template."""
+ """Test that the view uses the correct template."""
response = self.client.get(self.url)
self.assertTemplateUsed(response, 'filter_journey.html')
def test_view_uses_correct_form(self):
- """Tests that the view uses the correct form."""
+ """Test that the view uses the correct form."""
response = self.client.get(self.url)
self.assertIsInstance(response.context['form'], FilterForm)
@@ -314,6 +310,7 @@ def test_form_valid(self):
def test_get_ajax(self):
"""
Test the `get` method when an AJAX request is made.
+
Ensure that the correct JSON response is returned with the progress and status information.
"""
request = self.factory.get(self.url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
@@ -332,7 +329,7 @@ class ResultViewTests(TestCase):
fixtures = ["tracex_project/tracex/fixtures/dataframe_fixtures.json"]
def setUp(self): # pylint: disable=invalid-name
- """Set up method that gets called everytime before tests are executed."""
+ """Set up test client, a mock patient journey, session data and the URL."""
self.client = Client()
self.mock_journey = PatientJourney.manager.create(name='Test Journey',
patient_journey='This is a test patient journey.')
@@ -342,7 +339,7 @@ def setUp(self): # pylint: disable=invalid-name
self.url = reverse('result')
def test_view_get_request(self):
- """Tests that the view URL exists and is accessible by passing a GET request."""
+ """Test that the view URL exists and is accessible by passing a GET request."""
response = self.client.get(self.url)
resolver = resolve(self.url)
@@ -350,19 +347,19 @@ def test_view_get_request(self):
self.assertEqual(resolver.func.view_class, ResultView)
def test_uses_correct_template(self):
- """Tests that the view uses the correct template."""
+ """Test that the view uses the correct template."""
response = self.client.get(self.url)
self.assertTemplateUsed(response, 'result.html')
def test_uses_correct_form(self):
- """Tests that the view uses the correct form."""
+ """Test that the view uses the correct form."""
response = self.client.get(self.url)
self.assertIsInstance(response.context['form'], ResultForm)
def test_get_form_kwargs(self):
- """Tests that correct form kwargs are passed to the form."""
+ """Test that correct form kwargs are passed to the form."""
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
@@ -373,7 +370,7 @@ def test_get_form_kwargs(self):
self.assertEqual((form.initial['selected_modules']), self.session['selected_modules'])
def test_get_context_data(self):
- """Tests that the view fetches the correct context data."""
+ """Test that the view fetches the correct context data."""
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)