@@ -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
197251if __name__ == '__main__' :
198252 unittest .main ()
0 commit comments