Beispiel #1
0
def test_linechart_data(example_ledger):
    with app.test_request_context():
        g.conversion = "units"
        data = example_ledger.charts.linechart(
            "Assets:Testing:MultipleCommodities")
        assert data == [
            {
                "date": datetime.date(2000, 1, 1),
                "balance": {
                    "USD": D("100")
                }
            },
            {
                "date": datetime.date(2000, 1, 2),
                "balance": {
                    "XYZ": D("1"),
                    "USD": D("50")
                },
            },
            {
                "date": datetime.date(2000, 1, 3),
                "balance": {
                    "USD": 0,
                    "ABC": D("1"),
                    "XYZ": D("1")
                },
            },
        ]
Beispiel #2
0
def test_scrape(setup_app):
    urls = URLQueue()
    current = urls.stack[0]

    @app.url_defaults
    def collect_urls(endpoint, values):
        if 'loop' in values:
            values.pop('loop')
            return
        urls.append(endpoint, values, current)

    test_app = app.test_client()

    while urls.stack:
        print(current)
        rv = test_app.get(current)
        assert rv.status_code in [200, 302]
        current = urls.pop()

    for url_values in urls.all:
        for filters in filter_combinations:
            values = url_values[1].copy()
            values.update(filters)

            with app.test_request_context(current):
                app.preprocess_request()
                url = url_for(url_values[0], **values)

            print(url)
            rv = test_app.get(url)
            assert rv.status_code in [200, 302]
Beispiel #3
0
def test_linechart_data(example_ledger):
    with app.test_request_context('/'):
        g.conversion = 'units'
        data = example_ledger.charts.linechart(
            'Assets:Testing:MultipleCommodities')
        assert data == [
            {
                'date': datetime.date(2000, 1, 1),
                'balance': {
                    'USD': D('100')
                }
            },
            {
                'date': datetime.date(2000, 1, 2),
                'balance': {
                    'XYZ': D('1'),
                    'USD': D('50')
                },
            },
            {
                'date': datetime.date(2000, 1, 3),
                'balance': {
                    'USD': 0,
                    'ABC': D('1'),
                    'XYZ': D('1')
                },
            },
        ]
Beispiel #4
0
def test_scrape(setup_app):
    urls = URLQueue()
    current = urls.stack[0]

    @app.url_defaults
    def collect_urls(endpoint, values):
        if 'loop' in values:
            values.pop('loop')
            return
        urls.append(endpoint, values, current)

    test_app = app.test_client()

    while urls.stack:
        print(current)
        rv = test_app.get(current)
        assert rv.status_code in [200, 302]
        current = urls.pop()

    for url_values in urls.all:
        for filters in filter_combinations:
            values = url_values[1].copy()
            values.update(filters)

            with app.test_request_context(current):
                app.preprocess_request()
                url = url_for(url_values[0], **values)

            print(url)
            rv = test_app.get(url)
            assert rv.status_code in [200, 302]
Beispiel #5
0
def test_net_worth(example_ledger):
    with app.test_request_context():
        app.preprocess_request()
        g.conversion = "USD"
        data = example_ledger.charts.net_worth(Interval.MONTH)
        assert data[-18]["date"] == datetime.date(2015, 1, 1)
        assert data[-18]["balance"]["USD"] == D("39125.34004")
        assert data[-1]["date"] == datetime.date(2016, 5, 10)
        assert data[-1]["balance"]["USD"] == D("102327.53144")
Beispiel #6
0
def test_hierarchy(example_ledger):
    with app.test_request_context('/'):
        app.preprocess_request()
        data = example_ledger.charts.hierarchy('Assets')
        assert data['balance_children'] == {
            'IRAUSD': D('7200.00'),
            'USD': D('94320.27840'),
            'VACHR': D('-82')
        }
        assert data['balance'] == {}
        # Assets:US:ETrade
        etrade = data['children'][0]['children'][2]
        assert etrade['children'][4]['balance'] == {'USD': D('4899.98')}
        assert etrade['balance_children'] == {'USD': D('23137.54')}
Beispiel #7
0
def test_hierarchy(example_ledger):
    with app.test_request_context('/'):
        app.preprocess_request()
        data = example_ledger.charts.hierarchy('Assets')
        assert data['balance_children'] == {
            'IRAUSD': D('7200.00'),
            'USD': D('94320.27840'),
            'VACHR': D('-82')
        }
        assert data['balance'] == {}
        # Assets:US:ETrade
        etrade = data['children'][0]['children'][2]
        assert etrade['children'][4]['balance'] == {'USD': D('4899.98')}
        assert etrade['balance_children'] == {'USD': D('23137.54')}
Beispiel #8
0
def test_hierarchy(example_ledger):
    with app.test_request_context("/"):
        app.preprocess_request()
        data = example_ledger.charts.hierarchy("Assets")
        assert data["balance_children"] == {
            "IRAUSD": D("7200.00"),
            "USD": D("94320.27840"),
            "VACHR": D("-82"),
        }
        assert data["balance"] == {}
        # Assets:US:ETrade
        etrade = data["children"][0]["children"][2]
        assert etrade["children"][4]["balance"] == {"USD": D("4899.98")}
        assert etrade["balance_children"] == {"USD": D("23137.54")}
Beispiel #9
0
 def append(self, endpoint, values, current):
     if endpoint in ['source', 'document', 'add_document'] or \
             'REPLACEME' in values.values():
         return
     real_endpoint = endpoint
     if 'report_name' in values:
         endpoint = values['report_name']
     value_keys = frozenset([key for key, value in values.items() if value])
     if value_keys not in self.seen_values[endpoint]:
         self.seen_values[endpoint].add(value_keys)
         with app.test_request_context(current):
             app.preprocess_request()
             url = url_for(real_endpoint, loop=True, **values)
             if url not in self.seen:
                 self.seen.add(url)
                 self.stack.append(url)
Beispiel #10
0
    def append(self, endpoint, values, current):
        if (endpoint in ['source', 'document', 'add_document'] or
                'REPLACEME' in values.values()):
            return
        real_endpoint = endpoint
        if 'report_name' in values:
            endpoint = values['report_name']
        filters = ['account', 'interval', 'payee', 'tag', 'time']
        value_keys = frozenset([key for key, value in values.items()
                                if value and key not in filters])

        if value_keys not in self.seen_values[endpoint]:
            self.seen_values[endpoint].add(value_keys)
            with app.test_request_context(current):
                app.preprocess_request()
                url = url_for(real_endpoint, loop=True, **values)
                self.all.append((real_endpoint, values))
                self.stack.append(url)
Beispiel #11
0
    def append(self, endpoint, values, current):
        if (endpoint in ['source', 'document', 'add_document']
                or 'REPLACEME' in values.values()):
            return
        real_endpoint = endpoint
        if 'report_name' in values:
            endpoint = values['report_name']
        filters = ['account', 'interval', 'payee', 'tag', 'time']
        value_keys = frozenset([
            key for key, value in values.items()
            if value and key not in filters
        ])

        if value_keys not in self.seen_values[endpoint]:
            self.seen_values[endpoint].add(value_keys)
            with app.test_request_context(current):
                app.preprocess_request()
                url = url_for(real_endpoint, loop=True, **values)
                self.all.append((real_endpoint, values))
                self.stack.append(url)
Beispiel #12
0
def test_interval_totals(small_example_ledger):
    with app.test_request_context(''):
        g.conversion = None
        data = small_example_ledger.charts.interval_totals(
            Interval.MONTH, 'Expenses')
        assert data == [{
            'date': datetime.date(2012, 11, 18),
            'balance': {
                'EUR': D('280.00')
            },
            'budgets': Counter({
                'EUR': D('31.42857142857142857142857145')
            })
        }, {
            'date': datetime.date(2012, 12, 1),
            'balance': {
                'EUR': D('80.00')
            },
            'budgets': Counter({
                'EUR': D('48.57142857142857142857142861')
            })
        }]
Beispiel #13
0
def test_interval_totals(small_example_ledger):
    with app.test_request_context(''):
        g.conversion = None
        data = small_example_ledger.charts.interval_totals(
            Interval.MONTH, 'Expenses')
        assert data == [{
            'date':
            datetime.date(2012, 11, 18),
            'balance': {
                'EUR': D('280.00')
            },
            'budgets':
            Counter({'EUR': D('31.42857142857142857142857145')})
        }, {
            'date':
            datetime.date(2012, 12, 1),
            'balance': {
                'EUR': D('80.00')
            },
            'budgets':
            Counter({'EUR': D('48.57142857142857142857142861')})
        }]
Beispiel #14
0
def test_interval_totals(small_example_ledger):
    with app.test_request_context(""):
        g.conversion = None
        data = small_example_ledger.charts.interval_totals(
            Interval.MONTH, "Expenses")
        assert data == [
            {
                "date": datetime.date(2012, 11, 18),
                "balance": {
                    "EUR": D("280.00")
                },
                "budgets": Counter({"EUR":
                                    D("31.42857142857142857142857145")}),
            },
            {
                "date": datetime.date(2012, 12, 1),
                "balance": {
                    "EUR": D("80.00")
                },
                "budgets": Counter({"EUR":
                                    D("48.57142857142857142857142861")}),
            },
        ]
Beispiel #15
0
def test_linechart_data(example_ledger):
    with app.test_request_context('/'):
        g.conversion = 'units'
        data = example_ledger.charts.linechart(
            'Assets:Testing:MultipleCommodities')
        assert data == [{
            'date': datetime.date(2000, 1, 1),
            'balance': {
                'USD': D('100')
            },
        }, {
            'date': datetime.date(2000, 1, 2),
            'balance': {
                'XYZ': D('1'),
                'USD': D('50')
            },
        }, {
            'date': datetime.date(2000, 1, 3),
            'balance': {
                'USD': 0,
                'ABC': D('1'),
                'XYZ': D('1')
            },
        }]