Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into selenium/grievance…
Browse files Browse the repository at this point in the history
…_tickets_happy_path

# Conflicts:
#	backend/selenium_tests/girevance/grievance_tickets/test_grievance_tickets.py
  • Loading branch information
szymon-kellton committed May 13, 2024
2 parents 9e9de27 + 1949fda commit f1f0c5d
Show file tree
Hide file tree
Showing 343 changed files with 20,873 additions and 705 deletions.
2 changes: 1 addition & 1 deletion backend/.coveragerc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[run]
branch = True
source = hct_mis_api
concurrency=multiprocessing
concurrency=multiprocessing,thread

omit =
*/selenium_tests/**
Expand Down
10 changes: 10 additions & 0 deletions backend/hct_mis_api/api/endpoints/rdi/push_people.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
ImportedIndividual,
RegistrationDataImportDatahub,
)
from hct_mis_api.apps.utils.phone import calculate_phone_numbers_validity

PEOPLE_TYPE_CHOICES = (
(BLANK, "None"),
Expand All @@ -54,6 +55,9 @@ class PushPeopleSerializer(serializers.ModelSerializer):
residence_status = serializers.ChoiceField(choices=RESIDENCE_STATUS_CHOICE)
village = serializers.CharField(allow_blank=True, required=False)

phone_no = serializers.CharField(allow_null=True, allow_blank=True, required=False)
phone_no_alternative = serializers.CharField(allow_null=True, allow_blank=True, required=False)

class Meta:
model = ImportedIndividual
exclude = [
Expand Down Expand Up @@ -118,6 +122,9 @@ def _create_individual(
relationship=relationship,
**individual_data,
)
if ind.phone_no or ind.phone_no_alternative:
ind = self._validate_phone_number(ind)
ind.save(update_fields=("phone_no_valid", "phone_no_alternative_valid"))

if person_type is not NON_BENEFICIARY:
hh.head_of_household = ind
Expand All @@ -128,6 +135,9 @@ def _create_individual(
self._create_document(ind, doc)
return ind

def _validate_phone_number(self, individual: ImportedIndividual) -> ImportedIndividual:
return calculate_phone_numbers_validity(individual)

def _create_document(self, member: ImportedIndividual, doc: Dict) -> None:
ImportedDocument.objects.create(
document_number=doc["document_number"],
Expand Down
38 changes: 38 additions & 0 deletions backend/hct_mis_api/api/tests/test_push_people.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from typing import Any

from parameterized import parameterized
from rest_framework import status
from rest_framework.reverse import reverse

Expand Down Expand Up @@ -241,3 +244,38 @@ def test_upload_with_errors(self) -> None:
{"birth_date": ["This field is required."], "type": ["This field is required."]},
],
)

@parameterized.expand(
[
("invalid_phone_no", "phone_no", "invalid", False),
("invalid_phone_no_alternative", "phone_no", "invalid", False),
("valid_phone_no", "phone_no_alternative", "+48 632 215 789", True),
("valid_phone_no_alternative", "phone_no_alternative", "+48 632 215 789", True),
]
)
def test_upload_single_person_with_phone_number(
self, _: Any, field_name: str, phone_number: str, expected_value: bool
) -> None:
data = [
{
"residence_status": "IDP",
"village": "village1",
"country": "AF",
"collect_individual_data": COLLECT_TYPE_FULL,
"full_name": "John Doe",
"birth_date": "2000-01-01",
"sex": "MALE",
"type": "",
field_name: phone_number,
}
]
response = self.client.post(self.url, data, format="json")
self.assertEqual(response.status_code, status.HTTP_201_CREATED, str(response.json()))
response_json = response.json()

rdi_datahub = RegistrationDataImportDatahub.objects.filter(id=response_json["id"]).first()
self.assertIsNotNone(rdi_datahub)
ind = ImportedIndividual.objects.filter(registration_data_import=rdi_datahub).first()
self.assertIsNotNone(ind)
self.assertEqual(ind.full_name, "John Doe")
self.assertEqual(getattr(ind, f"{field_name}_valid"), expected_value)
213 changes: 141 additions & 72 deletions backend/hct_mis_api/apps/core/attributes_qet_queries.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,7 @@ def __init__(
super().__init__(*args, **kwargs)
self.scopes: Iterable = scopes or set()
if fields:
self.extend(fields)
self.extend(copy.deepcopy(fields))
self.all_fields = copy.deepcopy(CORE_FIELDS_ATTRIBUTES)

def extend(self, __iterable: Iterable[dict]) -> None:
Expand Down Expand Up @@ -1865,11 +1865,22 @@ def _fill_label_template(self, field: dict, language: str = "English(EN)") -> Op
def from_scopes(cls, scopes: list[Scope]) -> "FieldFactory":
factory = cls()
all_fields = copy.deepcopy(factory.all_fields)
factory.scopes.update(scopes)
factory.extend(filter(lambda field: any(True for scope in scopes if scope in field["scope"]), all_fields))
if Scope.XLSX_PEOPLE in scopes:
for field_attr in factory:
field_attr["xlsx_field"] = "pp_" + field_attr["xlsx_field"].replace("_h_c", "_i_c")
return factory

@classmethod
def from_only_scopes(cls, scopes: list[Scope]) -> "FieldFactory":
factory = cls()
all_fields = copy.deepcopy(factory.all_fields)
factory.scopes.update(scopes)
factory.extend(filter(lambda field: all(scope in field["scope"] for scope in scopes), all_fields))
if Scope.XLSX_PEOPLE in scopes:
for field_attr in factory:
field_attr["xlsx_field"] = "pp_" + field_attr["xlsx_field"].replace("_h_c", "_i_c")
return factory

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions backend/hct_mis_api/apps/core/fixtures/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -6681,8 +6681,8 @@
"description": "Partial individuals collected (Social Worker)",
"type": "SOCIAL",
"active": true,
"individual_filters_available": false,
"household_filters_available": true,
"individual_filters_available": true,
"household_filters_available": false,
"compatible_types": [2, 3],
"limit_to": ["c259b1a0-ae3a-494e-b343-f7c8eb060c68", "3e269a73-123b-43e1-86af-ced1b30d8e80"]
}
Expand Down
12 changes: 9 additions & 3 deletions backend/hct_mis_api/apps/core/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
FlexibleAttributeGroup,
)
from hct_mis_api.apps.core.utils import decode_id_string
from hct_mis_api.apps.program.models import Program

if TYPE_CHECKING:
from django.db.models.query import QuerySet
Expand Down Expand Up @@ -268,9 +269,14 @@ def get_fields_attr_generators(
if flex_field is not False:
yield from FlexibleAttribute.objects.order_by("created_at")
if flex_field is not True:
yield from FieldFactory.from_scope(Scope.TARGETING).filtered_by_types(FILTERABLE_TYPES).apply_business_area(
business_area_slug=business_area_slug, program_id=program_id
)
if program_id and Program.objects.get(id=program_id).is_social_worker_program:
yield from FieldFactory.from_only_scopes([Scope.XLSX_PEOPLE, Scope.TARGETING]).filtered_by_types(
FILTERABLE_TYPES
).apply_business_area(business_area_slug=business_area_slug, program_id=program_id)
else:
yield from FieldFactory.from_scope(Scope.TARGETING).filtered_by_types(FILTERABLE_TYPES).apply_business_area(
business_area_slug=business_area_slug, program_id=program_id
)


def resolve_asset(business_area_slug: str, uid: str) -> Dict:
Expand Down
Loading

0 comments on commit f1f0c5d

Please sign in to comment.