示例#1
0
 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)
示例#2
0
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()
示例#3
0
 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
示例#4
0
def test_popular_stats(client):
    create_statistics()
    popular = Aggregate.get_most_popular('model', 90)
    assert(len(popular) == 5)
    Statistic.objects().delete()
    Aggregate.objects().delete()