Esempio n. 1
0
    def test_roundtrip(self):
        args = parser.parse_known_args()[0]

        # 1. gets sync data from server
        # 2. tests that to_api(from_api(data)) is the same thing

        client = clientfromargs(args, sync=False)
        sync_data = client.catalogClient.get_sync_data_obj()
        budget_version_id = next(
            d['id']
            for d in sync_data['changed_entities']['ce_budget_versions']
            if d['version_name'] == args.budgetname)
        client.budget_version_id = budget_version_id

        for objclient in (client.budgetClient, client.catalogClient):
            sync_data = objclient.get_sync_data_obj()
            server_changed_entities = sync_data['changed_entities']

            for key in server_changed_entities:
                if key in objclient.obj.listfields:
                    if len(server_changed_entities[key]) == 0:
                        continue
                    obj_dict = server_changed_entities[key][0]
                    typ = objclient.obj.listfields[key]
                    obj_dict2 = typ.from_apidict(obj_dict).get_apidict()

                    diff = DictDiffer(obj_dict2, obj_dict)
                    for k in diff.changed():
                        AssertionError('changed {}: {}->{}'.format(
                            k, obj_dict[k], obj_dict2[k]))
                    for k in diff.removed():
                        AssertionError('removed {}: {}'.format(k, obj_dict[k]))
                    for k in diff.added():
                        AssertionError('added {}: {}'.format(k, obj_dict2[k]))
                elif key in objclient.obj.scalarfields:
                    obj_dict2 = objclient.obj.from_apidict(
                        server_changed_entities).get_apidict()
                    if server_changed_entities[key] != obj_dict2[key]:
                        AssertionError('changed {}: {}->{}'.format(
                            key, server_changed_entities[key], obj_dict2[key]))
Esempio n. 2
0
 def reload(self):
     # parser = configargparse.getArgumentParser('pynYNAB')
     args = parser.parse_known_args()[0]
     self.client = clientfromargs(args)
Esempio n. 3
0
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()
Esempio n. 4
0
 def setUp(self):
     args = parser.parse_known_args()[0]
     args.budgetname = test_budget_name
     self.client = clientfromargs(args, sync=False)
     self.client.catalogClient.sync()
     self.client.select_budget(test_budget_name)