def run_test(self, payee_name): payee = Payee(name=payee_name) client = nYnabClientFactory().create_client(budget_name=u'budgetname', nynabconnection=MockConnection(), sync=False) client.budget.be_payees.append(payee) client.session.commit()
def client(account): client = nYnabClientFactory().create_client(budget_name='budgetname', connection=MockConnection(), sync=False) client.budget.be_accounts = [account] client.session.commit() client.budgetClient.clear_changed_entities() return client
def test_merge(self): connection = DummyConnection() connection.transactions = [Transaction(memo=str(i)) for i in range(51)] client = nYnabClientFactory().create_client(connection=connection, budget_name='Test', sync=False) client.sync() self.assertEqual(set(client.budget.be_transactions), set(connection.transactions))
def __new__(cls, *args, **kwargs): connection = kwargs.pop('nynabconnection', None) email = connection.email if hasattr(connection, 'email')\ else kwargs.pop('email', '') password = connection.password if hasattr(connection, 'password')\ else kwargs.pop('password', '') budget_name = kwargs.pop('budgetname', None) factory = nYnabClientFactory() return factory.create_client(email, password, budget_name, connection)
def __new__(cls, *args, **kwargs): connection = kwargs.pop('nynabconnection', None) class Args(object): budget_name = kwargs.pop('budgetname', None) email = connection.email if hasattr(connection, 'email') else kwargs.pop('email', '') password = connection.password if hasattr(connection, 'password') else kwargs.pop('password', '') nynabconnection = connection passed = Args() factory = nYnabClientFactory() return factory.create_client(passed)
def test_sync_mock(self): class MockConnection(object): user_id = '1' def dorequest(self, request_data, opname): with open(opname + '.json', 'r') as f: data = json.load(f) return data engine = create_engine('sqlite://', echo=True) client = nYnabClientFactory(engine=engine).create_client( budgetname='Test Budget', connection=MockConnection(), sync=True)
def __new__(cls, *args, **kwargs): connection = kwargs.pop('nynabconnection', None) class Args(object): budget_name = kwargs.pop('budgetname', None) email = connection.email if hasattr( connection, 'email') else kwargs.pop('email', '') password = connection.password if hasattr( connection, 'password') else kwargs.pop('password', '') nynabconnection = connection db_path = 'offline' passed = Args() if hasattr(passed, 'db_path'): logging.info('Creating client from server...') factory = nYnabClientFactory( engine=create_engine('sqlite:///{}/{}.db'.format( passed.db_path, settings.ynab_budget))) else: logging.info('Creating client from database...') factory = nYnabClientFactory( engine=create_engine('sqlite:///:memory:')) return factory.create_client(passed, sync=False)
def __init__(self, email, password, budget, ynab_connection=nYnabConnection, sync=True): connection = ynab_connection(email, password) connection.init_session() self.client = nYnabClientFactory().create_client( email=email, password=password, nynabconnection=connection, budgetname=budget, sync=sync) self.delta = 0
from pynYNAB.ClientFactory import nYnabClientFactory from .common_mock import MockConnection connection = MockConnection() factory = nYnabClientFactory('sqlite://') class MockConnection(object): def __init__(self, id): self.id = id def test_client_persist(): def get_cl(id): return factory.create_client(budget_name='Test Budget', connection=MockConnection(id), sync=False) cl1 = get_cl('12345') cl2 = get_cl('12345') assert cl1 == cl2 cl3 = get_cl('54321') assert cl1 != cl3
from pynYNAB.ClientFactory import nYnabClientFactory from pynYNAB.scripts.helpers import get_config_from_yaml config = get_config_from_yaml() engine_url = 'sqlite:////tmp/persist.db' factory1 = nYnabClientFactory(engine_url=engine_url) client1 = factory1.create_client(**config) factory2 = nYnabClientFactory(engine_url=engine_url) client2 = factory2.create_client(sync=False, **config) # client1 and client2 contain the same data assert client1.budget == client2.budget assert client1.catalog == client2.catalog
class MyEntity(Base, Entity): greatfield = Column(Integer, default=2) class CommonTest(unittest.TestCase): def setUp(self): engine = create_engine('sqlite:///:memory:') Base.metadata.create_all(engine) self.Session = sessionmaker(bind=engine) self.session = self.Session() factory = nYnabClientFactory() class TestGetChangedEntities(CommonTest): 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)
import logging from dotenv import load_dotenv, find_dotenv from pynYNAB.ClientFactory import nYnabClientFactory from pynYNAB.schema import Transaction from pynYNAB.scripts.__main__ import parser load_dotenv(find_dotenv()) print('test_sync') args = parser.parse_known_args()[0] LOG = logging.getLogger('pynYNAB.connection') LOG.setLevel(logging.DEBUG) client = nYnabClientFactory().create_client(args) client.sync()
be_monthly_subcategory_budgets=[], be_payee_rename_conditions=[], be_accounts=[], last_month='', first_month=''))) elif opname == 'syncCatalogData': d.update(dict(changed_entities=dict(ce_user_budgets=[], ce_user_settings=[], ce_budget_versions=[BudgetVersion(version_name='Test').get_apidict()], ce_users=[], ce_budgets=[]))) return d import time elapsed = [] for size in [10, 20, 40, 70, 100, 200, 400, 700,1000, 2000, 4000]: connection = DummyConnection() connection.transactions=[Transaction(memo=str(i)) for i in range(size)] client = nYnabClientFactory().create_client(connection=connection, budget_name='Test', sync=False) t = time.time() # do stuff client.sync() time_elapsed = time.time() - t elapsed.append(round(time_elapsed, 1)) assert (set(client.budget.be_transactions) == set(connection.transactions)) print('%i,%f' % (size, time_elapsed)) print(','.join(str(i) for i in elapsed))
def factory(): return nYnabClientFactory('sqlite://')