From ada0fefe242838c4f59dddc1fe247769c1596f59 Mon Sep 17 00:00:00 2001 From: Carlos Gavidia-Calderon Date: Mon, 24 Jun 2024 15:11:11 +0100 Subject: [PATCH] Testing consistent identifiers when creating multiple strategies --- CONTRIBUTING.md | 2 +- eap_backend/tests/test_views.py | 35 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e97684b5..465af208 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -45,7 +45,7 @@ Please remember to enable `pre-commit` and run it before any push or PR. ```bash pre-commit install -pre-commit run a--all-files +pre-commit run --all-files ``` ### Contributing to the Documentation diff --git a/eap_backend/tests/test_views.py b/eap_backend/tests/test_views.py index 172cbd74..6b2ab884 100644 --- a/eap_backend/tests/test_views.py +++ b/eap_backend/tests/test_views.py @@ -11,6 +11,7 @@ EAPUser, Evidence, PropertyClaim, + Strategy, TopLevelNormativeGoal, ) from eap_api.serializers import ( @@ -166,6 +167,40 @@ def test_goal_delete_with_standard_permission(self): assert len(response_get.json()) == 0 +class StrategyViewTest(TestCase): + def setUp(self): + self.assurance_case: AssuranceCase = AssuranceCase.objects.create(**CASE1_INFO) + + self.goal: TopLevelNormativeGoal = TopLevelNormativeGoal.objects.create( + **GOAL_INFO + ) + + def test_identifier_update_follows_order(self): + number_of_strategies: int = 3 + for strategy_number in range(1, number_of_strategies + 1): + post_data = { + "name": "", + "short_description": "Strategy for The Goal", + "long_description": "A longer description of the strategy", + "goal_id": 1, + } + response_post: HttpResponse = self.client.post( + reverse("strategies_list"), + data=json.dumps(post_data), + content_type="application/json", + ) + + assert response_post.status_code == 201 + assert response_post.json()["name"] == f"S{strategy_number}" + + created_strategy: Strategy = Strategy.objects.get( + pk=response_post.json()["id"] + ) + + assert created_strategy.pk == response_post.json()["id"] + assert created_strategy.name == f"S{strategy_number}" + + class ContextViewTest(TestCase): def setUp(self): # Mock Entries to be modified and tested