def test_should_return_none_when_date_is_invalid(self): response = self.app.get('/api/v1/reports/balance?account=%sstart=2012-01-32&end=2012-03-01' % self.account.id) self.assertEqual(500, response.status_code) data = helper.from_json(response.data) self.assertEqual(0, data['total']) self.assertEqual(1, len(data['messages']))
def test_calculate_total_amount_on_specific_date(self): request_data = '''{ "date": "2012-12-24", "account": %s, "transactions": [{ "transaction_date": "2012-12-01", "description": "Jenkins conference Sao Paulo, Brazil", "amount": "-300.0" }, { "transaction_date": "2012-12-31", "description": "Reveillon party", "amount": "-200.0" }] }''' % self.account.id response = self.app.post('/api/v1/calculator/calculate', data=request_data) self.assertEqual(200, response.status_code) data = helper.from_json(response.data) self.assertEqual(1, data.get('total')) fields = data.get('fields') self.assertEqual(-249.9, fields.get('balance')) self.assertEqual(2000.0, fields.get('income')) self.assertEqual(-800.0, fields.get('expense')) self.assertEqual(-300.0, fields.get('transactions')) self.assertEqual(650.1, fields.get('amount'))
def test_should_return_none_when_no_date(self): response = self.app.get('/api/v1/reports/balance?account=%s' % self.account.id) self.assertEqual(500, response.status_code) data = helper.from_json(response.data) self.assertEqual(0, data['total']) self.assertEqual(1, len(data['messages']))
def test_total_amount_for_one_month_by_account(self): response = self.app.get('/api/v1/reports/balance?account=%s&start=2012-01-01&end=2012-01-30' % self.account.id) data = helper.from_json(response.data) self.assertEqual(1, data['total']) fields = data['fields'] self.assertEqual('1/2012', fields[0].get('date')) self.assertEqual(-25.0, fields[0].get('balance'))
def test_total_amount_for_one_month_by_account(self): response = self.app.get( '/api/v1/reports/balance?account=%s&start=2012-01-01&end=2012-01-30' % self.account.id) data = helper.from_json(response.data) self.assertEqual(1, data['total']) fields = data['fields'] self.assertEqual('1/2012', fields[0].get('date')) self.assertEqual(-25.0, fields[0].get('balance'))
def test_total_amount_for_all_months_by_account(self): response = self.app.get('/api/v1/reports/balance?account=%s&start=2011-05-01&end=2012-11-30' % self.account.id) data = helper.from_json(response.data) self.assertEqual(3, data['total']) fields = data['fields'] self.assertEqual('5/2011', fields[0].get('date')) self.assertEqual(-99.9, fields[0].get('balance')) self.assertEqual('1/2012', fields[1].get('date')) self.assertEqual(-25.0, fields[1].get('balance')) self.assertEqual('10/2012', fields[2].get('date')) self.assertEqual(-400.0, fields[2].get('balance'))
def test_total_amount_for_all_months_by_account(self): response = self.app.get( '/api/v1/reports/balance?account=%s&start=2011-05-01&end=2012-11-30' % self.account.id) data = helper.from_json(response.data) self.assertEqual(3, data['total']) fields = data['fields'] self.assertEqual('5/2011', fields[0].get('date')) self.assertEqual(-99.9, fields[0].get('balance')) self.assertEqual('1/2012', fields[1].get('date')) self.assertEqual(-25.0, fields[1].get('balance')) self.assertEqual('10/2012', fields[2].get('date')) self.assertEqual(-400.0, fields[2].get('balance'))
def test_calculate_if_date_is_older(self): request_data = '''{ "date": "2010-01-01", "account": %s, "transactions": [{ "transaction_date": "2012-12-01", "description": "Jenkins conference Sao Paulo, Brazil", "amount": "-300.0" }] }''' % self.account.id response = self.app.post('/api/v1/calculator/calculate', data=request_data) self.assertEqual(200, response.status_code) data = helper.from_json(response.data) self.assertEqual(1, data.get('total')) fields = data.get('fields') self.assertEqual(0, fields.get('balance')) self.assertEqual(0, fields.get('income')) self.assertEqual(0, fields.get('expense')) self.assertEqual(0, fields.get('transactions')) self.assertEqual(0, fields.get('amount'))