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]
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")
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')}
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")}
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)
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)
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)