コード例 #1
0
    def test_cant_change_after_agreed(self):
        '''
        Tests:
        - clients can create a retirement plan.
        - specifying btc on creation works
        '''
        client = Fixture1.client1()
        url = '/api/v1/clients/%s/retirement-plans' % client.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)

        # Now update it with agreed_on=Now
        url = '/api/v1/clients/%s/retirement-plans/%s' % (client.id,
                                                          response.data['id'])
        dt = now()
        new_data = dict(self.base_plan_data, agreed_on=dt)
        response = self.client.put(url, new_data)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # Now we can't update it
        url = '/api/v1/clients/%s/retirement-plans/%s' % (client.id,
                                                          response.data['id'])
        response = self.client.put(url, self.base_plan_data)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
コード例 #2
0
ファイル: test_goal.py プロジェクト: dan0712/django-app
    def test_calculate_portfolio_complete(self):
        # 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='ITOT', 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)
        goal = GoalFactory.create(account=account, selected_settings=goal_settings, portfolio_set=self.portfolio_set,
                                  active_settings=goal_settings)
        goal_settings.completion_date = timezone.now().date() - timedelta(days=365)
        serializer = GoalSettingSerializer(goal_settings)
        url = '/api/v1/goals/{}/calculate-all-portfolios?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)
コード例 #3
0
 def test_add_retirement_plan_same_location_no_postal(self):
     url = '/api/v1/clients/{}/retirement-plans'.format(
         Fixture1.client1().id)
     data = {
         "name": "Personal Plan",
         "description": "My solo plan",
         'desired_income': 60000,
         'income': 80000,
         'volunteer_days': 1,
         'paid_days': 2,
         'same_home': False,
         'same_location': True,
         'reverse_mortgage': True,
         'expected_return_confidence': 0.5,
         'retirement_age': 65,
         'btc': 1000,
         'atc': 300,
         'desired_risk': 0.6,
         'selected_life_expectancy': 80,
     }
     self.client.force_authenticate(user=Fixture1.client1().user)
     response = self.client.post(url, data)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
     self.assertEqual(response.data['btc'], 1000)
     self.assertNotEqual(response.data['id'], None)
     saved_plan = RetirementPlan.objects.get(id=response.data['id'])
     self.assertEqual(saved_plan.btc, 1000)
     self.assertEqual(saved_plan.retirement_age, 65)
コード例 #4
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)
コード例 #5
0
    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)
コード例 #6
0
ファイル: test_settings.py プロジェクト: fagan2888/Betasmartz
    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)
コード例 #7
0
    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)
コード例 #8
0
 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)
コード例 #9
0
 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)
コード例 #10
0
ファイル: test_account.py プロジェクト: fagan2888/Betasmartz
    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))
コード例 #11
0
 def test_post_settings_with_memo_false_staff(self):
     # Test POST with a memo and false staff
     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)
     new_settings = {
         "completion": "2016-01-01",
         # Any metrics set must have a risk score metric.
         "metric_group": {
             "metrics": [self.risk_score_metric]
         },
         "hedge_fx": False,
         "event_memo": "Replaced because the old one smelled.",
         "event_memo_staff": False,
     }
     response = self.client.post(url, new_settings)
     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 an event memo was written
     self.assertEqual(old_memos + 1, EventMemo.objects.count())
     # Make sure the memo was the text I passed, and staff is false.
     memo = EventMemo.objects.order_by('-id')[0]
     self.assertFalse(memo.staff)
     self.assertEqual(memo.comment, new_settings['event_memo'])
コード例 #12
0
    def test_get_goal_settings_by_id(self):
        goal = Fixture1.goal1()
        setting = goal.selected_settings
        url = '/api/v1/goals/{}/settings/{}'.format(goal.id, setting.id)

        # unauthenticated
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        # authenticated
        self.client.force_authenticate(user=Fixture1.client1().user)
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertNotEqual(response.data, [])
        self.assertEqual(response.data.get('id'), setting.id)

        # 404 check
        url = '/api/v1/goals/{}/settings/{}'.format(goal.id, 99999)
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

        # Unauthorized user check
        self.client.force_authenticate(user=Fixture1.client2().user)
        url = '/api/v1/goals/{}/settings/{}'.format(goal.id, setting.id)
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
コード例 #13
0
 def test_performance_history_empty(self):
     url = '/api/v1/goals/{}/performance-history'.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(response.data, [])
コード例 #14
0
ファイル: test_settings.py プロジェクト: fagan2888/Betasmartz
    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')
コード例 #15
0
    def test_put_settings_recurring_transactions(self):
        # Test PUT with good transaction data
        tx1 = RecurringTransactionFactory.create()
        tx2 = RecurringTransactionFactory.create()
        url = '/api/v1/goals/{}/selected-settings'.format(Fixture1.goal1().id)
        self.client.force_authenticate(user=Fixture1.client1().user)
        serializer = RecurringTransactionCreateSerializer(tx1)
        serializer2 = RecurringTransactionCreateSerializer(tx2)
        settings_changes = {
            'recurring_transactions': [
                serializer.data,
                serializer2.data,
            ],
        }
        response = self.client.put(url, settings_changes)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # bad transaction missing enabled field
        data = serializer.data
        del data['enabled']
        settings_changes = {
            'recurring_transactions': [
                data,
                serializer2.data,
            ],
        }
        response = self.client.put(url, settings_changes)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
コード例 #16
0
ファイル: test_settings.py プロジェクト: fagan2888/Betasmartz
    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)
コード例 #17
0
ファイル: test_goal.py プロジェクト: dan0712/django-app
    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
コード例 #18
0
ファイル: test_goal.py プロジェクト: dan0712/django-app
    def test_get_pending_transfers(self):
        # Populate an executed deposit and make sure no pending transfers are returned
        tx1 = Fixture1.transaction1()
        url = '/api/v1/goals/{}/pending-transfers'.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(response.data, [])

        # Populate 2 pending transfers (a deposit and withdrawal) and make sure they are both returned.
        tx2 = Fixture1.pending_deposit1()
        tx3 = Fixture1.pending_withdrawal1()
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        data = [
            {
                "id": 3,
                "time": 946652400,
                "amount": -3500.0
            },
            {
                "id": 2,
                "time": 946648800,
                "amount": 4000.0
            }
        ]
        self.assertEqual(response.data, data)
コード例 #19
0
    def test_create_goal(self):
        self.bonds_index = MarketIndexFactory.create()
        self.stocks_index = MarketIndexFactory.create()

        self.bonds_asset_class = AssetClassFactory.create(
            investment_type=InvestmentType.Standard.BONDS.get())
        self.stocks_asset_class = AssetClassFactory.create(
            investment_type=InvestmentType.Standard.STOCKS.get())
        # Add the asset classes to the portfolio set
        self.portfolio_set = PortfolioSetFactory.create()
        self.portfolio_set.asset_classes.add(self.bonds_asset_class,
                                             self.stocks_asset_class)
        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)

        self.portfolio_provider = PortfolioProvider.objects.create(
            name='Krane', type=PORTFOLIO_PROVIDER_TYPE_KRANE)

        # 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()
        goal_type = GoalTypeFactory.create()
        url = '/api/v1/goals'
        data = {
            'account': account.id,
            'name': 'Fancy new goal',
            'type': goal_type.id,
            'target': 15000.0,
            'completion': "2016-01-01",
            'initial_deposit': 5000,
            'ethical': True,
            'portfolio_provider': self.portfolio_provider.id
        }

        # unauthenticated 403
        response = self.client.post(url, data)
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        # authenticated 200
        self.client.force_authenticate(account.primary_owner.user)
        response = self.client.post(url, data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertDictEqual(
            response.data['portfolio_provider'], {
                'id': self.portfolio_provider.id,
                'name': self.portfolio_provider.name,
                'type': PORTFOLIO_PROVIDER_TYPE_KRANE
            })
コード例 #20
0
ファイル: test_settings.py プロジェクト: fagan2888/Betasmartz
 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.
コード例 #21
0
ファイル: test_settings.py プロジェクト: fagan2888/Betasmartz
    def test_get_investor_risk_categories(self):
        RiskCategory.objects.create(name='Ripping', upper_bound=0.7)

        url = '/api/v1/settings/investor-risk-categories'
        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'], 'Ripping')
        self.assertEqual(response.data[0]['upper_bound'], 0.7)
コード例 #22
0
 def test_all_dates(self):
     self.client.force_authenticate(user=Fixture1.client1().user)
     r = self.request(status_code=200)
     content = ujson.loads(r.content)['data']
     self.assertEqual(content, [
         [16893, 0.1],
         [16894, -0.045454545454545005],
         [16895, -0.019047619047619],
         [16896, 0.03883495145631],
     ])
コード例 #23
0
ファイル: test_goal.py プロジェクト: dan0712/django-app
 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'])
コード例 #24
0
ファイル: test_goal.py プロジェクト: dan0712/django-app
 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)
コード例 #25
0
 def test_top_bound_dates(self):
     self.client.force_authenticate(user=Fixture1.client1().user)
     r = self.request(data={
         'ed': '2016-04-04',
     }, status_code=200)
     content = ujson.loads(r.content)['data']
     self.assertEqual(content, [
         [16893, 0.1],
         [16894, -0.045454545454545005],
         [16895, -0.019047619047619],
     ])
コード例 #26
0
ファイル: test_settings.py プロジェクト: fagan2888/Betasmartz
    def test_get_activity_types(self):
        # Populate some activity type items
        ActivityLog.objects.all().delete()
        ActivityLogEvent.objects.all().delete()
        ActivityLogEvent.get(Event.APPROVE_SELECTED_SETTINGS)
        ActivityLogEvent.get(Event.GOAL_WITHDRAWAL_EXECUTED)

        url = '/api/v1/settings/activity-types'
        self.client.force_authenticate(user=Fixture1.client1().user)
        response = self.client.get(url)
        self.assertEqual(len(response.data), 2)
コード例 #27
0
ファイル: test_settings.py プロジェクト: fagan2888/Betasmartz
    def test_get_portfolio_sets(self):
        portfolio_set = PortfolioSetFactory.create()

        url = '/api/v1/settings/portfolio-sets'
        self.client.force_authenticate(user=Fixture1.client1().user)
        response = self.client.get(url)

        self.assertEqual(len(response.data),
                         PortfolioSet.objects.all().count())
        self.assertTrue('name' in response.data[0])
        self.assertTrue('portfolio_provider' in response.data[0])
コード例 #28
0
 def test_add_retirement_plan_with_expenses(self):
     expenses = [{
         "cat": 3,
         "amt": 10000,
         "desc": "123",
         "who": "self",
         "id": 1
     }]
     self.base_plan_data['expenses'] = expenses
     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)
     self.assertNotEqual(response.data['expenses'], None)
     self.assertEqual(response.data['expenses'][0]['id'], 1)
     self.assertEqual(response.data['expenses'][0]['amt'], 10000)
コード例 #29
0
    def test_get_portfolio_sets(self):
        PortfolioSet.objects.create(name='Krane',
                                    type=PORTFOLIO_SET_TYPE_KRANE,
                                    risk_free_rate=0.0)

        url = '/api/v1/settings/portfolio-sets'
        self.client.force_authenticate(user=Fixture1.client1().user)
        response = self.client.get(url)

        self.assertEqual(len(response.data), 2)
        self.assertEqual(response.data[1]['name'], 'Krane')
        self.assertEqual(response.data[1]['type'], PORTFOLIO_SET_TYPE_KRANE)
コード例 #30
0
ファイル: test_settings.py プロジェクト: fagan2888/Betasmartz
 def test_inactive_tickers_not_in_settings(self):
     """
     Make sure inactive tickers are not returned by the /api/v1/settings endpoint
     """
     url = '/api/v1/settings'
     self.bonds_ticker.state = Ticker.State.INACTIVE.value
     self.bonds_ticker.save()
     self.client.force_authenticate(user=Fixture1.client1().user)
     response = self.client.get(url)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     ticker_ids = [int(t['id']) for t in response.data['tickers']]
     self.assertTrue(self.bonds_ticker.id not in ticker_ids)