Skip to content

Commit

Permalink
Merge pull request #4414 from unicef/generic-import-admin-area-fix
Browse files Browse the repository at this point in the history
generic-import-admin-area-fix
  • Loading branch information
domdinicola authored Nov 7, 2024
2 parents f064427 + 7f268f4 commit 3572d75
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 152 deletions.
4 changes: 3 additions & 1 deletion src/hct_mis_api/apps/household/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,9 @@ class CollectType(models.TextChoices):
org_name_enumerator = models.CharField(max_length=250, blank=True, default=BLANK)
village = models.CharField(max_length=250, blank=True, default=BLANK)
registration_method = models.CharField(max_length=250, choices=REGISTRATION_METHOD_CHOICES, default=BLANK)
collect_individual_data = models.CharField(max_length=250, choices=COLLECT_TYPES, default=COLLECT_TYPE_UNKNOWN)
collect_individual_data = models.CharField(
max_length=250, choices=COLLECT_TYPES, default=COLLECT_TYPE_UNKNOWN
) # TODO remove
currency = models.CharField(max_length=250, choices=CURRENCY_CHOICES, default=BLANK)
unhcr_id = models.CharField(max_length=250, blank=True, default=BLANK, db_index=True)
user_fields = JSONField(default=dict, blank=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from dateutil.relativedelta import relativedelta

from hct_mis_api.apps.household.models import (
COLLECT_TYPE_FULL,
COLLECT_TYPE_PARTIAL,
DISABLED,
FEMALE,
Expand Down Expand Up @@ -40,10 +39,7 @@ def recalculate_data(
) -> Tuple[Household, List[str]]:
household = Household.objects.select_for_update().get(id=household.id)

if (
household.collect_individual_data not in (COLLECT_TYPE_FULL, COLLECT_TYPE_PARTIAL)
and not household.program.data_collecting_type.recalculate_composition
):
if not household.program.data_collecting_type.recalculate_composition:
return household, []

individuals_to_update = []
Expand Down
85 changes: 0 additions & 85 deletions tests/unit/apps/household/test_collecting_individual_data.py

This file was deleted.

14 changes: 13 additions & 1 deletion tests/unit/apps/household/test_recalculate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from hct_mis_api.apps.household.services.household_recalculate_data import (
recalculate_data,
)
from hct_mis_api.apps.program.fixtures import ProgramFactory
from hct_mis_api.apps.registration_data.fixtures import RegistrationDataImportFactory


Expand All @@ -32,12 +33,16 @@ class TestRecalculateData(TestCase):
def setUpTestData(cls) -> None:
super().setUpTestData()
create_afghanistan()

cls.program = ProgramFactory()
data_collecting_type = cls.program.data_collecting_type
data_collecting_type.recalculate_composition = True
data_collecting_type.save()
business_area = BusinessArea.objects.first()
registration_data_import = RegistrationDataImportFactory(business_area=business_area)

cls.household_data = {
"business_area": business_area,
"program": cls.program,
"registration_data_import": registration_data_import,
"female_age_group_0_5_count": 2,
"female_age_group_6_11_count": 1,
Expand Down Expand Up @@ -76,6 +81,7 @@ def setUpTestData(cls) -> None:
"pregnant": True,
"first_registration_date": timezone.make_aware(datetime.datetime.strptime("2020-10-29", "%Y-%m-%d")),
"physical_disability": "LOT_DIFFICULTY",
"program": cls.program,
},
{
"registration_data_import": registration_data_import,
Expand All @@ -86,6 +92,7 @@ def setUpTestData(cls) -> None:
"pregnant": True,
"first_registration_date": timezone.make_aware(datetime.datetime.strptime("2021-07-03", "%Y-%m-%d")),
"selfcare_disability": "CANNOT_DO",
"program": cls.program,
},
{
"registration_data_import": registration_data_import,
Expand All @@ -96,6 +103,7 @@ def setUpTestData(cls) -> None:
"pregnant": False,
"first_registration_date": timezone.make_aware(datetime.datetime.strptime("2021-01-11", "%Y-%m-%d")),
"memory_disability": "LOT_DIFFICULTY",
"program": cls.program,
},
{
"registration_data_import": registration_data_import,
Expand All @@ -111,6 +119,7 @@ def setUpTestData(cls) -> None:
"memory_disability": "LOT_DIFFICULTY",
"selfcare_disability": "LOT_DIFFICULTY",
"comms_disability": "LOT_DIFFICULTY",
"program": cls.program,
},
{
"registration_data_import": registration_data_import,
Expand All @@ -121,6 +130,7 @@ def setUpTestData(cls) -> None:
"pregnant": False,
"first_registration_date": timezone.make_aware(datetime.datetime.strptime("2021-01-11", "%Y-%m-%d")),
"hearing_disability": "CANNOT_DO",
"program": cls.program,
},
{
"registration_data_import": registration_data_import,
Expand All @@ -131,6 +141,7 @@ def setUpTestData(cls) -> None:
"pregnant": False,
"first_registration_date": timezone.make_aware(datetime.datetime.strptime("2021-01-11", "%Y-%m-%d")),
"hearing_disability": "CANNOT_DO",
"program": cls.program,
},
{
"registration_data_import": registration_data_import,
Expand All @@ -142,6 +153,7 @@ def setUpTestData(cls) -> None:
"first_registration_date": timezone.make_aware(datetime.datetime.strptime("2020-10-29", "%Y-%m-%d")),
"memory_disability": "LOT_DIFFICULTY",
"comms_disability": "LOT_DIFFICULTY",
"program": cls.program,
},
]

Expand Down
61 changes: 1 addition & 60 deletions tests/unit/apps/registration_datahub/test_rdi_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from hct_mis_api.apps.household.models import (
BROTHER_SISTER,
COLLECT_TYPE_FULL,
COLLECT_TYPE_PARTIAL,
COUSIN,
HEAD,
NON_BENEFICIARY,
Expand Down Expand Up @@ -240,6 +239,7 @@ def test_merge_rdi_and_recalculation(self) -> None:
kobo_submission_uuid="c09130af-6c9c-4dba-8c7f-1b2ff1970d19",
kobo_submission_time="2022-02-22T12:22:22",
flex_fields={"enumerator_id": 1234567890},
program=self.rdi.program,
)
dct = self.rdi.program.data_collecting_type
dct.recalculate_composition = True
Expand Down Expand Up @@ -508,65 +508,6 @@ def test_merge_rdi_create_collections(self, household_representation_exists: boo
self.assertIsNotNone(household.household_collection)
self.assertEqual(household.household_collection.households.count(), 2)

@freeze_time("2022-01-01")
def test_merge_rdi_and_recalculation_for_collect_data_partial(self) -> None:
household = PendingHouseholdFactory(
collect_individual_data=COLLECT_TYPE_PARTIAL,
registration_data_import=self.rdi,
)
dct = self.rdi.program.data_collecting_type
dct.recalculate_composition = True
dct.save()

self.set_imported_individuals(household)

household.head_of_household = PendingIndividual.objects.first()
household.save()

with capture_on_commit_callbacks(execute=True):
RdiMergeTask().execute(self.rdi.pk)

households = Household.objects.all()
individuals = Individual.objects.all()

self.assertEqual(1, households.count())
self.assertEqual(households[0].collect_individual_data, COLLECT_TYPE_PARTIAL)
self.assertEqual(8, individuals.count())

household_data = model_to_dict(
households[0],
(
"female_age_group_0_5_count",
"female_age_group_6_11_count",
"female_age_group_12_17_count",
"female_age_group_18_59_count",
"female_age_group_60_count",
"male_age_group_0_5_count",
"male_age_group_6_11_count",
"male_age_group_12_17_count",
"male_age_group_18_59_count",
"male_age_group_60_count",
"children_count",
"size",
),
)

expected = {
"female_age_group_0_5_count": None,
"female_age_group_6_11_count": None,
"female_age_group_12_17_count": None,
"female_age_group_18_59_count": None,
"female_age_group_60_count": None,
"male_age_group_0_5_count": None,
"male_age_group_6_11_count": None,
"male_age_group_12_17_count": None,
"male_age_group_18_59_count": None,
"male_age_group_60_count": None,
"children_count": None,
"size": None,
}
self.assertEqual(household_data, expected)

def test_merging_external_collector(self) -> None:
household = PendingHouseholdFactory(
collect_individual_data=COLLECT_TYPE_FULL,
Expand Down

0 comments on commit 3572d75

Please sign in to comment.