def test_tip_filter(self): tip1 = {"isPersonalized": True} optin = False showTip = tip_filter(tip1, UserDataTree({}), optin) self.assertEqual(showTip, False) tip1 = {"isPersonalized": False, "active": True} showTip = tip_filter(tip1, UserDataTree({}), False) self.assertEqual(showTip, True) optin = True tip1 = {"isPersonalized": True, "active": False} showTip = tip_filter(tip1, UserDataTree({}), optin) self.assertEqual(showTip, False) optin = True tip1 = {"isPersonalized": True, "active": True} showTip = tip_filter(tip1, UserDataTree({}), optin) self.assertEqual(showTip, True)
def test_heeft_kinderen(self): fixture = self._get_tips_request_data() user_data = UserDataTree(fixture["user_data"]) rules = [{"type": "ref", "ref_id": "4"}] self.assertTrue(apply_rules(user_data, rules, compound_rules)) fixture["user_data"]["BRP"]["kinderen"] = [] user_data = UserDataTree(fixture["user_data"]) self.assertFalse(apply_rules(user_data, rules, compound_rules))
def test_woont_in_gemeente_Amsterdam(self): fixture = self._get_tips_request_data() user_data = UserDataTree(fixture["user_data"]) rules = [{"type": "ref", "ref_id": "3"}] self.assertTrue(apply_rules(user_data, rules, compound_rules)) fixture["user_data"]["BRP"]["persoon"]["mokum"] = True user_data = UserDataTree(fixture["user_data"]) self.assertTrue(apply_rules(user_data, rules, compound_rules)) fixture["user_data"]["BRP"]["persoon"]["mokum"] = False user_data = UserDataTree(fixture["user_data"]) self.assertFalse(apply_rules(user_data, rules, compound_rules))
def test_stadspas(self): # Stadspas rule rules = [{"type": "ref", "ref_id": "1"}] def is_valid(stadspas): user_data = UserDataTree({"FOCUS_AANVRAGEN": [stadspas]}) return apply_rules(user_data, rules, compound_rules) # Use invalid date invalid_date = get_date_years_ago(2) stadspas = { "productTitle": "Stadspas", "steps": [{ "datePublished": invalid_date, "decision": "toekenning" }], } self.assertFalse(is_valid(stadspas)) # Use valid date valid_date = get_date_years_ago(1) stadspas = { "productTitle": "Stadspas", "steps": [{ "datePublished": valid_date, "decision": "toekenning" }], } self.assertTrue(is_valid(stadspas)) # Use invalid decision stadspas = { "productTitle": "Stadspas", "steps": [{ "datePublished": valid_date, "decision": "afwijzing" }], } self.assertFalse(is_valid(stadspas)) # Use invalid productTitle stadspas = { "productTitle": "Bijstandsuitkering", "steps": [{ "datePublished": valid_date, "decision": "toekenning" }], } self.assertFalse(is_valid(stadspas)) # regression test for when there is no stadspas data or malformed stadspas data self.assertFalse(is_valid(None)) self.assertFalse(is_valid({"steps": ["hy"]})) user_data = UserDataTree({"bliep": None}) is_valid_data = apply_rules(user_data, rules, compound_rules) self.assertFalse(is_valid_data)
def tips_generator(request_data=None, tips=None, audience: List[str] = None): """Generate tips.""" if request_data is None: request_data = {} if tips is None: tips = tips_pool # add source tips if request_data["source_tips"]: tips = tips + format_source_tips(request_data["source_tips"]) tips = [normalize_tip_personalization(tip) for tip in tips] if request_data["optin"]: user_data_prepared = UserDataTree(request_data["user_data"]) else: user_data_prepared = UserDataTree({}) for tip in tips: enrich_tip(tip) if audience: tips = [ tip for tip in tips if set(tip.get("audience", [])).intersection(set(audience)) ] tips = [ tip for tip in tips if tip_filter(tip, user_data_prepared, request_data["optin"]) ] tips = [normalize_tip_output(tip) for tip in tips] tips.sort(key=lambda t: t["priority"], reverse=True) return tips
def test_stadspas(self): # Stadspas rule rules = [{"type": "ref", "ref_id": "1"}] def is_valid(stadspas): user_data = UserDataTree({"WPI_STADSPAS": {"aanvragen": [stadspas]}}) return apply_rules(user_data, rules, compound_rules) # Use invalid date invalid_date = get_date_years_ago(2) stadspas = { "about": "Stadspas", "decision": "toekenning", "datePublished": invalid_date, } self.assertFalse(is_valid(stadspas)) # Use valid date valid_date = get_date_years_ago(1) stadspas = { "about": "Stadspas", "datePublished": valid_date, "decision": "toekenning", } self.assertTrue(is_valid(stadspas)) # Use invalid decision stadspas = { "about": "Stadspas", "datePublished": valid_date, "decision": "afwijzing", } self.assertFalse(is_valid(stadspas)) # regression test for when there is no stadspas data or malformed stadspas data self.assertFalse(is_valid(None)) self.assertFalse(is_valid({"steps": ["hy"]})) user_data = UserDataTree({"bliep": None}) is_valid_data = apply_rules(user_data, rules, compound_rules) self.assertFalse(is_valid_data)
def is_valid(stadspas): user_data = UserDataTree({"FOCUS_AANVRAGEN": [stadspas]}) return apply_rules(user_data, rules, compound_rules)
def get_result(): user_data = UserDataTree(fixture["user_data"]) return apply_rules(user_data, rules, compound_rules)
def is_valid(stadspas): user_data = UserDataTree({"WPI_STADSPAS": {"aanvragen": [stadspas]}}) return apply_rules(user_data, rules, compound_rules)