def test_account_set_type(self): account_obj = account.Account("") account_obj.TYPE = "CHECKING" self.assertEqual(account_obj.TYPE, account.Type.CHECKING) account_obj2 = account.Account("") account_obj2.TYPE = 2 self.assertEqual(account_obj2.TYPE, account.Type.CREDIT)
def test_account_set_currency(self): account_obj = account.Account("") account_obj.CURRENCY = "USD" self.assertEqual(account_obj.CURRENCY, account.Currency.USD) account_obj2 = account.Account("") account_obj2.CURRENCY = 2 self.assertEqual(account_obj2.CURRENCY, account.Currency.EURO)
def test_db_modify_account_error(self): db_file = os.path.join(self.temp_dir, "simple.json") self.database = db.DB(db_file, create_new=False) account_obj = account.Account(self.SIMPLE_ACCOUNT) with self.assertRaises(db.DBLookupError): self.database.modify_account(account_obj)
def test_db_add_account_duplicate(self): db_file = os.path.join(self.temp_dir, "simple.json") self.database = db.DB(db_file, create_new=False) account_obj = account.Account(self.SIMPLE_ACCOUNT) with self.assertRaises(db.DBAccountAddError): self.database.add_account(account_obj)
def test_account_set_attr_extra_attr(self): account_obj = account.Account(self.SIMPLE_ACCOUNT) with self.assertRaises(account.AccountInvalidAttributeError): account_obj.RANDOM = 123 with self.assertRaises(account.AccountInvalidAttributeError): account_obj.SOSO = 123
def test_account_set_attr_error(self): account_obj = account.Account(self.SIMPLE_ACCOUNT) with self.assertRaises(account.AccountInvalidAttributeError): account_obj.ID = 123 with self.assertRaises(account.AccountInvalidAttributeError): account_obj.NAME = 123
def test_db_get_account_already_loaded_account_obj(self): db_file = os.path.join(self.temp_dir, "simple.json") self.database = db.DB(db_file, create_new=False) exsting_account = account.Account(self.SIMPLE_ACCOUNT) self.database.account_obj_list[exsting_account.ID] = exsting_account account_obj = self.database.get_account(account_id=1) self.assertEqual(account_obj, exsting_account) account_obj = self.database.get_account(account_name='Chase Reserve') self.assertEqual(account_obj, exsting_account)
def test_db_add_account_sanity(self): simple_account = { "NAME": "Chase Reserve", "TYPE": 1, "CURRENCY": 1, "RATE_TO": 1, "BALANCE": 100, "ACTIVE": False } db_file = os.path.join(self.temp_dir, "new_account.json") self.database = db.DB(db_file, create_new=True) account_obj = account.Account(simple_account) self.database.add_account(account_obj) self.database._close() self.database = db.DB(db_file, create_new=False) account_obj_from_db = self.database.get_account( account_name=account_obj.NAME) self.database._close() self.assertIsNotNone(account_obj_from_db) self.assertNotEqual(account_obj_from_db, account_obj) self.assertEqual(account_obj_from_db.NAME, account_obj.NAME)
def test_account_check_sanity_error(self): account_obj = account.Account("") self.assertFalse(account_obj.check_sanity())
def test_account_check_sanity_sanity(self): account_obj = account.Account(self.SIMPLE_ACCOUNT) self.assertTrue(account_obj.check_sanity())
def test_account_set_type_invalid_type(self): account_obj = account.Account("") with self.assertRaises(ValueError): account_obj.TYPE = {} self.assertFalse(hasattr(account_obj, "TYPE"))
def test_account_set_currency_invalid_type(self): account_obj = account.Account("") with self.assertRaises(ValueError): account_obj.CURRENCY = [] self.assertFalse(hasattr(account_obj, "CURRENCY"))
def test_account_set_attr_sanity(self): account_obj = account.Account(self.SIMPLE_ACCOUNT) account_obj.RATE_TO = 123 self.assertEqual(account_obj.RATE_TO, 123)
def test_account_init_sanity(self): account_obj = account.Account(self.SIMPLE_ACCOUNT) self.assertIsNotNone(account_obj) account_str = repr(account_obj) self.assertIsNotNone(account_str)