3131from country_workspace .datasources .utils import datetime_to_date , date_to_iso_string
3232from country_workspace .models import Household
3333from country_workspace .workspaces .exceptions import BeneficiaryValidationError
34- from country_workspace .validators .beneficiaries import validate_beneficiaries
3534
3635
3736HOUSEHOLD_1_PK = 1
4544def config (request ) -> Config :
4645 return {
4746 "batch_name" : "batch_name" ,
47+ "validate_mode" : "none" ,
4848 "master_detail" : request .param ,
4949 "household_pk_col" : "household_pk" ,
5050 "master_column_label" : "master_column" ,
5151 "detail_column_label" : "detail_column" ,
5252 "people_column_prefix" : "pp_" ,
53- "check_before" : False ,
54- "fail_if_alien" : False ,
5553 }
5654
5755
@@ -110,6 +108,11 @@ def household_mapping() -> Mapping[int, Mock]:
110108 }
111109
112110
111+ @pytest .fixture
112+ def people_mapping (people_sheet : Sheet ) -> Mapping [int , Mock ]:
113+ return {i : Mock () for i in range (len (list (people_sheet )))}
114+
115+
113116def test_column_configuration_error_format () -> None :
114117 error = ColumnConfigurationError (column_name := "test_column" )
115118 assert column_name in str (error )
@@ -277,60 +280,34 @@ def test_process_beneficiaries_failed_to_create(
277280 assert exc_info .value .sheet_name == expected_sheet_name
278281
279282
280- def test_validate_beneficiaries (config : Config , household_mapping : Mapping [int , Mock ]) -> None :
281- config ["check_before" ] = True
282-
283- validate_beneficiaries (config , household_mapping )
284-
285- for household in household_mapping .values ():
286- household .validate_with_checker .assert_called_once ()
287-
288-
289- def test_validate_beneficiaries_raises_exception_on_failed_validation (
290- config : Config , household_mapping : Mapping [int , Mock ]
291- ) -> None :
292- config ["check_before" ] = True
293- household_mapping [HOUSEHOLD_1_PK ].validate_with_checker .return_value = False
294-
295- with pytest .raises (BeneficiaryValidationError ):
296- validate_beneficiaries (config , household_mapping )
297-
298-
299- def test_validate_beneficiaries_check_before_is_false (config : Config , household_mapping : Mapping [int , Mock ]) -> None :
300- config ["check_before" ] = False
301-
302- validate_beneficiaries (config , household_mapping )
303-
304- for household in household_mapping .values ():
305- household .validate_with_checker .assert_not_called ()
306-
307-
308283def test_import_from_rdi (
309284 mocker : MockerFixture ,
310285 config : Config ,
311286 household_sheet : Sheet ,
312287 individual_sheet : Sheet ,
313288 people_sheet : Sheet ,
314289 household_mapping : Mapping [int , Mock ],
290+ people_mapping : Mapping [int , Mock ],
315291) -> None :
316292 job = Mock ()
317293 job .config = config
318294 batch_class_mock = mocker .patch ("country_workspace.datasources.rdi.Batch" )
319295 read_sheets_mock = mocker .patch ("country_workspace.datasources.rdi.read_sheets" )
320296 process_beneficiaries_mock = mocker .patch ("country_workspace.datasources.rdi.process_beneficiaries" )
321297 validate_beneficiaries_mock = mocker .patch ("country_workspace.datasources.rdi.validate_beneficiaries" )
298+ partial_mock = mocker .patch ("country_workspace.datasources.rdi.partial" )
322299 if config ["master_detail" ]:
323300 read_sheets_mock .return_value = household_sheet , individual_sheet
324301 process_households_mock = mocker .patch ("country_workspace.datasources.rdi.process_households" )
325302 process_households_mock .return_value = household_mapping
326303 process_beneficiaries_mock .return_value = (processed_individuals := list (individual_sheet ))
327304 else :
328305 read_sheets_mock .return_value = (people_sheet ,)
329- people_mapping = {i : Mock () for i in range (len (list (people_sheet )))}
330306 process_beneficiaries_mock .return_value = people_mapping
331307
332308 result = import_from_rdi (job )
333309
310+ partial_mock .assert_called_once_with (validate_beneficiaries_mock , config = config , office = job .program .country_office )
334311 if config ["master_detail" ]:
335312 assert result == {"household" : len (household_mapping ), "individual" : len (processed_individuals )}
336313 process_households_mock .assert_called_once_with (
@@ -343,7 +320,7 @@ def test_import_from_rdi(
343320 config ,
344321 household_mapping ,
345322 )
346- validate_beneficiaries_mock . assert_called_once_with (config , household_mapping )
323+ partial_mock . return_value . assert_called_once_with (household_mapping )
347324 else :
348325 assert result == {"people" : len (people_mapping )}
349326 process_beneficiaries_mock .assert_called_once_with (
@@ -352,7 +329,7 @@ def test_import_from_rdi(
352329 batch_class_mock .objects .create .return_value ,
353330 config ,
354331 )
355- validate_beneficiaries_mock . assert_called_once_with (config , people_mapping )
332+ partial_mock . return_value . assert_called_once_with (people_mapping )
356333
357334 batch_class_mock .objects .create .assert_called_once_with (
358335 name = config ["batch_name" ],
0 commit comments