2222 extract_images ,
2323 merge_images ,
2424 read_sheets ,
25+ full_name_column ,
2526 # validate_households,
2627)
2728from country_workspace .models import Household
3334HOUSEHOLD_2_PK = 2
3435HOUSEHOLD_1_NAME = "Household 1"
3536HOUSEHOLD_2_NAME = "Household 2"
37+ FULL_NAME_COLUMN = "full_name"
3638
3739
3840@pytest .fixture
@@ -50,21 +52,21 @@ def config() -> Config:
5052@pytest .fixture
5153def household_sheet (config : Config ) -> Sheet :
5254 return [
53- {config ["master_column_label " ]: HOUSEHOLD_1_NAME , config ["household_pk_col" ]: HOUSEHOLD_1_PK },
54- {config ["master_column_label " ]: HOUSEHOLD_1_NAME , config ["household_pk_col" ]: HOUSEHOLD_2_PK },
55+ {config ["detail_column_label " ]: HOUSEHOLD_1_NAME , config ["household_pk_col" ]: HOUSEHOLD_1_PK },
56+ {config ["detail_column_label " ]: HOUSEHOLD_1_NAME , config ["household_pk_col" ]: HOUSEHOLD_2_PK },
5557 ]
5658
5759
5860@pytest .fixture
5961def individual_sheet (config : Config ) -> Sheet :
6062 return [
6163 {
62- config [ "detail_column_label" ] : "John Doe" ,
63- config ["household_pk_col " ]: HOUSEHOLD_1_PK ,
64+ FULL_NAME_COLUMN : "John Doe" ,
65+ config ["master_column_label " ]: HOUSEHOLD_1_PK ,
6466 },
6567 {
66- config [ "detail_column_label" ] : "Doe John" ,
67- config ["household_pk_col " ]: HOUSEHOLD_2_PK ,
68+ FULL_NAME_COLUMN : "Doe John" ,
69+ config ["master_column_label " ]: HOUSEHOLD_2_PK ,
6870 },
6971 ]
7072
@@ -135,7 +137,7 @@ def test_process_households(mocker: MockerFixture, config: Config, household_she
135137 }
136138 job .program .households .create .assert_has_calls (
137139 [
138- call (batch = batch , name = row [config ["master_column_label " ]], flex_fields = clean_field_names_mock .return_value )
140+ call (batch = batch , name = row [config ["detail_column_label " ]], flex_fields = clean_field_names_mock .return_value )
139141 for row in household_sheet
140142 ]
141143 )
@@ -166,8 +168,8 @@ def test_process_individuals(
166168 [
167169 call (
168170 batch = batch_mock ,
169- name = row [config [ "detail_column_label" ] ],
170- household_id = household_mapping [row [config ["household_pk_col " ]]].pk ,
171+ name = row [FULL_NAME_COLUMN ],
172+ household_id = household_mapping [row [config ["master_column_label " ]]].pk ,
171173 flex_fields = clean_field_names_mock .return_value ,
172174 )
173175 for row in individual_sheet
@@ -305,3 +307,15 @@ def test_read_sheets(mocker: MockerFixture) -> None:
305307 extract_images_mock .assert_called_once_with (filepath , sheet_index )
306308 merge_images_mock .assert_called_once_with (sheet , images )
307309 filter_rows_with_household_pk_mock .assert_called_once_with (config_mock , merge_images_mock .return_value )
310+
311+
312+ @pytest .mark .parametrize (
313+ ("record" , "expected" ),
314+ [
315+ ({"full_name" : "John Smith" }, "full_name" ),
316+ ({}, None ),
317+ ({"name_full" : "John Smith" }, None ),
318+ ],
319+ )
320+ def test_full_name_column (record : Record , expected : str | None ) -> None :
321+ assert full_name_column (record ) == expected
0 commit comments