def setUp(self): super(TestGetChangedEntities, self).setUp() self.obj = Budget() self.account = Account() self.obj.be_accounts = [self.account] self.obj.clear_changed_entities() self.account2 = Account(id=self.account)
def testCE_simplechange(self): obj = Budget() account1 = Account() obj.be_accounts.append(account1) account2 = Account(id=account1.id, account_name='BLA') obj.be_accounts.changed = [] obj.be_accounts.modify(account2) self.assertEqual(obj.get_changed_entities(), {'be_accounts': [account2]})
def setUp(self): super(TestGetChangedEntities, self).setUp() self.obj = Budget() self.account = Account() self.obj.be_accounts = [self.account] self.obj.clear_changed_entities() self.account2 = Account(id=self.account) self.client = factory.create_client(budget_name='budgetname', nynabconnection=MockConnection(), sync=False)
def test_add_delete_account(self): account_type = AccountTypes.Checking account_name = KeyGenerator.generateuuid() budget = self.client.budget for account in budget.be_accounts: if account.account_name == account_name: return if len(budget.be_accounts) > 0: sortable_index = max(account.sortable_index for account in budget.be_accounts) else: sortable_index = 0 account = Account( account_type=account_type, account_name=account_name, sortable_index=sortable_index, ) self.client.add_account(account, balance=random.randint(-10, 10), balance_date=datetime.now()) self.reload() self.assertIn(account, self.client.budget.be_accounts) self.client.delete_account(account) self.reload() result = self.client.budget.be_transactions.get(account.id) self.assertTrue(result is None)
def setUp(self): super(TestUpdateChangedEntities, self).setUp() self.account = Account() self.client = nYnabClient_(budgetname='Mock Budget') self.client.budget.be_accounts = [self.account] self.account2 = self.account.copy() self.client.session.commit()
def testappend(self): obj = Budget() account = Account(None) obj.be_accounts.append(account) assert (len(obj.be_accounts) == 1) assert (list(obj.be_accounts)[-1] == account)
def migrate_main(): print('migrate YNAB4 to pynYNAB') """Migrate a YNAB4 budget transaction history to nYNAB, using pyynab""" parser = configargparse.getArgumentParser('pynYNAB') parser.description = inspect.getdoc(migrate_main) parser.add_argument('budget', metavar='BudgetPath', type=str, help='The budget .ynab4 directory') args = parser.parse_args() test_common_args(args) budget_base_name = os.path.basename(args.budget) budget_path = os.path.dirname(args.budget) budget_name = re.match(r"(?P<budget_name>.*)~[A-Z0-9]{8}\.ynab4", budget_base_name).groupdict().get('budget_name') if args.budgetname is not None: budget_name = args.budgetname thisynab = YNAB(budget_path, budget_name) client = clientfromargs(args, reset=True) for ynab4_account in thisynab.accounts: account = Account( name=ynab4_account.name, account_type=ynab4_account.type.value, on_budget=ynab4_account.on_budget, sortable_index=random.randint(-50000, 50000), ) mindate = min([ ynab4transaction.date for ynab4transaction in thisynab.transactions if ynab4transaction.account == ynab4_account ]) client.add_account(account, 0, mindate) for master_category in thisynab.master_categories: master_entity = MasterCategory(name=master_category.name, sortable_index=random.randint( -50000, 50000)) client.budget.be_master_categories.append(master_entity) for category in master_category.categories: entity = Subcategory(name=category.name, entities_master_category_id=master_entity.id, sortable_index=random.randint(-50000, 50000)) client.budget.be_subcategories.append(entity) client.sync() for ynab4_payee in thisynab.payees: payee = Payee(name=ynab4_payee.name) client.budget.be_payees.append(payee) client.sync() for ynab4transaction in thisynab.transactions: transaction = Transaction() pass
def setUp(self): self.account = Account() self.client = factory.create_client(budgetname='budgetname', nynabconnection=MockConnection(), sync=False) self.client.budget.be_accounts = [self.account] self.account2 = self.account.copy() self.client.session.commit()
def test_get_ce_add(obj, objclient): added_account = Account() obj.be_accounts.append(added_account) changed_entities = objclient.get_changed_entities() assert changed_entities == { 'be_accounts': { added_account.id: added_account } }
def util_add_account(client, account_name=None): if account_name is None: account_name = str(KeyGenerator.generateuuid()) account = Account(account_type=random.choice(list(AccountTypes)), account_name=account_name) client.add_account(account, balance=random.randint(-10, 10), balance_date=datetime.now()) return account
def testupdatechangedentities(self): obj = Budget() assert (obj.be_accounts.__class__ == ListofEntities) assert (obj.be_accounts.typeItems == Account) assert (len(obj.be_accounts) == 0) account = Account() changed_entities = dict(be_accounts=[account]) obj.update_from_changed_entities(changed_entities) assert (len(obj.be_accounts) == 1) assert (next(obj.be_accounts.__iter__()) == account)
def test_get_ce_replace(obj, objclient, account): added_account = Account() obj.be_accounts = [added_account] changed_entities = objclient.get_changed_entities() removed_account = account.copy() removed_account.is_tombstone = True assert changed_entities == { 'be_accounts': { added_account.id: added_account, removed_account.id: removed_account } }
def test_add_deleteaccount(live_client): account = Account(account_type=random.choice(list(AccountTypes)), account_name=KeyGenerator.generateuuid()) live_client.add_account(account, balance=random.randint(-10, 10), balance_date=datetime.now()) live_client = reload() assert account in live_client.budget.be_accounts live_client.delete_account(account) live_client = reload() assert account not in live_client.budget.be_accounts
def get_nubank_account(self): try: logging.info('Searching for Nubank account') return next(acc for acc in self.client.budget.be_accounts if acc.account_name == 'Nubank') except StopIteration: logging.info('Nubank account not found, creating a new one') account = Account() account.account_name = 'Nubank' self.client.budget.be_accounts.append(account) self.delta += 1 return account
def get_or_create_account(client, name): accounts = {a.account_name: a for a in client.budget.be_accounts if a.account_name == name} if name in accounts: return accounts[name] account = Account( account_type=AccountTypes.Checking, account_name=name ) client.add_account(account, balance=random.randint(-10, 10), balance_date=datetime.now()) return account
def get_account(self, account_name): try: logging.info('Searching for ' + account_name + ' account') return next(acc for acc in self.client.budget.be_accounts if acc.account_name == account_name) except StopIteration: logging.info(account_name + ' account not found, creating a new one') account = Account() account.account_name = account_name self.client.budget.be_accounts.append(account) self.delta += 1 return account
def util_get_empty_account_by_name_if_doesnt_exist(client, name): accounts = { a.account_name: a for a in client.budget.be_accounts if a.account_name == name } if name in accounts: account = accounts[name] client.delete_account(account) account = Account(account_type=AccountTypes.Checking, account_name=name) client.add_account(account, balance=random.randint(-10, 10), balance_date=datetime.now()) client.reload() return account
def testgetChangedEntities_add(self): added_account = Account() self.obj.be_accounts.append(added_account) changed_entities = self.obj.get_changed_entities() self.assertEqual(changed_entities, {'be_accounts': [added_account]})
def test_get_ce_add_delete(obj, objclient): added_account = Account() obj.be_accounts.append(added_account) obj.be_accounts.remove(added_account) changed_entities = objclient.get_changed_entities() assert changed_entities == {}
def test_copy(self): obj = Account() objc = obj.copy() self.assertEqual(obj.id, objc.id) self.assertEqual(obj.get_dict(), objc.get_dict())
def testappend(self): obj = Budget() account = Account() obj.be_accounts.append(account) self.assertEqual(len(obj.be_accounts), 1) self.assertEqual(list(obj.be_accounts)[-1], account)
def testupdateChangedEntities_add(self): new_account = Account() changed_entities = dict(be_accounts=[new_account]) self.client.budgetClient.update_from_changed_entities(changed_entities) self.assertEqual(len(self.client.budget.be_accounts), 2) self.assertIn(new_account, self.client.budget.be_accounts)
def test_append(): obj = Budget() account = Account() obj.be_accounts.append(account) assert len(obj.be_accounts) == 1 assert list(obj.be_accounts)[-1] == account
def test_copy(): obj = Account() objc = obj.copy() assert obj.id == objc.id assert obj.get_dict() == objc.get_dict()
def account(): return Account()
def testCE_simpledelete(self): obj = Budget() account = Account() obj.be_accounts.delete(account) self.assertEqual(obj.get_changed_entities(), {'be_accounts': [account]})