Skip to content

Commit 5fcb7db

Browse files
authored
Merge pull request #114 from itk-dev-rpa/release/2.13.0
Release/2.13.0
2 parents fadfa5a + 75433a0 commit 5fcb7db

File tree

4 files changed

+126
-39
lines changed

4 files changed

+126
-39
lines changed

changelog.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [2.13.0] - 2025-08-13
11+
12+
### Added
13+
14+
- Nova: Function to set the state of an existing case.
15+
1016
## [2.12.1] - 2025-08-07
1117

1218
### Fixed
@@ -232,7 +238,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
232238

233239
- Initial release
234240

235-
[Unreleased]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/compare/2.12.1...HEAD
241+
[Unreleased]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/compare/2.13.0...HEAD
242+
[2.13.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.13.0
236243
[2.12.1]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.12.1
237244
[2.12.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.12.0
238245
[2.11.1]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.11.1

itk_dev_shared_components/kmd_nova/nova_cases.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import uuid
55
import urllib.parse
6+
from typing import Literal
67

78
import requests
89

@@ -348,3 +349,28 @@ def add_case(case: NovaCase, nova_access: NovaAccess):
348349

349350
response = requests.post(url, params=params, headers=headers, json=payload, timeout=60)
350351
response.raise_for_status()
352+
353+
354+
def set_case_state(case_uuid: str, new_state: Literal["Opstaaet", "Oplyst", "Afgjort", "Bestilt", "Udfoert", "Afsluttet"], nova_access: NovaAccess):
355+
"""Set the state of an existing case.
356+
357+
Args:
358+
case_uuid: The uuid of the case.
359+
new_state: The new state of the case.
360+
nova_access: The NovaAccess object used to authenticate.
361+
"""
362+
url = urllib.parse.urljoin(nova_access.domain, "api/Case/Update")
363+
params = {"api-version": "2.0-Case"}
364+
365+
headers = {'Content-Type': 'application/json', 'Authorization': f"Bearer {nova_access.get_bearer_token()}"}
366+
367+
payload = {
368+
"common": {
369+
"transactionId": str(uuid.uuid4()),
370+
"uuid": case_uuid
371+
},
372+
"state": new_state
373+
}
374+
375+
response = requests.patch(url, params=params, headers=headers, json=payload, timeout=60)
376+
response.raise_for_status()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "itk_dev_shared_components"
7-
version = "2.12.1"
7+
version = "2.13.0"
88
authors = [
99
{ name="ITK Development", email="itk-rpa@mkb.aarhus.dk" },
1010
]

tests/test_nova_api/test_cases.py

Lines changed: 91 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,9 @@ def test_add_case(self):
8686
"""Test adding a case to Nova.
8787
Also tests getting a case on uuid.
8888
"""
89-
nova_party = os.getenv('NOVA_PARTY').split(',')
90-
party = CaseParty(
91-
role="Primær",
92-
identification_type="CprNummer",
93-
identification=nova_party[0],
94-
name=nova_party[1]
95-
)
96-
97-
caseworker_dict = json.loads(os.environ['NOVA_USER'])
98-
caseworker = Caseworker(
99-
**caseworker_dict
100-
)
101-
102-
department_dict = json.loads(os.environ['NOVA_DEPARTMENT'])
103-
department = Department(
104-
**department_dict
105-
)
89+
party = _get_test_party()
90+
caseworker = _get_test_caseworker()
91+
department = _get_test_department()
10692

10793
case = NovaCase(
10894
uuid=str(uuid.uuid4()),
@@ -119,16 +105,7 @@ def test_add_case(self):
119105
)
120106

121107
nova_cases.add_case(case, self.nova_access)
122-
123-
# Wait up to 10 seconds for the case to be created in Nova
124-
nova_case = None
125-
for _ in range(10):
126-
time.sleep(1)
127-
try:
128-
nova_case = nova_cases.get_case(case.uuid, self.nova_access)
129-
break
130-
except ValueError:
131-
pass
108+
nova_case = _get_case(case.uuid, self.nova_access)
132109

133110
self.assertIsNotNone(nova_case)
134111

@@ -164,19 +141,31 @@ def test_user_groups(self):
164141
self.assertEqual(nova_case.caseworker, caseworker)
165142

166143
# Add case
167-
nova_party = os.getenv('NOVA_PARTY').split(',')
168-
party = CaseParty(
169-
role="Primær",
170-
identification_type="CprNummer",
171-
identification=nova_party[0],
172-
name=nova_party[1]
173-
)
144+
party = _get_test_party()
145+
department = _get_test_department()
174146

175-
department_dict = json.loads(os.environ['NOVA_DEPARTMENT'])
176-
department = Department(
177-
**department_dict
147+
case = NovaCase(
148+
uuid=str(uuid.uuid4()),
149+
title=f"Test {datetime.now()}",
150+
case_date=datetime.now(),
151+
progress_state="Opstaaet",
152+
case_parties=[party],
153+
kle_number="23.05.01",
154+
proceeding_facet="G01",
155+
sensitivity="Fortrolige",
156+
caseworker=caseworker,
157+
responsible_department=department,
158+
security_unit=department
178159
)
179160

161+
nova_cases.add_case(case, self.nova_access)
162+
163+
def test_set_case_state(self):
164+
"""Test setting the state of an existing case."""
165+
party = _get_test_party()
166+
caseworker = _get_test_caseworker()
167+
department = _get_test_department()
168+
180169
case = NovaCase(
181170
uuid=str(uuid.uuid4()),
182171
title=f"Test {datetime.now()}",
@@ -193,6 +182,71 @@ def test_user_groups(self):
193182

194183
nova_cases.add_case(case, self.nova_access)
195184

185+
nova_case = _get_case(case.uuid, self.nova_access)
186+
self.assertEqual(nova_case.progress_state, "Opstaaet")
187+
188+
nova_cases.set_case_state(case.uuid, "Afsluttet", self.nova_access)
189+
nova_case = _get_case(case.uuid, self.nova_access)
190+
self.assertEqual(nova_case.progress_state, "Afsluttet")
191+
192+
193+
def _get_case(case_uuid: str, nova_access: NovaAccess) -> NovaCase | None:
194+
"""Get a case by the given uuid. Retry for up to 10 seconds until the case appears.
195+
196+
Args:
197+
case_uuid: The uuid of the case to get.
198+
nova_access: The NovaAccess object used to authenticate.
199+
200+
Returns:
201+
The case with the given uuid if it exists.
202+
"""
203+
for _ in range(10):
204+
time.sleep(1)
205+
try:
206+
return nova_cases.get_case(case_uuid, nova_access)
207+
except ValueError:
208+
pass
209+
return None
210+
211+
212+
def _get_test_party() -> CaseParty:
213+
"""Get the case party used for tests defined in NOVA_PARTY envvar.
214+
215+
Returns:
216+
A CaseParty object based on the NOVA_PARTY envvar.
217+
"""
218+
nova_party = os.getenv('NOVA_PARTY').split(',')
219+
return CaseParty(
220+
role="Primær",
221+
identification_type="CprNummer",
222+
identification=nova_party[0],
223+
name=nova_party[1]
224+
)
225+
226+
227+
def _get_test_caseworker() -> Caseworker:
228+
"""Get the caseworker used for tests defined in the NOVA_USER envvar.
229+
230+
Returns:
231+
A Caseworker object based on the NOVA_USER envvar.
232+
"""
233+
caseworker_dict = json.loads(os.environ['NOVA_USER'])
234+
return Caseworker(
235+
**caseworker_dict
236+
)
237+
238+
239+
def _get_test_department() -> Department:
240+
"""Get the department used for tests defined in the NOVA_DEPARTMENT envvar.
241+
242+
Returns:
243+
A Department object based on the NOVA_DEPARTMENT envvar.
244+
"""
245+
department_dict = json.loads(os.environ['NOVA_DEPARTMENT'])
246+
return Department(
247+
**department_dict
248+
)
249+
196250

197251
if __name__ == '__main__':
198252
unittest.main()

0 commit comments

Comments
 (0)