Ejemplo n.º 1
0
    def test_max_risk(self):
        goal = Fixture1.goal1()
        settings = Fixture1.settings1()
        client = goal.account.primary_owner
        # Add the weights for the risk factors
        Fixture1.populate_risk_profile_questions()  # Also populates all possible answers.
        Fixture1.populate_risk_profile_responses()

        # we haven't set a net worth or a target, so worth_score isn't a factor

        # An all-9s account will have a max_risk of 1
        self.assertEqual(max_risk(settings), 1.0)

        # and if they are low risk behavior, high Ability + Sophistication
        # the max risk is still 1
        client.risk_profile_responses.clear()
        client.risk_profile_responses.add(Fixture1.risk_profile_answer1c())
        client.risk_profile_responses.add(Fixture1.risk_profile_answer2c())
        self.assertEqual(max_risk(settings), 1.0)

        # but if they are risky, new and unskilled, recommend no risk
        client.risk_profile_responses.clear()
        client.risk_profile_responses.add(Fixture1.risk_profile_answer1d())
        client.risk_profile_responses.add(Fixture1.risk_profile_answer2d())
        self.assertAlmostEqual(recommend_risk(settings), 0.1, 1)
        self.assertAlmostEqual(max_risk(settings), 0.1, 1)
Ejemplo n.º 2
0
 def test_put_settings_with_risk_too_high(self):
     url = '/api/v1/goals/{}/selected-settings'.format(Fixture1.goal1().id)
     self.client.force_authenticate(user=Fixture1.client1().user)
     rsm = self.risk_score_metric.copy()
     rsm['configured_val'] = 0.9
     new_settings = {
         "metric_group": {"metrics": [rsm]},
     }
     self.assertLess(max_risk(Fixture1.goal1().selected_settings), 0.9)
     response = self.client.put(url, new_settings)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 3
0
 def test_fully_answered_zero_max(self):
     goal = Fixture1.goal1()
     setting = Fixture1.settings1()
     risk_metric = setting.metric_group.metrics.get(type=GoalMetric.METRIC_TYPE_RISK_SCORE)
     q = RiskProfileQuestionFactory.create(group=goal.account.primary_owner.risk_profile_group)
     a = RiskProfileAnswerFactory.create(b_score=0, a_score=0, s_score=0, question=q)
     client = goal.account.primary_owner
     client.risk_profile_responses.add(a)
     self.assertGreater(risk_metric.configured_val, 0.01)
     with self.assertRaises(ValidationError) as ex:
         validate_risk_score(setting)
     risk_metric.configured_val = 0
     risk_metric.save()
     self.assertEqual(validate_risk_score(setting), None)  # Should now complete OK.
     self.assertEqual(max_risk(setting), 0.0)
     self.assertEqual(recommend_risk(setting), 0.0)