diff options
| author | Max Nanis | 2026-03-06 16:49:46 -0500 |
|---|---|---|
| committer | Max Nanis | 2026-03-06 16:49:46 -0500 |
| commit | 91d040211a4ed6e4157896256a762d3854777b5e (patch) | |
| tree | cd95922ea4257dc8d3f4e4cbe8534474709a20dc /tests/models/precision/test_survey.py | |
| download | generalresearch-91d040211a4ed6e4157896256a762d3854777b5e.tar.gz generalresearch-91d040211a4ed6e4157896256a762d3854777b5e.zip | |
Initial commitv3.3.4
Diffstat (limited to 'tests/models/precision/test_survey.py')
| -rw-r--r-- | tests/models/precision/test_survey.py | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/models/precision/test_survey.py b/tests/models/precision/test_survey.py new file mode 100644 index 0000000..ff2d6d1 --- /dev/null +++ b/tests/models/precision/test_survey.py @@ -0,0 +1,88 @@ +class TestPrecisionQuota: + + def test_quota_passes(self): + from generalresearch.models.precision.survey import PrecisionSurvey + from tests.models.precision import survey_json + + s = PrecisionSurvey.model_validate(survey_json) + q = s.quotas[0] + ce = {k: True for k in ["b41e1a3", "bc89ee8", "4124366", "9f32c61"]} + assert q.matches(ce) + + ce["b41e1a3"] = False + assert not q.matches(ce) + + ce.pop("b41e1a3") + assert not q.matches(ce) + assert not q.matches({}) + + def test_quota_passes_closed(self): + from generalresearch.models.precision import PrecisionStatus + from generalresearch.models.precision.survey import PrecisionSurvey + from tests.models.precision import survey_json + + s = PrecisionSurvey.model_validate(survey_json) + q = s.quotas[0] + q.status = PrecisionStatus.CLOSED + ce = {k: True for k in ["b41e1a3", "bc89ee8", "4124366", "9f32c61"]} + # We still match, but the quota is not open + assert q.matches(ce) + assert not q.is_open + + +class TestPrecisionSurvey: + + def test_passes(self): + from generalresearch.models.precision.survey import PrecisionSurvey + from tests.models.precision import survey_json + + s = PrecisionSurvey.model_validate(survey_json) + ce = {k: True for k in ["b41e1a3", "bc89ee8", "4124366", "9f32c61"]} + assert s.determine_eligibility(ce) + + def test_elig_closed_quota(self): + from generalresearch.models.precision import PrecisionStatus + from generalresearch.models.precision.survey import PrecisionSurvey + from tests.models.precision import survey_json + + s = PrecisionSurvey.model_validate(survey_json) + ce = {k: True for k in ["b41e1a3", "bc89ee8", "4124366", "9f32c61"]} + q = s.quotas[0] + q.status = PrecisionStatus.CLOSED + # We match a closed quota + assert not s.determine_eligibility(ce) + + s.quotas[0].status = PrecisionStatus.OPEN + s.quotas[1].status = PrecisionStatus.CLOSED + # Now me match an open quota and dont match the closed quota, so we should be eligible + assert s.determine_eligibility(ce) + + def test_passes_sp(self): + from generalresearch.models.precision import PrecisionStatus + from generalresearch.models.precision.survey import PrecisionSurvey + from tests.models.precision import survey_json + + s = PrecisionSurvey.model_validate(survey_json) + ce = {k: True for k in ["b41e1a3", "bc89ee8", "4124366", "9f32c61"]} + passes, hashes = s.determine_eligibility_soft(ce) + + # We don't know if we match the 2nd quota, but it is open so it doesn't matter + assert passes + assert (True, []) == s.quotas[0].matches_soft(ce) + assert (None, ["0cdc304", "500af2c"]) == s.quotas[1].matches_soft(ce) + + # Now don't know if we match either + ce.pop("9f32c61") # age + passes, hashes = s.determine_eligibility_soft(ce) + assert passes is None + assert {"500af2c", "9f32c61", "0cdc304"} == hashes + + ce["9f32c61"] = False + ce["0cdc304"] = False + # We know we don't match either + assert (False, set()) == s.determine_eligibility_soft(ce) + + # We pass 1st quota, 2nd is unknown but closed, so we don't know for sure we pass + ce = {k: True for k in ["b41e1a3", "bc89ee8", "4124366", "9f32c61"]} + s.quotas[1].status = PrecisionStatus.CLOSED + assert (None, {"0cdc304", "500af2c"}) == s.determine_eligibility_soft(ce) |
