Skip to content

Commit

Permalink
Write basic unit tests for Stakeholder model
Browse files Browse the repository at this point in the history
  • Loading branch information
nas-tabchiche committed Dec 2, 2024
1 parent 40b1721 commit 4cf70f0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
13 changes: 12 additions & 1 deletion backend/ebios_rm/tests/fixtures.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
28 changes: 28 additions & 0 deletions backend/ebios_rm/tests/test_stakeholder.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4cf70f0

Please sign in to comment.