예제 #1
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)
예제 #2
0
    def test_retirement_incomes(self):
        """
        Test listing and creating retirement incomes
        """

        plan = RetirementPlanFactory.create()
        client = plan.client

        # Create an income
        url = '/api/v1/clients/%s/retirement-incomes' % client.id
        self.client.force_authenticate(user=client.user)
        income_data = {
            'name': 'RetirementIncome1',
            'plan': plan.id,
            'begin_date': now().date(),
            'amount': 200,
            'growth': 1.0,
            'schedule': 'DAILY'
        }
        response = self.client.post(url, income_data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        income = response.data
        self.assertEqual(income['schedule'], 'DAILY')
        self.assertEqual(income['amount'], 200)
        self.assertEqual(income['growth'], 1.0)
        self.assertEqual(income['plan'], plan.id)

        # Update it
        url = '/api/v1/clients/%s/retirement-incomes/%s' % (client.id,
                                                            income['id'])
        income_data = {'schedule': 'WEEKLY'}
        response = self.client.put(url, income_data)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # Make sure it's in the list
        url = '/api/v1/clients/%s/retirement-incomes' % client.id
        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]['id'], income['id'])

        # And unprivileged users can't see it
        self.client.force_authenticate(user=Fixture1.client2().user)
        url = '/api/v1/clients/%s/retirement-incomes' % client.id
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 0)