Esempio n. 1
0
    def test_create_client_no_address(self):
        # We need an accepted invitation to be able to create a client
        usr = UserFactory.create()
        EmailInviteFactory.create(user=usr, status=EmailInvite.STATUS_ACCEPTED)

        url = reverse('api:v1:client-list')
        regional_data = {
            'ssn': '555-55-5555',
        }
        data = {
            "advisor_agreement": True,
            "betasmartz_agreement": True,
            "date_of_birth": date(2016, 9, 21),
            "employment_status": EMPLOYMENT_STATUS_EMMPLOYED,
            "gender": GENDER_MALE,
            "income": 1234,
            "politically_exposed": True,
            "phone_num": "+1-234-234-2342",
            'regional_data': regional_data,
        }
        self.client.force_authenticate(usr)
        response = self.client.post(url, data)
        # Check client created with default address.
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertTrue(response.data['residential_address'] is not None)
Esempio n. 2
0
    def test_advisor_invite_states_displayed(self):
        usr_accepted = UserFactory.create()
        invite_accepted = EmailInviteFactory.create(
            user=usr_accepted, status=EmailInvite.STATUS_ACCEPTED)
        self.assertEqual(invite_accepted.get_status_display(), 'Accepted')

        usr_completed = UserFactory.create()
        invite_completed = EmailInviteFactory.create(
            user=usr_completed, status=EmailInvite.STATUS_COMPLETE)
        self.assertEqual(invite_completed.get_status_display(), 'Complete')

        usr_created = UserFactory.create()
        invite_created = EmailInviteFactory.create(
            user=usr_created, status=EmailInvite.STATUS_CREATED)
        self.assertEqual(invite_created.get_status_display(), 'Created')

        usr_expired = UserFactory.create()
        invite_expired = EmailInviteFactory.create(
            user=usr_expired, status=EmailInvite.STATUS_EXPIRED)
        self.assertEqual(invite_expired.get_status_display(), 'Expired')

        usr_sent = UserFactory.create()
        invite_sent = EmailInviteFactory.create(user=usr_sent,
                                                status=EmailInvite.STATUS_SENT)
        self.assertEqual(invite_sent.get_status_display(), 'Sent')
Esempio n. 3
0
    def test_create_client_with_readonly_access(self):
        """
        Test readonly_access is set.
        """
        # We need an accepted invitation to be able to create a client
        usr = UserFactory.create()
        EmailInviteFactory.create(user=usr,
                                  status=EmailInvite.STATUS_ACCEPTED,
                                  access_level=CLIENT_FULL_ACCESS)

        url = reverse('api:v1:client-list')

        regional_data = {
            'ssn': '555-55-5555',
        }
        address = {
            "address": "123 My Street\nSome City",
            "post_code": "112233",
            "region": {
                "name": "New South Wales",
                "country": "AU",
                "code": "NSW",
            }
        }
        data = {
            "advisor_agreement": True,
            "betasmartz_agreement": True,
            "date_of_birth": date(2016, 9, 21),
            "employment_status": EMPLOYMENT_STATUS_EMMPLOYED,
            "gender": GENDER_MALE,
            "income": 1234,
            "politically_exposed": True,
            "phone_num": "+1-234-234-2342",
            "residential_address": address,
            "regional_data": regional_data
        }
        self.client.force_authenticate(usr)
        response = self.client.post(url, data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        client = Client.objects.get(id=response.data.get('id'))
        self.assertEqual(client.readonly_access, False)

        usr2 = UserFactory.create()
        EmailInviteFactory.create(user=usr2,
                                  status=EmailInvite.STATUS_ACCEPTED,
                                  access_level=CLIENT_READONLY_ACCESS)
        self.client.force_authenticate(usr2)
        response = self.client.post(url, data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        client = Client.objects.get(id=response.data.get('id'))
        self.assertEqual(client.readonly_access, True)
Esempio n. 4
0
    def test_create_client_with_ib_onboard(self):
        """
        Test ib_onboard is created.
        """
        # We need an accepted invitation to be able to create a client
        usr = UserFactory.create()
        EmailInviteFactory.create(user=usr, status=EmailInvite.STATUS_ACCEPTED)

        url = reverse('api:v1:client-list')
        regional_data = {
            'ssn': '555-55-5555',
            'politically_exposed': True,
        }
        address = {
            "address": "123 My Street\nSome City",
            "post_code": "112233",
            "region": {
                "name": "New South Wales",
                "country": "AU",
                "code": "NSW",
            }
        }
        ib_onboard = {
            "account_number": "U1234567",
            "employer_address": address,
            "tax_address": address,
        }
        data = {
            "advisor_agreement": True,
            "betasmartz_agreement": True,
            "date_of_birth": date(2016, 9, 21),
            "employment_status": EMPLOYMENT_STATUS_EMMPLOYED,
            "gender": GENDER_MALE,
            "income": 1234,
            "phone_num": "+1-234-234-2342",
            "residential_address": address,
            "regional_data": regional_data,
            "ib_onboard": ib_onboard
        }
        self.client.force_authenticate(usr)
        response = self.client.post(url, data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        client = Client.objects.get(id=response.data.get('id'))
        client_ib_onboard = client.ib_onboard
        self.assertEqual(client_ib_onboard.account_number,
                         ib_onboard['account_number'])
        self.assertEqual(client_ib_onboard.employer_address.address,
                         ib_onboard['employer_address']['address'])
        self.assertEqual(client_ib_onboard.employer_address.post_code,
                         ib_onboard['employer_address']['post_code'])
Esempio n. 5
0
    def setUp(self):
        # Mocked to speed up tests, no need run them every time
        PDFStatement.save_pdf = MagicMock()

        self.support_group = GroupFactory(name=GROUP_SUPPORT_STAFF)
        self.plan = RetirementPlanFactory.create()
        self.plan2 = RetirementPlanFactory.create(client=self.plan.client)
        self.plan3 = RetirementPlanFactory.create()
        # self.advice_url = reverse('api:v1:client-retirement-advice', args=[self.plan.client.id, self.plan.id])
        self.plan_url = '/api/v1/clients/{}/retirement-plans/{}'.format(
            self.plan.client.id, self.plan.id)
        self.advice_url = '/api/v1/clients/{}/retirement-plans/{}/advice-feed'.format(
            self.plan.client.id, self.plan.id)
        self.invite = EmailInviteFactory.create(
            user=self.plan.client.user, status=EmailInvite.STATUS_ACCEPTED)

        self.bonds_type = InvestmentType.Standard.BONDS.get()
        self.stocks_type = InvestmentType.Standard.STOCKS.get()
        self.bonds_asset_class = AssetClassFactory.create(
            investment_type=self.bonds_type)
        self.stocks_asset_class = AssetClassFactory.create(
            investment_type=self.stocks_type)
        self.portfolio_set = PortfolioSetFactory.create()
        self.portfolio_set.asset_classes.add(self.bonds_asset_class,
                                             self.stocks_asset_class)
Esempio n. 6
0
    def test_update_client_tax_filing_status(self):
        """


        """
        invite = EmailInviteFactory.create(status=EmailInvite.STATUS_ACCEPTED)
        url = reverse('api:v1:client-list')
        usr = UserFactory.create()
        EmailInviteFactory.create(user=usr, status=EmailInvite.STATUS_ACCEPTED)

        url = reverse('api:v1:client-list')
        regional_data = {
            'ssn': '555-55-5555',
            'politically_exposed': True,
            'tax_transcript': 'some.random.url',
            'tax_transcript_data': {
                "FILING STATUS": "test"
            },
        }
        data = {
            "advisor_agreement": True,
            "betasmartz_agreement": True,
            "date_of_birth": date(2016, 9, 21),
            "employment_status": EMPLOYMENT_STATUS_FULL_TIME,
            "gender": GENDER_MALE,
            "income": 1234,
            "phone_num": "+1-234-234-2342",
            "residential_address": {
                "address": "123 My Street\nSome City",
                "post_code": "112233",
                "region": {
                    "name": "New South Wales",
                    "country": "AU",
                    "code": "NSW",
                }
            },
            "user_id": 44,
            'regional_data': regional_data,
        }
        self.client.force_authenticate(usr)
        response = self.client.post(url, data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertNotEqual(usr.id, 44)
        self.assertEqual(response.data['user']['id'], usr.id)
        regional_data_load = response.data.get('regional_data')
        self.assertEqual(
            regional_data_load['tax_transcript_data']['FILING STATUS'], 'test')
Esempio n. 7
0
    def test_create_client_with_user(self):
        """
        Test user_id is ignored, as user must be logged in to create client, and the user will always be the logged in.
        """
        # We need an accepted invitation to be able to create a client
        usr = UserFactory.create()
        EmailInviteFactory.create(user=usr, status=EmailInvite.STATUS_ACCEPTED)

        url = reverse('api:v1:client-list')
        regional_data = {
            'ssn': '555-55-5555',
            'politically_exposed': True,
        }
        data = {
            "advisor_agreement": True,
            "betasmartz_agreement": True,
            "date_of_birth": date(2016, 9, 21),
            "employment_status": EMPLOYMENT_STATUS_FULL_TIME,
            "gender": GENDER_MALE,
            "income": 1234,
            "phone_num": "+1-234-234-2342",
            "residential_address": {
                "address": "123 My Street\nSome City",
                "post_code": "112233",
                "region": {
                    "name": "New South Wales",
                    "country": "AU",
                    "code": "NSW",
                }
            },
            "user_id": 44,
            'regional_data': regional_data,
        }
        self.client.force_authenticate(usr)
        response = self.client.post(url, data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertNotEqual(usr.id, 44)
        self.assertEqual(response.data['user']['id'], usr.id)
Esempio n. 8
0
    def test_create_client_no_regional_data(self):
        """
        regional_data is a required field, needs ssn and politically_exposed fields
        at a minimum
        """
        usr = UserFactory.create()
        EmailInviteFactory.create(user=usr, status=EmailInvite.STATUS_ACCEPTED)
        url = reverse('api:v1:client-list')
        address = {
            "address": "123 My Street\nSome City",
            "post_code": "112233",
            "region": {
                "name": "New South Wales",
                "country": "AU",
                "code": "NSW",
            }
        }
        data = {
            "advisor_agreement": True,
            "betasmartz_agreement": True,
            "date_of_birth": date(2016, 9, 21),
            "employment_status": EMPLOYMENT_STATUS_FULL_TIME,
            "gender": GENDER_MALE,
            "income": 1234,
            "phone_num": "+1-234-234-2342",
            "residential_address": address,
        }
        self.client.force_authenticate(usr)
        response = self.client.post(url, data)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

        regional_data = {
            'ssn': '555-55-5555',
            'politically_exposed': True,
        }
        data['regional_data'] = json.dumps(regional_data)
        response = self.client.post(url, data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Esempio n. 9
0
    def test_create_client_with_confirmed(self):
        """
        Test is_confirmed is ignored, as client cannot set is_confirmed
        """
        # We need an accepted invitation to be able to create a client
        usr = UserFactory.create()
        EmailInviteFactory.create(user=usr, status=EmailInvite.STATUS_ACCEPTED)

        url = reverse('api:v1:client-list')
        regional_data = {
            'ssn': '555-55-5555',
        }
        data = {
            "advisor_agreement": True,
            "betasmartz_agreement": True,
            "date_of_birth": date(2016, 9, 21),
            "employment_status": EMPLOYMENT_STATUS_EMMPLOYED,
            "gender": GENDER_MALE,
            "income": 1234,
            "phone_num": "+1-234-234-2342",
            "politically_exposed": True,
            "residential_address": {
                "address": "123 My Street\nSome City",
                "post_code": "112233",
                "region": {
                    "name": "New South Wales",
                    "country": "AU",
                    "code": "NSW",
                }
            },
            "is_confirmed": False,
            'regional_data': regional_data,
        }
        self.client.force_authenticate(usr)
        response = self.client.post(url, data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(response.data['is_confirmed'], True)
Esempio n. 10
0
    def test_get_risk_profile_groups(self):
        """
        Should be accessible by clients and onboarding users.
        """
        # Bring an invite key, get logged in as a new user
        PW = 'testpassword'
        invite = EmailInviteFactory.create(status=EmailInvite.STATUS_SENT)

        url = reverse('api:v1:client-user-register')
        data = {
            'first_name': invite.first_name,
            'last_name': invite.last_name,
            'invite_key': invite.invite_key,
            'password': PW,
            'question_one': 'what is the first answer?',
            'question_one_answer': 'answer one',
            'question_two': 'what is the second answer?',
            'question_two_answer': 'answer two',
        }

        # Accept an invitation and create a user
        response = self.client.post(url, data)
        lookup_invite = EmailInvite.objects.get(pk=invite.pk)
        invite_detail_url = reverse('api:v1:invite-detail',
                                    kwargs={'invite_key': invite.invite_key})
        me_url = reverse('api:v1:user-me')
        self.assertEqual(EmailInvite.STATUS_ACCEPTED, lookup_invite.status)

        # New user must be logged in and able to see invite data
        self.assertIn('sessionid', response.cookies)
        response = self.client.get(me_url)
        self.assertEqual(response.status_code,
                         status.HTTP_200_OK,
                         msg='/api/v1/me should be valid during invitation')

        # can retrieve risk-profile-groups
        url = '/api/v1/settings/risk-profile-groups'
        group = RiskProfileGroupFactory.create()
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data[0]['name'], group.name)
Esempio n. 11
0
    def test_create_client(self):
        # We need an accepted invitation to be able to create a client
        usr = UserFactory.create()
        EmailInviteFactory.create(user=usr, status=EmailInvite.STATUS_ACCEPTED)
        url = reverse('api:v1:client-list')
        address = {
            "address": "123 My Street\nSome City",
            "post_code": "112233",
            "region": {
                "name": "New South Wales",
                "country": "AU",
                "code": "NSW",
            }
        }
        regional_data = {
            'ssn': '555-55-5555',
            'politically_exposed': True,
        }
        data = {
            "advisor_agreement": True,
            "betasmartz_agreement": True,
            "date_of_birth": date(2016, 9, 21),
            "employment_status": EMPLOYMENT_STATUS_FULL_TIME,
            "gender": GENDER_MALE,
            "income": 1234,
            "phone_num": "+1-234-234-2342",
            "residential_address": address,
            "regional_data": json.dumps(regional_data)
        }
        self.client.force_authenticate(usr)
        response = self.client.post(url, data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        # Ensure it is created approved and accepted.
        self.assertEqual(response.data['is_confirmed'], True)
        self.assertEqual(response.data['is_accepted'], True)
        self.assertEqual(response.data['phone_num'], "+12342342342")
        self.assertEqual(response.data['residential_address']['address'],
                         address['address'])
        self.assertEqual(response.data['residential_address']['post_code'],
                         address['post_code'])
        self.assertEqual(response.data['betasmartz_agreement'], True)
        self.assertEqual(response.data['advisor_agreement'], True)
        regional_data_load = json.loads(response.data['regional_data'])
        self.assertEqual(regional_data_load['ssn'], regional_data['ssn'])
        self.assertEqual(regional_data_load['politically_exposed'],
                         regional_data['politically_exposed'])

        # check onboarding status is complete
        lookup_invite = EmailInvite.objects.get(user=usr)
        self.assertEqual(lookup_invite.status, EmailInvite.STATUS_COMPLETE)

        # can login with new client
        self.client = DjangoClient()  # django
        url = reverse('login')
        data = {
            'username': usr.email,
            'password': '******',
        }
        response = self.client.post(url, data)
        # redirect to application
        self.assertRedirects(response,
                             reverse('client:page', args=[
                                 usr.client.id,
                             ]))

        # can retrieve profile info ok
        url = reverse('api:v1:user-me')
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
Esempio n. 12
0
 def test_create_client_with_ib_onboard(self):
     """
     Test ib_onboard is created.
     """
     # We need an accepted invitation to be able to create a client
     usr = UserFactory.create()
     EmailInviteFactory.create(user=usr, status=EmailInvite.STATUS_ACCEPTED)
     url = reverse('api:v1:client-list')
     regional_data = {
         'ssn': '555-55-5555',
     }
     address = {
         "address": "123 My Street\nSome City",
         "post_code": "112233",
         "region": {
             "name": "New South Wales",
             "country": "AU",
             "code": "NSW",
         }
     }
     ib_onboard = {
         "account_number": "U1234567",
         "account_type": ACCOUNT_TYPE_PERSONAL,
         "asset_exp_0_knowledge": 1,
         "asset_exp_0_trds_per_yr": 1,
         "asset_exp_0_yrs": 1,
         "asset_exp_1_knowledge": 1,
         "asset_exp_1_trds_per_yr": 1,
         "asset_exp_1_yrs": 1,
         "country_of_birth": "VE",
         "date_of_birth": "1986-03-21",
         "doc_exec_login_ts": "87987987987",
         "doc_exec_ts": "87987987987",
         "signature": "Fred Bloggs",
         "fin_info_ann_net_inc": 4,
         "fin_info_liq_net_worth": 5,
         "fin_info_net_worth": 3,
         "fin_info_tot_assets": 7,
         "ib_employment_status": IB_EMPLOY_STAT_EMPLOYED,
         "identif_leg_citizenship": "CA",
         "identif_ssn=": "111-111-11111",
         "other_income_source": SOURCE_OF_FUNDS_TYPE_CONSULTING,
         "num_dependents": 47,
         "phone_type": "Home",
         "reg_status_broker_deal": "False",
         "reg_status_disp": "False",
         "reg_status_exch_memb": "False",
         "reg_status_investig": "False",
         "reg_status_stk_cont": 1,
         "salutation": "Mr.",
         "suffix": "I",
         "tax_resid_0_tin": "111-111-1234",
         "tax_resid_0_tin_type": "SSN",
         "employer_address": address,
         "tax_address": address,
     }
     data = {
         "advisor_agreement": True,
         "betasmartz_agreement": True,
         "civil_status": abstract.PersonalData.CivilStatus['SINGLE'].value,
         "date_of_birth": date(2016, 9, 21),
         "employer": "Good Company, Inc.",
         "gender": GENDER_MALE,
         "income": 123467,
         "industry_sector": "NAICS 11",
         "occupation": "11-0000",
         "other_income": 1234,
         "politically_exposed": True,
         "phone_num": "+1-234-234-2342",
         "residential_address": address,
         "regional_data": regional_data,
         "ib_onboard": ib_onboard,
         "user_id": usr.id
     }
     self.client.force_authenticate(usr)
     response = self.client.post(url, data)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
     client = Client.objects.get(id=response.data.get('id'))
     client_ib_onboard = client.ib_onboard
     client_ib_account = client.accounts[0].ib_account
     self.assertEqual(client_ib_onboard.account_number,
                      ib_onboard['account_number'])
     self.assertEqual(client_ib_onboard.employer_address.address,
                      ib_onboard['employer_address']['address'])
     self.assertEqual(client_ib_onboard.employer_address.post_code,
                      ib_onboard['employer_address']['post_code'])
     self.assertEqual(client_ib_account.ib_account, 'U1234567')