Beispiel #1
0
    def test_calculate_three_months_and_day(self):
        date_start=datetime.datetime(2010, 01, 01)
        date_end=datetime.datetime(2010, 03, 03)

        calc = BalanceQuery(date_start, date_end, day=10)

        result = calc.calculate()

        self.assertEquals(result, [
            {
                'period': '2010-01',
                'renevues': Decimal(150),
                'expenses': Decimal(-300)
            },
            {
                'period': '2010-02',
                'renevues': Decimal(160),
                'expenses': Decimal(-360)
            },
            {
                'period': '2010-03',
                'renevues': Decimal(200),
                'expenses': Decimal(-150)
            }
        ])
Beispiel #2
0
    def test_calculate_simple(self):
        date_start = datetime.datetime(2010, 1, 1)
        date_end = datetime.datetime(2010, 1, 1)

        calc = BalanceQuery(date_start=date_start, date_end=date_end)

        result = calc.calculate()

        self.assertEquals(result, [{
            'period': '2010-01',
            'renevues': Decimal(450),
            'expenses': Decimal(-300)
        }])
Beispiel #3
0
    def test_calculate_simple(self):
        date_start = datetime.datetime(2010, 1, 1)
        date_end = datetime.datetime(2010, 1, 1)

        calc = BalanceQuery(date_start=date_start, date_end=date_end)

        result = calc.calculate()

        self.assertEquals(result, [
            {
                'period': '2010-01',
                'renevues': Decimal(450),
                'expenses': Decimal(-300)
            }
        ])
Beispiel #4
0
    def get_list(self, request, **kwargs):
        try:
            date_start = request.GET.get('date_start')
            date_start = datetime.datetime.strptime(date_start, '%Y-%m-%d')
        except TypeError:
            raise BadRequest(_("The 'date_start' parameter is required."))
        except ValueError:
            raise BadRequest(
                _("The 'date_start' parameter has an invalid format. Must be on YYYY-MM-DD format."
                  ))

        try:
            date_end = request.GET.get('date_end')
            date_end = datetime.datetime.strptime(date_end, '%Y-%m-%d')
        except TypeError:
            raise BadRequest(_("The 'date_end' parameter is required."))
        except ValueError:
            raise BadRequest(
                _("The 'date_end' parameter has an invalid format. Must be on YYYY-MM-DD format."
                  ))

        try:
            day = int(request.GET.get('day'))
        except ValueError:
            raise BadRequest(_("The `day` parameter must be an integer."))
        except TypeError:
            day = None

        balance = BalanceQuery(date_start=date_start,
                               date_end=date_end,
                               day=day).calculate(user=request.user)

        return self.create_response(request, list(balance))
Beispiel #5
0
    def test_no_data(self):
        date_start = datetime.datetime(2010, 04, 01)
        date_end = datetime.datetime(2010, 05, 03)

        calc = BalanceQuery(date_start, date_end)

        result = calc.calculate()

        self.assertEquals(result, [{
            'period': '2010-04',
            'renevues': Decimal(0),
            'expenses': Decimal(0)
        }, {
            'period': '2010-05',
            'renevues': Decimal(0),
            'expenses': Decimal(0)
        }])
Beispiel #6
0
    def test_no_data(self):
        date_start=datetime.datetime(2010, 04, 01)
        date_end=datetime.datetime(2010, 05, 03)

        calc = BalanceQuery(date_start, date_end)

        result = calc.calculate()

        self.assertEquals(result, [
            {
                'period': '2010-04',
                'renevues': Decimal(0),
                'expenses': Decimal(0)
            },
            {
                'period': '2010-05',
                'renevues': Decimal(0),
                'expenses': Decimal(0)
            }
        ])
Beispiel #7
0
    def test_calculate_three_months_and_day(self):
        date_start = datetime.datetime(2010, 01, 01)
        date_end = datetime.datetime(2010, 03, 03)

        calc = BalanceQuery(date_start, date_end, day=10)

        result = calc.calculate()

        self.assertEquals(result, [{
            'period': '2010-01',
            'renevues': Decimal(150),
            'expenses': Decimal(-300)
        }, {
            'period': '2010-02',
            'renevues': Decimal(160),
            'expenses': Decimal(-360)
        }, {
            'period': '2010-03',
            'renevues': Decimal(200),
            'expenses': Decimal(-150)
        }])