From 4cf70f015099bfe1124fb72e691d89d066b4bc43 Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Mon, 2 Dec 2024 20:54:07 +0100 Subject: [PATCH] Write basic unit tests for Stakeholder model --- backend/ebios_rm/tests/fixtures.py | 13 +++++++++- backend/ebios_rm/tests/test_stakeholder.py | 28 ++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 backend/ebios_rm/tests/test_stakeholder.py diff --git a/backend/ebios_rm/tests/fixtures.py b/backend/ebios_rm/tests/fixtures.py index b166b27b1..5098f0667 100644 --- a/backend/ebios_rm/tests/fixtures.py +++ b/backend/ebios_rm/tests/fixtures.py @@ -1,7 +1,7 @@ import pytest from core.models import RiskMatrix, StoredLibrary, Asset -from ebios_rm.models import EbiosRMStudy, FearedEvent +from ebios_rm.models import ROTO, EbiosRMStudy, FearedEvent @pytest.fixture @@ -47,3 +47,14 @@ def basic_feared_event_fixture(basic_ebios_rm_study_fixture): ) asset = Asset.objects.get(name="Primary Asset 1") feared_event.assets.add(asset) + + +@pytest.fixture +def basic_roto_fixture(basic_ebios_rm_study_fixture, basic_feared_event_fixture): + roto = ROTO.objects.create( + risk_origin=ROTO.RiskOrigin.STATE, + target_objective="test target objectives", + ebios_rm_study=basic_ebios_rm_study_fixture, + ) + roto.feared_events.set(FearedEvent.objects.filter(name="test feared event")) + return roto diff --git a/backend/ebios_rm/tests/test_stakeholder.py b/backend/ebios_rm/tests/test_stakeholder.py new file mode 100644 index 000000000..e77c30415 --- /dev/null +++ b/backend/ebios_rm/tests/test_stakeholder.py @@ -0,0 +1,28 @@ +import pytest +from ebios_rm.models import EbiosRMStudy, FearedEvent, ROTO, Stakeholder + +from tprm.models import Entity + +from ebios_rm.tests.fixtures import * + + +@pytest.mark.django_db +class TestStakeholder: + @pytest.mark.usefixtures( + "basic_ebios_rm_study_fixture", + ) + def test_create_stakeholder_basic(self): + study = EbiosRMStudy.objects.get(name="test study") + entity = Entity.objects.create(name="Entity") + stakeholder = Stakeholder.objects.create( + entity=entity, + category=Stakeholder.Category.SUPPLIER, + ) + stakeholder.ebios_rm_studies.add(study) + + assert stakeholder in study.stakeholders.all() + assert stakeholder.entity == entity + assert stakeholder.category == Stakeholder.Category.SUPPLIER + + assert stakeholder.current_criticality == 0 + assert stakeholder.residual_criticality == 0