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 create_client(self, args=None, sync=True, **kwargs): from pynYNAB.schema.Client import nYnabClient_ if args is None: class Arg(object): pass args = Arg() for k, v in kwargs.items(): setattr(args, k, v) if hasattr(args, 'budgetname'): setattr(args, 'budget_name', args.budgetname) if hasattr(args, 'nynabconnection') and args.nynabconnection is not None: setattr(args, 'connection', args.nynabconnection) if not hasattr(args, 'budget_name') or args.budget_name is None: raise NoBudgetNameException try: if not hasattr(args, 'connection'): if not hasattr(args, 'email') or args.email is None: if not hasattr(args, 'password') or args.password is None: raise NoCredentialsException connection = nYnabConnection(args.email, args.password) connection.init_session() else: connection = args.connection client_id = connection.id def postprocessed_client(cl): cl.connection = connection cl.catalogClient = CatalogClient(cl) cl.budgetClient = BudgetClient(cl) return cl previous_client = self.session.query(nYnabClient_).get(client_id) if previous_client is not None: previous_client.session = self.session return postprocessed_client(previous_client) client = nYnabClient_(id=client_id, budget_name=args.budget_name) client.engine = self.engine client.session = self.session client.add_missing() client = postprocessed_client(client) self.session.add(client) client.session.commit() if sync: client.sync() return client except BudgetNotFound: LOG.error('No budget by the name %s found in nYNAB' % args.budget_name) raise
def create_client(self, email=None, password=None, budget_name=None, connection=None, sync=True): from pynYNAB.schema.Client import nYnabClient_ if budget_name is None: raise NoBudgetNameException try: if connection is None: if email is None and password is None: raise NoCredentialsException() connection = nYnabConnection(email, password) connection.init_session() client_id = connection.id def postprocessed_client(cl): cl.connection = connection cl.catalogClient = CatalogClient(cl) cl.budgetClient = BudgetClient(cl) return cl previous_client = self.session.query(nYnabClient_).get(client_id) if previous_client is not None: previous_client.session = self.session return postprocessed_client(previous_client) client = nYnabClient_(id=client_id, budget_name=budget_name) client.engine = self.engine client.session = self.session client.add_missing() client = postprocessed_client(client) self.session.add(client) client.session.commit() if sync: client.sync() return client except BudgetNotFound: LOG.error('No budget by the name %s found in nYNAB' % budget_name) raise
def TestWrongPush(self): client = nYnabClient_(budgetname='Test') client.budget.be_transactions.append(Transaction()) client.budget.be_transactions.append(Transaction()) self.assertRaises(WrongPushException, lambda: client.push(expected_delta=1))