def setUp(self): self.gl_structure = GeneralLedgerStructure("NameA", description="DescriptionA") self.sales_acc = self.gl_structure._acci_sales_.create_account( "sales_default", "0000") self.cos_acc = self.gl_structure._acci_cos_.create_account( "cos_default", "0000") self.reva_acc = self.gl_structure["Other Income"].create_account( "RevA", number="011") self.expa_acc = self.gl_structure["Expense"].create_account( "ExpenseA", number="011") self.object = Entity("EntityA", gl_structure=self.gl_structure, description="DescriptionA") # Set up the needed objects self.comp1 = self.object.create_component("ComponentA1", description="ca1") basic_activity = BasicActivity("BasicActivityA", description="DescriptionA", dt_account="Bank", cr_account="Sales", amount=5000, start=datetime(2016, 2, 1), end=datetime(2017, 2, 1), interval=1) self.comp1.add_activity(basic_activity) self.clock = Clock("NameA", start_datetime=datetime(2016, 1, 1))
def test_prepare_to_run(self): """ Test that the component run's its activities' prepare_to_run methods. """ clock = Clock("NameA", start_datetime=datetime(2016, 1, 1)) self.object.prepare_to_run(clock, 18) # The activity's start and end period indexes should be changed. self.assertEqual( self.object.components[0].activities[0].start_period_ix, 2) self.assertEqual(self.object.components[0].activities[0].end_period_ix, 14)
def test__meet_execution_criteria(self): """ Test that the activity only meets the execution criteria when it's amount is greater than 0. """ clock = Clock("NameA", start_datetime=datetime(2016, 1, 1)) self.object.prepare_to_run(clock, 13) self.assertEqual(self.object._meet_execution_criteria(5), True) self.object.amount = 0 self.assertEqual(self.object._meet_execution_criteria(5), False)
def __init__(self, name, description=None, start_datetime=datetime.now(), period_duration=TimePeriod.year, period_count=1): self.clock = Clock( "Clock", start_datetime=get_date(start_datetime), timestep_period_duration=period_duration) self.period_count = period_count self.entities = [] super(TimeBasedModel, self).__init__(name, description=description)
def test_run(self): """ Test that the activity run method creates a transaction with an amount of 5000. """ structure = GeneralLedgerStructure("NameA", description="DescriptionA") gl = GeneralLedger("NameA", structure, description="DescriptionA") clock = Clock("NameA", start_datetime=datetime(2016, 1, 1)) clock.tick() clock.tick() self.object.prepare_to_run(clock, 20) self.object.run(clock, gl) self.assertEqual(len(gl.transactions), 1) self.assertEqual(gl.transactions[0].amount, 5000)
def test_run(self): """ Test that the component runs its activities. """ # Set up the general ledger so that an activity can create a # transaction. structure = GeneralLedgerStructure("NameA", description="DescriptionA") gl = GeneralLedger("NameA", structure, description="DescriptionA") # Prepare the component for a run. Tick the clock to the correct place # for the activity to create a transaction. clock = Clock("NameA", start_datetime=datetime(2016, 1, 1)) clock.tick() clock.tick() self.object.prepare_to_run(clock, 20) self.object.run(clock, gl) # If the activity has been run, then a transaction should have # been generated. self.assertEqual(len(gl.transactions), 1)
def setUp(self): self.gl_structure = GeneralLedgerStructure( "GL Structure", description="General Ledger Structure") self.gl_structure["Account Payable"].create_account( "Capital Loan", "0000") self.gl_structure["Expense"].create_account("Interest Expense", "0000") self.gl = GeneralLedger("GL", self.gl_structure, description="General Ledger") self.clock = Clock("NameA", start_datetime=datetime(2016, 2, 1)) self.object = BasicLoanActivity( "Capital Loan", bank_account="Bank/Default", loan_account="Account Payable/Capital Loan", interest_account="Expense/Interest Expense", amount=180000, interest_rate=0.15, start=datetime(2016, 2, 1), duration=36, interval=1, description="Loan for Capital")
def test_prepare_to_run(self): clock = Clock("NameA", start_datetime=datetime(2016, 1, 1)) self.object.prepare_to_run(clock, 18) self.assertEqual(self.object.start_period_ix, 2) self.assertEqual(self.object.end_period_ix, 14)
def test__meet_execution_criteria(self): clock = Clock("NameA", start_datetime=datetime(2016, 1, 1)) self.object.prepare_to_run(clock, 13) self.assertEqual(self.object._meet_execution_criteria(3), False) self.assertEqual(self.object._meet_execution_criteria(5), True) self.assertEqual(self.object._meet_execution_criteria(40), False)
def setUp(self): self.object = Clock("NameA", description="DescriptionA", start_datetime=datetime(2016, 2, 1), timestep_period_duration=TimePeriod.year, timestep_period_count=3)