def on_get(self, req, resp): '''Handles get requests to /api/v1/stats''' stats = { 'model': Aggregate.get_most_popular('model', 90), 'country': Aggregate.get_most_popular("country", 90), 'total': Aggregate.get_count(90) } resp.body = json.dumps(stats)
def test_get(client): create_statistics() expected = { 'model': Aggregate.get_most_popular('model', 90), 'country': Aggregate.get_most_popular('country', 90), 'total': Aggregate.get_count(90) } result = client.simulate_get('/api/v1/stats') assert result.status_code == 200 assert result.json == expected Statistic.objects().delete() Aggregate.objects().delete()
def on_get(self, req, resp): '''Render the main page''' stats = { "model": Aggregate.get_most_popular('model', 90), "country": Aggregate.get_most_popular("country", 90), "total": Aggregate.get_count(90) } template = load_template('index.html').render( stats=stats, columns=["model", "country"], date=datetime.utcnow().strftime("%Y-%m-%d %H:%M")) resp.content_type = 'text/html' resp.body = template