-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/selenium/people_smoke_tests' int…
…o selenium/people_smoke_tests
- Loading branch information
Showing
24 changed files
with
507 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 54 additions & 22 deletions
76
backend/hct_mis_api/apps/targeting/tests/test_targeting_validators.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,86 @@ | ||
from django.core.exceptions import ValidationError | ||
from django.test import TestCase | ||
|
||
from hct_mis_api.apps.core.fixtures import DataCollectingTypeFactory | ||
from hct_mis_api.apps.core.fixtures import DataCollectingTypeFactory, create_afghanistan | ||
from hct_mis_api.apps.core.models import DataCollectingType | ||
from hct_mis_api.apps.household.fixtures import create_household | ||
from hct_mis_api.apps.household.models import Household, Individual | ||
from hct_mis_api.apps.program.fixtures import ProgramFactory | ||
from hct_mis_api.apps.program.models import Program | ||
from hct_mis_api.apps.targeting.validators import TargetingCriteriaInputValidator | ||
|
||
|
||
class TestTargetingCriteriaInputValidator(TestCase): | ||
@classmethod | ||
def setUpTestData(cls) -> None: | ||
cls.dct_standard = DataCollectingTypeFactory( | ||
type=DataCollectingType.Type.STANDARD, | ||
individual_filters_available=True, | ||
household_filters_available=True, | ||
create_afghanistan() | ||
cls.program_standard = ProgramFactory( | ||
data_collecting_type=DataCollectingTypeFactory( | ||
type=DataCollectingType.Type.STANDARD, | ||
individual_filters_available=True, | ||
household_filters_available=True, | ||
) | ||
) | ||
cls.dct_standard_hh_only = DataCollectingTypeFactory( | ||
type=DataCollectingType.Type.STANDARD, | ||
individual_filters_available=False, | ||
household_filters_available=True, | ||
cls.program_standard_hh_only = ProgramFactory( | ||
data_collecting_type=DataCollectingTypeFactory( | ||
type=DataCollectingType.Type.STANDARD, | ||
individual_filters_available=False, | ||
household_filters_available=True, | ||
) | ||
) | ||
cls.dct_standard_ind_only = DataCollectingTypeFactory( | ||
type=DataCollectingType.Type.STANDARD, | ||
individual_filters_available=True, | ||
household_filters_available=False, | ||
cls.program_standard_ind_only = ProgramFactory( | ||
data_collecting_type=DataCollectingTypeFactory( | ||
type=DataCollectingType.Type.STANDARD, | ||
individual_filters_available=True, | ||
household_filters_available=False, | ||
) | ||
) | ||
cls.dct_social = DataCollectingTypeFactory( | ||
type=DataCollectingType.Type.SOCIAL, | ||
individual_filters_available=True, | ||
household_filters_available=False, | ||
cls.program_social = ProgramFactory( | ||
data_collecting_type=DataCollectingTypeFactory( | ||
type=DataCollectingType.Type.SOCIAL, | ||
individual_filters_available=True, | ||
household_filters_available=False, | ||
) | ||
) | ||
|
||
def test_TargetingCriteriaInputValidator(self) -> None: | ||
validator = TargetingCriteriaInputValidator | ||
create_household({"unicef_id": "HH-1", "size": 1}, {"unicef_id": "IND-1"}) | ||
with self.assertRaisesMessage( | ||
ValidationError, "Target criteria can has only filters or ids, not possible to has both" | ||
): | ||
self._update_program(self.program_standard) | ||
validator.validate( | ||
{"rules": ["Rule1"], "household_ids": "HH-1", "individual_ids": "IND-1"}, self.dct_standard | ||
{"rules": ["Rule1"], "household_ids": "HH-1", "individual_ids": "IND-1"}, self.program_standard | ||
) | ||
|
||
with self.assertRaisesMessage(ValidationError, "Target criteria can has only individual ids"): | ||
validator.validate({"rules": [], "household_ids": "HH-1", "individual_ids": "IND-1"}, self.dct_social) | ||
self._update_program(self.program_social) | ||
validator.validate({"rules": [], "household_ids": "HH-1", "individual_ids": "IND-1"}, self.program_social) | ||
|
||
self._update_program(self.program_standard_ind_only) | ||
validator.validate( | ||
{"rules": [], "household_ids": "HH-1", "individual_ids": "IND-1"}, self.dct_standard_ind_only | ||
{"rules": [], "household_ids": "HH-1", "individual_ids": "IND-1"}, self.program_standard_ind_only | ||
) | ||
|
||
with self.assertRaisesMessage(ValidationError, "Target criteria can has only household ids"): | ||
self._update_program(self.program_standard_hh_only) | ||
validator.validate( | ||
{"rules": [], "household_ids": "HH-1", "individual_ids": "IND-1"}, self.dct_standard_hh_only | ||
{"rules": [], "household_ids": "HH-1", "individual_ids": "IND-1"}, self.program_standard_hh_only | ||
) | ||
|
||
with self.assertRaisesMessage(ValidationError, "There should be at least 1 rule in target criteria"): | ||
validator.validate({"rules": [], "household_ids": "", "individual_ids": ""}, self.dct_standard_hh_only) | ||
self._update_program(self.program_standard_hh_only) | ||
validator.validate({"rules": [], "household_ids": "", "individual_ids": ""}, self.program_standard_hh_only) | ||
|
||
with self.assertRaisesMessage(ValidationError, "The given households do not exist in the current program"): | ||
self._update_program(self.program_standard) | ||
validator.validate({"rules": [], "household_ids": "HH-666", "individual_ids": ""}, self.program_standard) | ||
|
||
with self.assertRaisesMessage(ValidationError, "The given individuals do not exist in the current program"): | ||
self._update_program(self.program_standard) | ||
validator.validate({"rules": [], "household_ids": "", "individual_ids": "IND-666"}, self.program_standard) | ||
|
||
def _update_program(self, program: Program) -> None: | ||
Household.objects.all().update(program=program) | ||
Individual.objects.all().update(program=program) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.