def setUp(self): self.gl_structure = GeneralLedgerStructure( "NameA", description="DescriptionA") self.gl_structure["Sales"].create_account("Default", number="0000") self.gl = GeneralLedger( "NameA", self.gl_structure, description="DescriptionA") self.object = Component("ComponentA", self.gl, description="DescriptionA") # Set up the needed objects self.object.create_component("ComponentA1", description="ca1") self.object.create_component("ComponentA2", description="ca2") self.basic_activity = BasicActivity( "BasicActivityA", description="DescriptionA", dt_account="Bank/Default", cr_account="Sales/Default", amount=5000, start=datetime(2016, 2, 1), end=datetime(2017, 2, 1), interval=3) self.object["ComponentA1"].add_activity(self.basic_activity)
def setUp(self): self.gl_structure = GeneralLedgerStructure("NameA", description="DescriptionA") self.gl_structure["Sales"].create_account("Default", number="0000") self.gl = GeneralLedger("NameA", self.gl_structure, description="DescriptionA") self.object = Component("ComponentA", self.gl, description="DescriptionA") # Set up the needed objects self.object.create_component("ComponentA1", description="ca1") self.object.create_component("ComponentA2", description="ca2") self.basic_activity = BasicActivity("BasicActivityA", description="DescriptionA", dt_account="Bank/Default", cr_account="Sales/Default", amount=5000, start=datetime(2016, 2, 1), end=datetime(2017, 2, 1), interval=3) self.object["ComponentA1"].add_activity(self.basic_activity)
class ComponentUnitTester(unittest.TestCase): """ Tester for the auxi.modelling.business.structure.Component class. """ def setUp(self): self.gl_structure = GeneralLedgerStructure( "NameA", description="DescriptionA") self.gl_structure["Sales"].create_account("Default", number="0000") self.gl = GeneralLedger( "NameA", self.gl_structure, description="DescriptionA") self.object = Component("ComponentA", self.gl, description="DescriptionA") # Set up the needed objects self.object.create_component("ComponentA1", description="ca1") self.object.create_component("ComponentA2", description="ca2") self.basic_activity = BasicActivity( "BasicActivityA", description="DescriptionA", dt_account="Bank/Default", cr_account="Sales/Default", amount=5000, start=datetime(2016, 2, 1), end=datetime(2017, 2, 1), interval=3) self.object["ComponentA1"].add_activity(self.basic_activity) def test_constructor(self): self.assertEqual(self.object.name, "ComponentA") self.assertEqual(self.object.description, "DescriptionA") def test_set_parent_path(self): self.object.set_parent_path("/entityA") self.assertEqual(self.object.path, "/entityA/ComponentA") def test_set_name(self): """ Test wether the name changes when it is set, that the component's name changes and that the component's children's paths are updated correctly. """ self.object.set_parent_path("entityA") self.object.name = "NameAt" self.assertEqual(self.object.name, "NameAt") self.assertEqual(self.object.components[0].path, "entityA/NameAt/ComponentA1") self.assertEqual(self.object.components[1].path, "entityA/NameAt/ComponentA2") self.assertEqual(self.object.components[0].activities[0].path, "entityA/NameAt/ComponentA1/BasicActivityA") def test_create_component(self): new_comp = self.object.create_component("ComponentTestCreate", description="catc") self.assertEqual(new_comp.name, "ComponentTestCreate") self.assertEqual(new_comp.description, "catc") self.assertEqual(new_comp, self.object.components[2]) def test_remove_component(self): self.object.create_component("ComponentTestRemove", description="catr") self.object.remove_component("ComponentTestRemove") self.assertEqual(len(self.object.components), 2) def test_get_component_exists(self): self.assertEqual( self.object.get_component("ComponentA1"), self.object["ComponentA1"]) def test_get_component_not_exists(self): self.assertRaises(IndexError, self.object.get_component, "ComponentA3") def test_add_activity_valid_account_name(self): basic_activity2 = BasicActivity( "BasicActivityB", description="DescriptionB", dt_account="Bank/Default", cr_account="Sales/Default", amount=5000, start=datetime(2016, 2, 1), end=datetime(2017, 2, 1), interval=3) self.object["ComponentA2"].add_activity(basic_activity2) self.assertEqual(len(self.object["ComponentA2"].activities), 1) self.assertEqual( basic_activity2.path, "/ComponentA/ComponentA2/BasicActivityB") def test_add_activity_invalid_account_name(self): basic_activity2 = BasicActivity( "BasicActivityB", description="DescriptionB", dt_account="invalid_acc_name_a", cr_account="invalid_acc_name_b", amount=5000, start=datetime(2016, 2, 1), end=datetime(2017, 2, 1), interval=3) self.assertRaises( ValueError, self.object["ComponentA2"].add_activity, basic_activity2) def test_get_activity_exists(self): self.assertEqual( self.object["ComponentA1"].get_activity("BasicActivityA"), self.basic_activity) def test_get_activity_not_exists(self): self.assertRaises( IndexError, self.object["ComponentA1"].get_activity, "B") 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_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)
class ComponentUnitTester(unittest.TestCase): """ Tester for the auxi.modelling.business.structure.Component class. """ def setUp(self): self.gl_structure = GeneralLedgerStructure("NameA", description="DescriptionA") self.gl_structure["Sales"].create_account("Default", number="0000") self.gl = GeneralLedger("NameA", self.gl_structure, description="DescriptionA") self.object = Component("ComponentA", self.gl, description="DescriptionA") # Set up the needed objects self.object.create_component("ComponentA1", description="ca1") self.object.create_component("ComponentA2", description="ca2") self.basic_activity = BasicActivity("BasicActivityA", description="DescriptionA", dt_account="Bank/Default", cr_account="Sales/Default", amount=5000, start=datetime(2016, 2, 1), end=datetime(2017, 2, 1), interval=3) self.object["ComponentA1"].add_activity(self.basic_activity) def test_constructor(self): self.assertEqual(self.object.name, "ComponentA") self.assertEqual(self.object.description, "DescriptionA") def test_set_parent_path(self): self.object.set_parent_path("/entityA") self.assertEqual(self.object.path, "/entityA/ComponentA") def test_set_name(self): """ Test whether the name changes when it is set, that the component's name changes and that the component's children's paths are updated correctly. """ self.object.set_parent_path("entityA") self.object.name = "NameAt" self.assertEqual(self.object.name, "NameAt") self.assertEqual(self.object.components[0].path, "entityA/NameAt/ComponentA1") self.assertEqual(self.object.components[1].path, "entityA/NameAt/ComponentA2") self.assertEqual(self.object.components[0].activities[0].path, "entityA/NameAt/ComponentA1/BasicActivityA") def test_create_component(self): new_comp = self.object.create_component("ComponentTestCreate", description="catc") self.assertEqual(new_comp.name, "ComponentTestCreate") self.assertEqual(new_comp.description, "catc") self.assertEqual(new_comp, self.object.components[2]) def test_remove_component(self): self.object.create_component("ComponentTestRemove", description="catr") self.object.remove_component("ComponentTestRemove") self.assertEqual(len(self.object.components), 2) def test_get_component_exists(self): self.assertEqual(self.object.get_component("ComponentA1"), self.object["ComponentA1"]) def test_get_component_not_exists(self): self.assertRaises(IndexError, self.object.get_component, "ComponentA3") def test_add_activity_valid_account_name(self): basic_activity2 = BasicActivity("BasicActivityB", description="DescriptionB", dt_account="Bank/Default", cr_account="Sales/Default", amount=5000, start=datetime(2016, 2, 1), end=datetime(2017, 2, 1), interval=3) self.object["ComponentA2"].add_activity(basic_activity2) self.assertEqual(len(self.object["ComponentA2"].activities), 1) self.assertEqual(basic_activity2.path, "/ComponentA/ComponentA2/BasicActivityB") def test_add_activity_invalid_account_name(self): basic_activity2 = BasicActivity("BasicActivityB", description="DescriptionB", dt_account="invalid_acc_name_a", cr_account="invalid_acc_name_b", amount=5000, start=datetime(2016, 2, 1), end=datetime(2017, 2, 1), interval=3) self.assertRaises(ValueError, self.object["ComponentA2"].add_activity, basic_activity2) def test_get_activity_exists(self): self.assertEqual( self.object["ComponentA1"].get_activity("BasicActivityA"), self.basic_activity) def test_get_activity_not_exists(self): self.assertRaises(IndexError, self.object["ComponentA1"].get_activity, "B") 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_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)