def test_get_achievement_properties(self): achievement = create_achievement(achievement_maxlevel=3) achievementproperty = AchievementProperty() achievementproperty.name = "xp" DBSession.add(achievementproperty) DBSession.flush() achievements_achievementproperty = AchievementAchievementProperty() achievements_achievementproperty.achievement_id = achievement.id achievements_achievementproperty.property_id = achievementproperty.id achievements_achievementproperty.value = "5" achievements_achievementproperty.from_level = 2 DBSession.add(achievements_achievementproperty) DBSession.flush() clear_all_caches() result1 = Achievement.get_achievement_properties(achievement.id, 4) print(result1) result2 = Achievement.get_achievement_properties(achievement.id, 1) print(result2) self.assertNotEqual(result1, []) self.assertEqual(result2, [])
def test_get_reward_and_properties_for_achievement(self): user = create_user() achievement = create_achievement( achievement_name="invite_users_achievement", achievement_relevance="friends", achievement_maxlevel=3) achievementproperty = AchievementProperty() achievementproperty.name = "xp" DBSession.add(achievementproperty) DBSession.flush() achievements_achievementproperty = AchievementAchievementProperty() achievements_achievementproperty.achievement_id = achievement.id achievements_achievementproperty.property_id = achievementproperty.id achievements_achievementproperty.value = "5" achievements_achievementproperty.from_level = None DBSession.add(achievements_achievementproperty) DBSession.flush() create_achievement_rewards(achievement=achievement) achievement_date = Achievement.get_datetime_for_evaluation_type( achievement.evaluation_timezone, achievement.evaluation) create_achievement_user(user=user, achievement=achievement, achievement_date=achievement_date, level=1) create_variable("invite_users", "none") Value.increase_value(variable_name="invite_users", user=user, value=4, key="5", at_datetime=achievement_date) create_goals( achievement=achievement, goal_condition= """{"term": {"type": "literal", "variable": "invite_users"}}""", goal_group_by_key=True, goal_operator="geq", goal_goal="1*level") clear_all_caches() result = Achievement.evaluate(user, achievement.id, achievement_date) print("reward_achievement_result:", result) self.assertEqual(len(result["new_levels"]["2"]["rewards"]), 0) self.assertEqual(len(result["new_levels"]["3"]["rewards"]), 1) self.assertEqual(len(result["new_levels"]["2"]["properties"]), 1) self.assertEqual(len(result["new_levels"]["3"]["properties"]), 1)