def test_change_account_cash(self): goal1 = Fixture1.goal1() account = Fixture1.personal_account1() account.all_goals.return_value = [goal1] #no difference account.cash_balance = 1000 ib_account = account.ib_account ib_account_cash[ib_account.ib_account] = 1000 difference = reconcile_cash_client_account(account) self.assertAlmostEqual(0, difference) self.assertEqual(ib_account.ib_account, 'DU299694') #deposit - transferred to account.cash_balance ib_account_cash[ib_account.ib_account] = 1100 reconcile_cash_client_account(account) self.assertAlmostEqual(1100, account.cash_balance) #withdrawal - from account.cash_balance ib_account_cash[ib_account.ib_account] = 900 reconcile_cash_client_account(account) self.assertAlmostEqual(900, account.cash_balance) #exception - sum of goal cash balances > ib_account_cash goal1.cash_balance = 1000 goal1.save() account.cash_balance = 100 ib_account_cash[ib_account.ib_account] = 900 with self.assertRaises(Exception) as cm: reconcile_cash_client_account(account) self.assertTrue(ib_account.ib_account in cm.exception.args[0])
def test_create_account(self): url = '/api/v1/accounts' client = Fixture1.client1() data = { 'account_type': ACCOUNT_TYPE_PERSONAL, 'account_name': 'Test Account', 'primary_owner': client.id, } old_count = ClientAccount.objects.count() self.client.force_authenticate(user=Fixture1.client1_user()) response = self.client.post(url, data) # First off, the test should fail, as personal accounts are not activated for the firm yet. self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED) # Add the personal account type, then the post should succeed Fixture1.client1().advisor.firm.account_types.add( self.personal_account_type) response = self.client.post(url, data) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(ClientAccount.objects.count(), 1) self.assertTrue('id' in response.data) self.assertEqual(response.data['account_name'], 'Test Account') # Don't let them create a second personal account data = { 'account_type': ACCOUNT_TYPE_PERSONAL, 'account_name': 'Test Account 2', 'primary_owner': client.id, } response = self.client.post(url, data) self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED) self.assertEqual(ClientAccount.objects.count(), 1)
def test_add_goal_complete(self): # tickers for testing portfolio calculations in goals endpoint # otherwise, No valid instruments found self.bonds_index = MarketIndexFactory.create() self.stocks_index = MarketIndexFactory.create() self.bonds_ticker = TickerFactory.create( asset_class=self.bonds_asset_class, benchmark=self.bonds_index) self.stocks_ticker = TickerFactory.create( asset_class=self.stocks_asset_class, benchmark=self.stocks_index) # Set the markowitz bounds for today self.m_scale = MarkowitzScaleFactory.create() # populate the data needed for the optimisation # We need at least 500 days as the cycles go up to 70 days and we need at least 7 cycles. populate_prices(500, asof=mocked_now.date()) populate_cycle_obs(500, asof=mocked_now.date()) populate_cycle_prediction(asof=mocked_now.date()) self.portfolio_provider = PortfolioProvider.objects.create( name='Krane', type=PORTFOLIO_PROVIDER_TYPE_KRANE) url = '/api/v1/goals' self.client.force_authenticate(user=Fixture1.client1().user) account = ClientAccountFactory.create(primary_owner=Fixture1.client1()) goal_settings = GoalSettingFactory.create() goal_metric = GoalMetricFactory.create( group=goal_settings.metric_group) ser = GoalCreateSerializer( data={ 'account': account.id, 'name': 'Zero Goal Target', 'type': GoalTypeFactory().id, 'target': 500, 'completion': timezone.now().date(), 'initial_deposit': 0, 'ethical': True, 'portfolio_provider': self.portfolio_provider.id }) self.assertEqual(ser.is_valid(), True, msg="Serializer has errors %s" % ser.errors) response = self.client.post(url, ser.data) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.data['selected_settings']['target'], 500) # "OnTrack" is false because the 500 deposit is still pending self.assertEqual(response.data['on_track'], False) goal = Goal.objects.get(pk=response.data['id']) goal.cash_balance += 500 goal.save() response = self.client.get('%s/%s' % (url, goal.id)) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['selected_settings']['target'], 500) self.assertEqual(response.data['on_track'], True)
def test_get_asset_weights_held_less_than1y_without_new_postions(self): fund = TickerFactory.create(unit_price=2.1) goal = GoalFactory.create() today = datetime.date(2016, 1, 1) # Create a 6 month old execution, transaction and a distribution that caused the transaction Fixture1.create_execution_details(goal, fund, 10, 2, datetime.date(2014, 6, 1)) ep = ExecutionProviderDjango() vals = ep.get_asset_weights_held_less_than1y(goal, today) self.assertEqual(len(vals), 0)
def test_external_instrument(self): Fixture1.external_instrument1() Fixture1.external_instrument2() instrument1 = ExternalInstrument.objects.get(institution=ExternalInstrument.Institution.APEX.value, ticker__symbol='SPY') instrument2 = ExternalInstrument.objects.get(institution=ExternalInstrument.Institution.INTERACTIVE_BROKERS.value, ticker__symbol='SPY') self.assertTrue(instrument1.instrument_id == 'SPY_APEX') self.assertTrue(instrument2.instrument_id == 'SPY_IB')
def test_perturbate_withdrawal(self): Fixture1.create_execution_details(self.goal, self.t4, self.goal.available_balance / 90, 90, date(2016, 1, 1)) TransactionFactory.create(from_goal=self.goal, status=Transaction.STATUS_PENDING, amount=self.goal.total_balance / 2) weights = perturbate_withdrawal(self.goal) self.assertTrue(sum(weights.values()) < 1)
def test_get_goal_types(self): Fixture1.goal_type1() url = '/api/v1/settings/goal-types' self.client.force_authenticate(user=Fixture1.client1().user) response = self.client.get(url) self.assertEqual(len(response.data), 1) self.assertEqual(response.data[0]['name'], 'goaltype1') self.assertFalse( 'risk_sensitivity' in response.data[0]) # We should not make public our risk model.
def test_get_asset_weights_without_tax_winners(self): fund = TickerFactory.create(unit_price=3) goal = GoalFactory.create() today = datetime.date(2016, 1, 1) # Create a 6 month old execution, transaction and a distribution that caused the transaction Fixture1.create_execution_details(goal, fund, 10, 2, datetime.date(2014, 6, 1)) Fixture1.create_execution_details(goal, fund, 10, 4, datetime.date(2015, 6, 1)) ep = ExecutionProviderDjango() vals = ep.get_asset_weights_without_tax_winners(goal=goal) self.assertAlmostEqual(vals[fund.id], (10*3) / goal.available_balance)
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)
def test_account_types_non_creatable(self): url = '/api/v1/settings/account-types' self.client.force_authenticate(user=Fixture1.client1().user) # Populate a non-creatable and check Fixture1.client1().advisor.firm.account_types.add( self.r401k_account_type) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 1) self.assertEqual(response.data[0]['creatable'], False)
def test_get_detail(self): goal = Fixture1.goal1() url = '/api/v1/goals/{}'.format(goal.id) goal.approve_selected() self.client.force_authenticate(user=Fixture1.client1().user) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['id'], Fixture1.goal1().id) # Make sure for the detail endpoint, selected settings is an object, but active and approved are null or integer. self.assertEqual(response.data['active_settings'], None) self.assertEqual(response.data['approved_settings'], response.data['selected_settings']['id'])
def test_account_must_be_confirmed(self): account = Fixture1.personal_account1() account.confirmed = False account.save() self.assertFalse(account.confirmed) with self.assertRaises(ValidationError) as e: goal = Goal.objects.create(account=Fixture1.personal_account1(), name='goal1', type=Fixture1.goal_type1(), portfolio_set=Fixture1.portfolioset1(), selected_settings=Fixture1.settings1())
def test_validate_risk_score_with_unlimited(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) try: validate_risk_score(setting, True) except ValidationError: self.fail("validate_risk_score() should not raise ValidationError when `risk_score_unlimited` is set.")
def test_recommended_risk_scores(self): """ expects the years parameter for the span of risk scores """ url = '/api/v1/goals/{}/risk-score-data'.format(Fixture1.goal1().id) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.client.force_authenticate(user=Fixture1.client1().user) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['max'], MINIMUM_RISK) self.assertEqual(response.data['recommended'], MINIMUM_RISK)
def test_put_settings_no_memo(self): # Test PUT with no memo old_events = Log.objects.count() old_memos = EventMemo.objects.count() url = '/api/v1/goals/{}/selected-settings'.format(Fixture1.goal1().id) self.client.force_authenticate(user=Fixture1.client1().user) settings_changes = {"target": 1928355} response = self.client.put(url, settings_changes) self.assertEqual(response.status_code, status.HTTP_200_OK) # Make sure an event log was written self.assertEqual(old_events + 1, Log.objects.count()) # Make sure no event memo was written self.assertEqual(old_memos, EventMemo.objects.count())
def test_get_context_positions(self): kwargs = {} # empty queries tests, should be empty unless Positions are # added to setUp positions = self.view.get_context_positions(**kwargs) self.assertSequenceEqual(positions.get('asset_class'), []) self.assertSequenceEqual(positions.get('region'), []) self.assertSequenceEqual(positions.get('investment_type'), []) # now we're going to add some data and rerun sequence tests # have to specify content_type here because ticker uses the django # built in contenttype it causes problems here otherwise, # TODO: maybe some more elegant factoryboy solution here? ticker1 = TickerFactory.create() ticker2 = TickerFactory.create( benchmark_content_type=ticker1.benchmark_content_type) ticker3 = TickerFactory.create( benchmark_content_type=ticker1.benchmark_content_type) goal = GoalFactory.create() today = date(2016, 1, 1) # Create a 6 month old execution, transaction and a distribution that caused the transaction data1 = Fixture1.create_execution_details(goal, ticker1, 10, 2, date(2014, 6, 1)) data2 = Fixture1.create_execution_details(goal, ticker2, 10, 2, date(2014, 6, 1)) data3 = Fixture1.create_execution_details(goal, ticker3, 10, 2, date(2014, 6, 1)) positions = self.view.get_context_positions(**kwargs) # should be three results, one for each position we just added self.assertEqual(len(positions.get('asset_class')), 3) self.assertEqual(len(positions.get('region')), 3) self.assertEqual(len(positions.get('investment_type')), 3) # compare sum of values to double check values being passed expected_sum = data1[-1].quantity * ticker1.unit_price + \ data2[-1].quantity * ticker2.unit_price + \ data3[-1].quantity * ticker3.unit_price asset_actual_sum = sum( [x.get('value') for x in positions.get('asset_class')]) region_actual_sum = sum( [x.get('value') for x in positions.get('region')]) investment_actual_sum = sum( [x.get('value') for x in positions.get('investment_type')]) self.assertAlmostEqual(expected_sum, asset_actual_sum) self.assertAlmostEqual(expected_sum, region_actual_sum) self.assertAlmostEqual(expected_sum, investment_actual_sum)
def test_calculate_portfolio(self): """ expects the setting parameter to be a json dump of the goal settings to use for the portfolio calculation """ # tickers for testing portfolio calculations in goals endpoint # otherwise, No valid instruments found TickerFactory.create(symbol='IAGG', asset_class=self.bonds_asset_class) TickerFactory.create(symbol='AGG', asset_class=self.bonds_asset_class) TickerFactory.create(symbol='ITOT', asset_class=self.stocks_asset_class) TickerFactory.create(symbol='GRFXX', asset_class=self.stocks_asset_class) TickerFactory.create(symbol='IPO') fund = TickerFactory.create(symbol='rest') self.portfolio_set.asset_classes.add(fund.asset_class) # Set the markowitz bounds for today self.m_scale = MarkowitzScaleFactory.create() # populate the data needed for the optimisation # We need at least 500 days as the cycles go up to 70 days and we need at least 7 cycles. populate_prices(500, asof=mocked_now.date()) populate_cycle_obs(500, asof=mocked_now.date()) populate_cycle_prediction(asof=mocked_now.date()) account = ClientAccountFactory.create(primary_owner=Fixture1.client1()) # setup some inclusive goal settings goal_settings = GoalSettingFactory.create() # Create a risk score metric for the settings GoalMetricFactory.create(group=goal_settings.metric_group, type=GoalMetric.METRIC_TYPE_RISK_SCORE) portfolio_provider = PortfolioProvider( type=constants.PORTFOLIO_PROVIDER_TYPE_KRANE) portfolio_provider.save() goal = GoalFactory.create(account=account, portfolio_provider=portfolio_provider, selected_settings=goal_settings, portfolio_set=self.portfolio_set) serializer = GoalSettingSerializer(goal_settings) url = '/api/v1/goals/{}/calculate-portfolio?setting={}'.format( goal.id, json.dumps(serializer.data)) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.client.force_authenticate(user=Fixture1.client1().user) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_get_all_activity(self): # First add some transactions, balances and eventlogs, and make sure the ActivityLogs are set. Fixture1.settings_event1() Fixture1.transaction_event1() Fixture1.populate_balance1() # 2 Activity lines # We also need to activate the activity logging for the desired event types. ActivityLogEvent.get(Event.APPROVE_SELECTED_SETTINGS) ActivityLogEvent.get(Event.GOAL_BALANCE_CALCULATED) ActivityLogEvent.get(Event.GOAL_DEPOSIT_EXECUTED) url = '/api/v1/goals/{}/activity'.format(Fixture1.goal1().id) self.client.force_authenticate(user=Fixture1.client1().user) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 4) # Note the Goal not included in response as it is in request. self.assertEqual(response.data[0], {'time': 946684800, 'type': ActivityLogEvent.get(Event.APPROVE_SELECTED_SETTINGS).activity_log.id}) # Setting change approval self.assertEqual(response.data[1], {'balance': 0.0, 'time': 978220800, 'type': ActivityLogEvent.get(Event.GOAL_BALANCE_CALCULATED).activity_log.id}) # Balance # Deposit. Note inclusion of amount, as we're looking at it from the goal perspective. self.assertEqual(response.data[2], {'amount': 3000.0, 'data': [3000.0], 'time': 978307200, 'type': ActivityLogEvent.get(Event.GOAL_DEPOSIT_EXECUTED).activity_log.id}) self.assertEqual(response.data[3], {'balance': 3000.0, 'time': 978307200, 'type': ActivityLogEvent.get(Event.GOAL_BALANCE_CALCULATED).activity_log.id}) # Balance
def test_add_plan_with_json_fields(self): ''' Tests: - clients can create a retirement plan. - specifying btc on creation works ''' external_asset = ExternalAssetFactory.create(owner=Fixture1.client1(), valuation=100000) url = '/api/v1/clients/{}/retirement-plans'.format( Fixture1.client1().id) self.client.force_authenticate(user=Fixture1.client1().user) plan_data = self.base_plan_data.copy() plan_data['partner_data'] = { 'name': 'Freddy', 'dob': date(2000, 1, 1), 'income': 50000, 'btc': 1000 } plan_data['expenses'] = [ { "id": 1, "desc": "Car", "cat": RetirementPlan.ExpenseCategory.TRANSPORTATION.value, "who": "self", "amt": 200, }, ] plan_data['savings'] = [ { "id": 1, "desc": "Health Account", "cat": RetirementPlan.SavingCategory.HEALTH_GAP.value, "who": "self", "amt": 100, }, ] plan_data['initial_deposits'] = [ { "id": 1, "asset": external_asset.id, "amt": 10000, }, ] response = self.client.post(url, plan_data) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.data['partner_data']['btc'], 1000) saved_plan = RetirementPlan.objects.get(id=response.data['id']) self.assertEqual(saved_plan.savings[0]['amt'], 100) self.assertEqual(saved_plan.expenses[0]['amt'], 200) self.assertEqual(saved_plan.initial_deposits[0]['amt'], 10000)
def test_get_all_activity(self): # First add some transactions, balances and eventlogs, and make sure the ActivityLogs are set Fixture1.settings_event1() Fixture1.transaction_event1() Fixture1.populate_balance1() # 2 Activity lines ActivityLogEvent.get(Event.APPROVE_SELECTED_SETTINGS) ActivityLogEvent.get(Event.GOAL_BALANCE_CALCULATED) ActivityLogEvent.get(Event.GOAL_DEPOSIT_EXECUTED) url = '/api/v1/clients/{}/activity'.format( Fixture1.personal_account1().primary_owner.id) self.client.force_authenticate( user=Fixture1.personal_account1().primary_owner.user) response = self.client.get(url) self.assertEqual(len(response.data), 4) self.assertEqual( response.data[3], { 'goal': 1, 'account': 1, 'time': 946684800, 'type': ActivityLogEvent.get( Event.APPROVE_SELECTED_SETTINGS).activity_log.id }) # Setting change self.assertEqual( response.data[2], { 'balance': 0.0, 'time': 978220800, 'type': ActivityLogEvent.get( Event.GOAL_BALANCE_CALCULATED).activity_log.id }) # Balance self.assertEqual( response.data[1], { 'balance': 3000.0, 'time': 978307200, 'type': ActivityLogEvent.get( Event.GOAL_BALANCE_CALCULATED).activity_log.id }) # Balance self.assertEqual( response.data[0], { 'data': [3000.0], 'goal': 1, 'account': 1, 'time': 978307200, 'type': ActivityLogEvent.get( Event.GOAL_DEPOSIT_EXECUTED).activity_log.id }) # Deposit
def test_add_plan(self): ''' Tests: - clients can create a retirement plan. - specifying btc on creation works ''' url = '/api/v1/clients/{}/retirement-plans'.format( Fixture1.client1().id) self.client.force_authenticate(user=Fixture1.client1().user) response = self.client.post(url, self.base_plan_data) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.data['btc'], 3200) # 80000 * 0.04 self.assertNotEqual(response.data['id'], None) saved_plan = RetirementPlan.objects.get(id=response.data['id']) self.assertEqual(saved_plan.btc, 3200)
def test_create_us_retirement_fail(self): Fixture1.client1().advisor.firm.account_types.add(self.roth401k) url = '/api/v1/accounts' client = Fixture1.client1() data = { 'account_type': ACCOUNT_TYPE_ROTH401K, 'account_name': 'Test Failing Account', 'primary_owner': client.id, } self.client.force_authenticate(user=Fixture1.client1_user()) response = self.client.post(url, data) self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED) self.assertTrue('are not user creatable' in str(response.content))
def setUp(self): self.rt = RecurringTransaction.objects.create( setting=Fixture1.settings1(), begin_date=timezone.now().date(), amount=10, growth=0.0005, schedule='RRULE:FREQ=MONTHLY;BYMONTHDAY=4')
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)
def test_account_types(self): url = '/api/v1/settings/account-types' self.client.force_authenticate(user=Fixture1.client1().user) # Before populating any account types for the firm, they are returned as empty. response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 0) # Populate some and we should get them back Fixture1.client1().advisor.firm.account_types.add( self.personal_account_type) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 1) self.assertEqual(response.data[0]['creatable'], True)
def test_do_not_rebuy_within_30_days(self): # finish test GoalMetricFactory.create(group=self.goal_settings.metric_group, feature=self.equity, type=GoalMetric.METRIC_TYPE_RISK_SCORE, rebalance_type=GoalMetric.REBALANCE_TYPE_ABSOLUTE, rebalance_thr=0.5, configured_val=0.5) weights, instruments, reason = rebalance(self.goal, self.idata, self.data_provider, self.execution_provider) executed = datetime(year=2016, month=5, day=15) for i in range(3, 5): Fixture1.create_execution_details(self.goal, self.tickers[i], -self.quantities[i],self.tickers[i].unit_price, executed) self.goal.cash_balance += self.tickers[i].unit_price * abs(self.quantities[i]) weights, instruments, reason = rebalance(self.goal, self.idata, self.data_provider, self.execution_provider) self.assertAlmostEqual(weights[4], 0)
def test_only_active_asset_features_in_settings(self): """ Should only return asset features values for active Ticker assets where we have funds. """ url = '/api/v1/settings/asset-features' # add some assets self.bonds_ticker.state = 1 self.bonds_ticker.save() # Add some asset features that have no values, and some feature values that have no assets. # They should also not be included. orphan_feature = AssetFeatureFactory.create() orphan_feature_value = AssetFeatureValueFactory.create() self.client.force_authenticate(user=Fixture1.client1().user) response = self.client.get(url) inactive_asset_feature = [ af for af in AssetFeature.objects.all() if not af.active ] self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual( len(response.data), AssetFeature.objects.count() - len(inactive_asset_feature)) self.assertTrue( orphan_feature.id not in [f['id'] for f in response.data]) for f in response.data: for fv in f['values']: self.assertNotEqual( fv['id'], orphan_feature_value.id, msg='Orphaned feature value in setting endpoint')
def test_saving(self): advisor = Fixture1.advisor1() advisor.regional_data = { 'tax_file_number': '1234', } advisor.clean() advisor.save() advisor = self.o(advisor) self.assertDictEqual(advisor.regional_data, { 'tax_file_number': '1234', }) advisor.regional_data = '' with self.assertRaises(ValueError) as e: advisor.clean() self.assertEqual(str(e.exception), "{'regional_data': " "\"Must be 'dict' type.\"}") advisor.regional_data = {} advisor.clean() advisor.save() advisor = self.o(advisor) self.assertEqual(advisor.regional_data, {})
def goal_opening(self, value): with mock.patch.object(timezone, 'now', self.mocked_date(0)): self.goal = Fixture1.goal1() Transaction.objects.create(reason=Transaction.REASON_DEPOSIT, to_goal=self.goal, amount=value, status=Transaction.STATUS_EXECUTED, executed=timezone.now())
def test_recommend_risk_fully_answered_bad_questions(self): # Fully populate the answers, but no range in the available question responses, we should get 0.5 goal = Fixture1.goal1() settings = Fixture1.settings1() account = settings.goal.account Fixture1.populate_risk_profile_questions() # Also populates all possible answers. Fixture1.populate_risk_profile_responses() Fixture1.risk_profile_question3() # Add a question we don't have an answer for self.assertEqual(recommend_risk(settings), MINIMUM_RISK) # Now answer the question, we shouldn't get MINIMUM_RISK account.primary_owner.risk_profile_responses.add(Fixture1.risk_profile_answer3a()) self.assertNotEqual(recommend_risk(settings), MINIMUM_RISK)