From 9d0cf664419dcaa4655cd3171759453d18945136 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 26 Feb 2024 22:30:36 +0000 Subject: [PATCH] major update to test --- atlas/tests.py | 3 - atlas/tests/conftest.py | 189 ++++++++++++++++++ atlas/tests/test_atlas_models.py | 10 +- generic/tests/__init__.py | 0 generic/tests/conftest.py | 31 +++ .../test_exam_collection.py} | 0 longs/tests/conftest.py | 2 + longs/tests/test_longs_exams.py | 6 +- 8 files changed, 234 insertions(+), 7 deletions(-) delete mode 100755 atlas/tests.py create mode 100644 atlas/tests/conftest.py create mode 100644 generic/tests/__init__.py create mode 100644 generic/tests/conftest.py rename generic/{tests.py => tests/test_exam_collection.py} (100%) diff --git a/atlas/tests.py b/atlas/tests.py deleted file mode 100755 index 7ce503c2..00000000 --- a/atlas/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/atlas/tests/conftest.py b/atlas/tests/conftest.py new file mode 100644 index 00000000..751993b5 --- /dev/null +++ b/atlas/tests/conftest.py @@ -0,0 +1,189 @@ +from django.conf import settings +from django.utils import timezone +import pytest +from django.test import Client +from django.contrib.auth import get_user_model + +from generic.tests.conftest import create_modality, create_examination, create_plane, create_contrast, create_user + +from atlas.models import ( + Case, + Finding, + Condition, + ConditionRelationship, + Presentation, + Subspecialty, + PathologicalProcess, + Differential, + Structure, + Series, + SeriesImage, + SeriesFinding, + CaseCollection, + SeriesDetail, + CaseDetail, + BaseReportAnswer, + CidReportAnswer, + UserReportAnswer, + SelfReview, + UncategorisedDicom, + DuplicateDicom, +) + + +@pytest.fixture +def create_finding(): + return Finding.objects.create(name="Test Finding") + + +@pytest.fixture +def create_condition(): + return Condition.objects.create(name="Test Condition") + + +@pytest.fixture +def create_condition_relationship(create_condition): + return ConditionRelationship.objects.create( + child=create_condition, parent=create_condition + ) + + +@pytest.fixture +def create_presentation(): + return Presentation.objects.create(name="Test Presentation") + + +@pytest.fixture +def create_subspecialty(): + return Subspecialty.objects.create(name="Test Subspecialty") + + +@pytest.fixture +def create_pathological_process(): + return PathologicalProcess.objects.create(name="Test Pathological Process") + + +@pytest.fixture +def create_differential(create_condition, create_case): + return Differential.objects.create(condition=create_condition, case=create_case) + + +@pytest.fixture +def create_structure(): + return Structure.objects.create(name="Test Structure") + + +@pytest.fixture +def create_case( + create_subspecialty, + create_condition, + create_presentation, + create_pathological_process, +): + subspecialty = create_subspecialty + condition = create_condition + presentation = create_presentation + pathological_process = create_pathological_process + user = get_user_model().objects.create( + username="Test User", password="Test Password", email="testuser@example.com" + ) + + case = Case.objects.create( + title="Sample Case", + description="Sample description", + history="Sample history", + discussion="Sample discussion", + report="Sample report", + diagnostic_certainty=Case.CertaintyChoices.LIKELY, + verified=True, + created_date=timezone.now(), + published_date=timezone.now(), + archive=False, + open_access=True, + ) + + case.subspecialty.add(subspecialty) + case.condition.add(condition) + case.presentation.add(presentation) + case.pathological_process.add(pathological_process) + case.author.add(user) + case.editor.add(user) + + return case + + +@pytest.fixture +def create_series(create_modality, create_examination, create_plane, create_contrast, create_user): + author=create_user + series_instance_uid="1234567890" + modality = create_modality + examination = create_examination + plane = create_plane + contrast = create_contrast + + series = Series.objects.create( + modality=modality, + examination=examination, + plane=plane, + contrast=contrast, + series_instance_uid=series_instance_uid + ) + + series.author.add(author) + + return series + + +@pytest.fixture +def create_series_image(): + return SeriesImage.objects.create() + + +@pytest.fixture +def create_series_finding(): + return SeriesFinding.objects.create() + + +@pytest.fixture +def create_case_collection(): + return CaseCollection.objects.create() + + +@pytest.fixture +def create_series_detail(): + return SeriesDetail.objects.create() + + +@pytest.fixture +def create_case_detail(): + return CaseDetail.objects.create() + + +@pytest.fixture +def create_base_report_answer(): + return BaseReportAnswer.objects.create() + + +@pytest.fixture +def create_cid_report_answer(): + return CidReportAnswer.objects.create() + + +@pytest.fixture +def create_user_report_answer(): + return UserReportAnswer.objects.create() + + +@pytest.fixture +def create_self_review(): + return SelfReview.objects.create() + + +@pytest.fixture +def create_uncategorised_dicom(): + return UncategorisedDicom.objects.create() + + +@pytest.fixture +def create_duplicate_dicom(): + return DuplicateDicom() diff --git a/atlas/tests/test_atlas_models.py b/atlas/tests/test_atlas_models.py index 0b39434c..049a0386 100644 --- a/atlas/tests/test_atlas_models.py +++ b/atlas/tests/test_atlas_models.py @@ -72,4 +72,12 @@ def test_condition_tree_structure(db): # client.login(username="basicuser", password="password") # response = client.get(reverse('rapids:active_exams')) # print(response.content) -# assert response.status_code == 200 \ No newline at end of file +# assert response.status_code == 200 + +def test_create_case(db, create_case): + case = create_case + assert case.title == "Sample Case" + +def test_create_series(db, create_series): + series = create_series + assert series \ No newline at end of file diff --git a/generic/tests/__init__.py b/generic/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/generic/tests/conftest.py b/generic/tests/conftest.py new file mode 100644 index 00000000..cd6c7bf6 --- /dev/null +++ b/generic/tests/conftest.py @@ -0,0 +1,31 @@ +from django.conf import settings +from django.utils import timezone +import pytest +from django.test import Client + +from generic.models import Modality, Plane, Contrast, Examination, Site +from django.contrib.auth import get_user_model + +@pytest.fixture +def create_user(db): + return get_user_model().objects.create_user( + username="testuser", + password="testpassword", + email="test@test.com" + ) + +@pytest.fixture +def create_modality(): + return Modality.objects.create(modality="Test Modality") + +@pytest.fixture +def create_plane(): + return Plane.objects.create(plane="Test Plane") + +@pytest.fixture +def create_contrast(): + return Contrast.objects.create(contrast="Test Contrast") + +@pytest.fixture +def create_examination(create_modality): + return Examination.objects.create(examination="Test Examination", modality=create_modality) diff --git a/generic/tests.py b/generic/tests/test_exam_collection.py similarity index 100% rename from generic/tests.py rename to generic/tests/test_exam_collection.py diff --git a/longs/tests/conftest.py b/longs/tests/conftest.py index 0d1ee6a4..e4b128cb 100644 --- a/longs/tests/conftest.py +++ b/longs/tests/conftest.py @@ -4,6 +4,8 @@ from django.urls import reverse from longs.models import Long +from generic.tests.conftest import create_modality, create_examination, create_plane, create_contrast, create_user + @pytest.fixture def create_long(db): return Long.objects.create( diff --git a/longs/tests/test_longs_exams.py b/longs/tests/test_longs_exams.py index 25eaab18..fa9ccd24 100644 --- a/longs/tests/test_longs_exams.py +++ b/longs/tests/test_longs_exams.py @@ -58,7 +58,7 @@ def create_exam(db): return exam -def create_examination(db): +def create_examinations(db): examination = Examination.objects.create(examination="test examination") examination.save() examination = Examination.objects.create(examination="test examination 2") @@ -68,7 +68,7 @@ def create_examination(db): def create_long_series(question, image_number=5): series = LongSeries( description="Test series", - examination=Examination.objects.get(pk=1), + examination=Examination.objects.all().first(), ) series.save() @@ -118,7 +118,7 @@ def test_exams(db, client): # create_structures(db) # create_question_types(db) - create_examination(db) + create_examinations(db) question1 = create_question(exam) generated_questions = [question1, create_question(exam), create_question(exam)]