예제 #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'
        }])
예제 #2
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)
예제 #3
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'
            }
        ])
예제 #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'
            }
        ])
예제 #5
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'
            }])
예제 #6
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)