Skip to content

Commit

Permalink
incr test cov, small adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
pkujawa committed Aug 23, 2024
1 parent b400888 commit 0cb06ae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
8 changes: 2 additions & 6 deletions backend/hct_mis_api/apps/targeting/graphql_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,12 @@ def resolve_field_attribute(parent, info: Any) -> Optional[Dict]:
field_attribute = get_field_by_name(
parent.field_name, parent.targeting_criteria_rule.targeting_criteria.target_population
)
parent.targeting_criteria_rule
return filter_choices(
field_attribute, parent.arguments # type: ignore # can't convert graphene list to list
)

program = None
if parent.flex_field_classification == FlexFieldClassification.FLEX_FIELD_PDU:
encoded_program_id = info.context.headers.get("Program")
program = Program.objects.get(id=decode_id_string(encoded_program_id))
return FlexibleAttribute.objects.get(name=parent.field_name, program=program)
else: # FlexFieldClassification.FLEX_FIELD_BASIC
return FlexibleAttribute.objects.get(name=parent.field_name)

class Meta:
model = target_models.TargetingCriteriaRuleFilter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@
'some'
],
'comparisonMethod': 'EQUALS',
'fieldAttribute': {
'labelEn': 'PDU Field STRING',
'type': 'PDU'
},
'fieldName': 'pdu_field_string',
'flexFieldClassification': 'FLEX_FIELD_PDU',
'roundNumber': 1
Expand Down
13 changes: 12 additions & 1 deletion backend/hct_mis_api/apps/targeting/tests/test_target_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ class TestTargetPopulationQuery(APITestCase):
arguments
flexFieldClassification
roundNumber
fieldAttribute
{
labelEn
type
}
}
}
}
Expand Down Expand Up @@ -324,7 +329,13 @@ def test_simple_target_query_pdu(self, _: Any, permissions: List[Permissions]) -
self.create_user_role_with_permissions(self.user, permissions, self.business_area, self.program)
self.snapshot_graphql_request(
request_string=TestTargetPopulationQuery.TARGET_POPULATION_QUERY,
context={"user": self.user},
context={
"user": self.user,
"headers": {
"Business-Area": self.business_area.slug,
"Program": self.id_to_base64(self.program.id, "ProgramNode"),
},
},
variables={
"id": self.id_to_base64(
self.target_population_with_pdu_filter.id,
Expand Down

0 comments on commit 0cb06ae

Please sign in to comment.