def test_no_limit_applies(self): """ We can also ignore the limit """ jrn13 = yearend.YearEndJournal(start_next_year=datetime(2016, 1, 1), num_accounts=None) self.assertEqual(len(jrn13['journal']['postings']), 7, 'Wrong number of accounts')
def test_return_json(self): """ Return the journal as a json string """ jrn14 = yearend.YearEndJournal(start_next_year=self.start_next_year) jrn14s = jrn14.as_json() self.assertIn('inkopen', jrn14s, 'Inkopen not found') self.assertIn('1716', jrn14s, 'Balance not found')
def test_limit_accounts(self): """ We can limit the number of accounts processed """ jrn10 = yearend.YearEndJournal(start_next_year=datetime(2016, 1, 1), num_accounts=3) self.assertEqual(len(jrn10['journal']['postings']), 4, 'Wrong number of accounts')
def test_journal_has_function(self): """ The journal should have a function of "insert" """ jrn2 = yearend.YearEndJournal(start_next_year=self.start_next_year) self.assertIn('function', jrn2['journal'], 'Journal should have function') self.assertEqual(jrn2['journal']['function'], 'insert', "Invalid function: " + jrn2['journal']['function'])
def test_journal_has_posting(self): """ A journal in internal format is created """ jrn1 = yearend.YearEndJournal(start_next_year=self.start_next_year) self.assertIn('account', jrn1['journal']['postings'][0], 'No field account in first posting') self.assertIn(jrn1['journal']['postings'][0]['account'], {'inkopen', 'verkopen'}, "Wrong account selected")
def test_open_month_after_close(self): """ An open postmonth after close date don't matter """ pm2 = accmodel.Postmonths(postmonth=201609, monthstat='a') pm2.add() gledger.db.session.flush() jrn9 = yearend.YearEndJournal(start_next_year=datetime(2016, 1, 1)) self.assertTrue(jrn9)
def test_open_month_fails_year_end(self): """ An open postmonth makes year end fail """ pm1 = accmodel.Postmonths(postmonth=201509, monthstat='a') pm1.add() gledger.db.session.flush() with self.assertRaises(ValueError): jrn8 = yearend.YearEndJournal(start_next_year=datetime(2016, 1, 1))
def test_closing_after_more_than_1_year(self): """ Closing can not be done at more than a year from previous """ last_close = accmodel.CloseDates(closing_date=datetime(2014, 1, 1)) last_close.add() gledger.db.session.flush() with self.assertRaises(ValueError): jrn7 = yearend.YearEndJournal(start_next_year=datetime(2016, 1, 1))
def test_amount_profit(self): """ The amount of profit should balance profit/loss accounts """ jrn12 = yearend.YearEndJournal(start_next_year=self.start_next_year) for posting in jrn12['journal']['postings']: if posting['account'] == 'winst': winst_posted = posting['amount'] debcred = posting['debitcredit'] self.assertEqual(winst_posted, 3449, 'Incorrect profit posted')
def test_close_year_from_last(self): """ If we do not pass date, close one year from last """ last_close = accmodel.CloseDates(closing_date=datetime(2015, 1, 1)) last_close.add() gledger.db.session.flush() jrn4 = yearend.YearEndJournal() self.assertEqual(jrn4['journal']['postings'][0]['valuedate'], '2016-01-01', "Wrong value date determined")
def test_pass_date(self): """ If we pass a specific date, it should pick that date """ jrn3 = yearend.YearEndJournal(start_next_year=datetime(2016, 1, 1)) self.assertEqual(jrn3['journal']['postings'][0]['valuedate'], '2016-01-01', "Wrong valuedate in journal")
def test_journal_counter_post(self): """ The journal has a posting to a balance account """ jrn11 = yearend.YearEndJournal(start_next_year=self.start_next_year) self.assertIn('winst', [account['account'] for account \ in jrn11['journal']['postings']], 'No profit posting')
def test_close_in_future(self): """ A closing date can not be in the future """ new_closing = datetime.now() + relativedelta(days=1) with self.assertRaises(ValueError): jrn6 = yearend.YearEndJournal(start_next_year=new_closing)
def test_year_from_last_missing(self): """ We try to close year from last, but no last close in db """ with self.assertRaises(ValueError): jrn5 = yearend.YearEndJournal()