Beispiel #1
0
    def test_get_list(self):
        TransactionFactory.create(date=datetime.date(2010, 10, 10),
                                  value=Decimal(-20),
                                  user=self.user,
                                  category=self.categories[0])

        resp = self.api_client.get(self.list_url,
                                   format='json',
                                   authentication=self.get_credentials())
        self.assertValidJSONResponse(resp)

        objects = self.deserialize(resp)['objects']

        self.assertEqual(len(objects), 2)

        self.assertEquals(objects, [{
            u'id': 1,
            u'resource_uri': u'/api/v1/restrictions/category/monthly/1',
            u'base': u'/api/v1/category/1',
            u'spent': u'-20.00',
            u'value': u'-100',
            u'month': u'2010-10-01'
        }, {
            u'id': 2,
            u'resource_uri': u'/api/v1/restrictions/category/monthly/2',
            u'base': u'/api/v1/category/2',
            u'spent': u'0',
            u'value': u'-200',
            u'month': u'2010-10-01'
        }])
Beispiel #2
0
    def test_get_list(self):

        TransactionFactory.create(date=datetime.date.today(), value=Decimal(10), user=self.user, category_id=1)

        resp = self.api_client.get(self.get_list_url(), format='json', authentication=self.get_credentials())
        self.assertValidJSONResponse(resp)

        self.assertEqual(len(self.deserialize(resp)['objects']), 2)

        self.assertEquals(self.deserialize(resp)['objects'], [
            {
                u'category': {u'group': u'category group 1',
                              u'id': 1,
                              u'is_negative': True,
                              u'name': u'category 1',
                              u'position': 1,
                              u'resource_uri': u'/api/v1/category/1'},
                u'id': 1,
                u'resource_uri': u'/api/v1/threshold/category/1',
                u'value': u'-100'
            },
            {
                u'category': {u'group': u'category group 1',
                              u'id': 2,
                              u'is_negative': True,
                              u'name': u'category 2',
                              u'position': 1,
                              u'resource_uri': u'/api/v1/category/2'},
                u'id': 2,
                u'resource_uri': u'/api/v1/threshold/category/2',
                u'value': u'-200'
            }
        ])
Beispiel #3
0
    def setUp(self):
        super(TransactionResourceTest, self).setUp()

        # Create a user.
        self.email = '*****@*****.**'
        self.password = '******'
        self.user = User.objects.create_user(self.email, self.password)

        TransactionFactory.create_batch(2,
                                        date=datetime.date(2010, 01, 03),
                                        user=self.user,
                                        category_id=1)

        another_user = UserFactory.create(email="*****@*****.**")
        TransactionFactory.create(date=datetime.date(2010, 01, 03),
                                  category_id=1,
                                  user=another_user)

        self.transaction = Transaction.objects.get(pk=1)

        self.post_data = {
            'date': '03/03/2010',
            'value': '40',
            'category': '/api/v1/category/2'
        }

        self.detail_url = '/api/v1/transaction/{0}'.format(self.transaction.id)
Beispiel #4
0
    def test_get_list(self):
        TransactionFactory.create(date=datetime.date(2010, 10, 10), value=Decimal(-20), user=self.user, category=self.categories[0])

        resp = self.api_client.get(self.list_url, format='json', authentication=self.get_credentials())
        self.assertValidJSONResponse(resp)

        objects = self.deserialize(resp)['objects']

        self.assertEqual(len(objects), 2)

        self.assertEquals(objects, [
            {
                u'id': 1,
                u'resource_uri': u'/api/v1/restrictions/category/monthly/1',
                u'base': u'/api/v1/category/1',
                u'spent': u'-20.00',
                u'value': u'-100',
                u'month': u'2010-10-01'
            },
            {
                u'id': 2,
                u'resource_uri': u'/api/v1/restrictions/category/monthly/2',
                u'base': u'/api/v1/category/2',
                u'spent': u'0',
                u'value': u'-200',
                u'month': u'2010-10-01'
            }
        ])
Beispiel #5
0
    def test_total_value(self, *args):
        split = SplitTransaction()

        t1 = TransactionFactory.build()
        t2 = TransactionFactory.build()
        t3 = TransactionFactory.build()

        split.transactions = [t1, t2, t3]

        self.assertEquals(split.get_total_value(), Decimal(30))
Beispiel #6
0
    def test_total_value(self, *args):
        split = SplitTransaction()

        t1 = TransactionFactory.build()
        t2 = TransactionFactory.build()
        t3 = TransactionFactory.build()

        split.transactions = [t1, t2, t3]

        self.assertEquals(split.get_total_value(), Decimal(30))
Beispiel #7
0
    def test_get_list_json(self):
        """
        Successful GET to a list endpoint.
        """

        split = SplitTransaction.objects.create(user=self.user, description="a split transaction")
        split.transactions = TransactionFactory.create_batch(3, user=self.user, category_id=1, date=datetime.date(2010, 10, 10), description="a installment")

        resp = self.api_client.get('/api/v1/split_transaction/', format='json', authentication=self.get_credentials())
        self.assertValidJSONResponse(resp)

        content = self.deserialize(resp)['objects']

        self.assertEquals(content,
                            [{u'id': 1,
                            u'installments': 3,
                            u'resource_uri': u'/api/v1/split_transaction/1',
                            u'total_value': u'30.00',
                            u'description': u'a split transaction',
                            u'transactions': [{u'category': {u'group': u'group',
                                                             u'id': 1,
                                                             u'is_negative': False,
                                                             u'name': u'cat1',
                                                             u'position': 1,
                                                             u'resource_uri': u'/api/v1/category/1'},
                                               u'date': u'2010-10-10',
                                               u'description': u'a installment',
                                               u'id': 1,
                                               u'installment_number': None,
                                               u'resource_uri': u'/api/v1/transaction/1',
                                               u'installment_of': u'/api/v1/split_transaction/1',
                                               u'value': u'10'},
                                              {u'category': {u'group': u'group',
                                                             u'id': 1,
                                                             u'is_negative': False,
                                                             u'name': u'cat1',
                                                             u'position': 1,
                                                             u'resource_uri': u'/api/v1/category/1'},
                                               u'date': u'2010-10-10',
                                               u'description': u'a installment',
                                               u'id': 2,
                                               u'installment_number': None,
                                               u'resource_uri': u'/api/v1/transaction/2',
                                               u'installment_of': u'/api/v1/split_transaction/1',
                                               u'value': u'10'},
                                              {u'category': {u'group': u'group',
                                                             u'id': 1,
                                                             u'is_negative': False,
                                                             u'name': u'cat1',
                                                             u'position': 1,
                                                             u'resource_uri': u'/api/v1/category/1'},
                                               u'date': u'2010-10-10',
                                               u'description': u'a installment',
                                               u'id': 3,
                                               u'installment_number': None,
                                               u'resource_uri': u'/api/v1/transaction/3',
                                               u'installment_of': u'/api/v1/split_transaction/1',
                                               u'value': u'10'}]}])
Beispiel #8
0
    def test_get_list(self):

        TransactionFactory.create(date=datetime.date.today(),
                                  value=Decimal(10),
                                  user=self.user,
                                  category_id=1)

        resp = self.api_client.get(self.get_list_url(),
                                   format='json',
                                   authentication=self.get_credentials())
        self.assertValidJSONResponse(resp)

        self.assertEqual(len(self.deserialize(resp)['objects']), 2)

        self.assertEquals(
            self.deserialize(resp)['objects'], [{
                u'category': {
                    u'group': u'category group 1',
                    u'id': 1,
                    u'is_negative': True,
                    u'name': u'category 1',
                    u'position': 1,
                    u'resource_uri': u'/api/v1/category/1'
                },
                u'id': 1,
                u'resource_uri': u'/api/v1/threshold/category/1',
                u'value': u'-100'
            }, {
                u'category': {
                    u'group': u'category group 1',
                    u'id': 2,
                    u'is_negative': True,
                    u'name': u'category 2',
                    u'position': 1,
                    u'resource_uri': u'/api/v1/category/2'
                },
                u'id': 2,
                u'resource_uri': u'/api/v1/threshold/category/2',
                u'value': u'-200'
            }])
Beispiel #9
0
    def setUp(self):
        super(TransactionResourceTest, self).setUp()

        # Create a user.
        self.email = '*****@*****.**'
        self.password = '******'
        self.user = User.objects.create_user(self.email, self.password)

        TransactionFactory.create_batch(2, date=datetime.date(2010, 01, 03), user=self.user, category_id=1)

        another_user = UserFactory.create(email="*****@*****.**")
        TransactionFactory.create(date=datetime.date(2010, 01, 03), category_id=1, user=another_user)

        self.transaction = Transaction.objects.get(pk=1)

        self.post_data = {
            'date': '03/03/2010',
            'value': '40',
            'category': '/api/v1/category/2'
        }

        self.detail_url = '/api/v1/transaction/{0}'.format(self.transaction.id)