def predict_desired_level(self, request): skill = Skills(request) target_level = skill.get_desired_level() if self.default_level < target_level and self.fill_skills: self.set_skills_to_desired_level(target_level) return target_level else: return self.predict_level("desired")
def save(self): if self.is_valid(): skills = Skills(self.request) skills.save_skills(self.skills) skills.save_desired_level(self.desired_level) skills.save_multiplier(self.multiplier) skills.save_fill_skills(self.fill_skills) else: raise SkillsValidationError(self.errors)
def manage_race_post(request): race = request.POST.get("race") reset_skills = default_skills_race_update(race) skills = Skills(request) skills.save_race(race) skills.save_skills(reset_skills) skills.save_fill_skills(None)
def test_skills_save_properties_to_session(self): request = self.FakeRequest() skills = Skills(request) skills.save_skills({"some"}) skills.save_desired_level(1) skills.save_multiplier(1.5) skills.save_fill_skills("true") self.assertDictEqual( request.session, { "skills": {"some"}, "desired_level": 1, "multiplier": 1.5, "fill_skills": "true" })
def __init__(self, request): skills = Skills(request) self.race = skills.get_race() self.skills = skills.get_skills() self.multiplier = skills.get_multiplier() self.fill_skills = skills.get_fill_skills() self.default_level = self.predict_level("default") self.desired_level = self.predict_desired_level(request) self.commands = self.commands_list()
def test_can_get_fill_skills(self): request = self.FakeRequest() request.session.update({"fill_skills": "true"}) skills = Skills(request) self.assertEqual(skills.get_fill_skills(), "true")
def test_have_default_multiplier(self): request = self.FakeRequest() skills = Skills(request) self.assertEqual(skills.get_multiplier(), 1.5)
def test_can_get_multiplier(self): request = self.FakeRequest() request.session.update({"multiplier": 2.5}) skills = Skills(request) self.assertEqual(skills.get_multiplier(), 2.5)
def test_have_default_desired_level(self): request = self.FakeRequest() skills = Skills(request) self.assertEqual(skills.get_desired_level(), 1)
def test_can_get_desired_level(self): request = self.FakeRequest() request.session.update({"desired_level": 1}) skills = Skills(request) self.assertEqual(skills.get_desired_level(), 1)
def test_have_default_skills(self): request = self.FakeRequest() skills = Skills(request) expected = setup_default_nord() self.assertDictEqual(skills.get_skills(), expected)
def test_can_get_default_race(self): request = self.FakeRequest() skills = Skills(request) self.assertEqual(skills.get_race(), "nord")
def test_can_get_race(self): request = self.FakeRequest() request.session.update({"race": "ork"}) skills = Skills(request) self.assertEqual(skills.get_race(), "ork")
def test_skills_can_save_race(self): request = self.FakeRequest() skills = Skills(request) skills.save_race("ork") self.assertEqual(request.session.get("race"), "ork")
def test_have_default_fill_skills(self): request = self.FakeRequest() skills = Skills(request) self.assertEqual(skills.get_fill_skills(), None)
def reset_skills(request): skills = Skills(request) race = skills.get_race() skills_after_reset = default_skills_race_update(race) skills.save_skills(skills_after_reset) skills.save_fill_skills(None)
def test_can_get_skills(self): request = self.FakeRequest() request.session.update({"skills": {"Some!"}}) skills = Skills(request) self.assertEqual(skills.get_skills(), {"Some!"})