|
|
|
@ -7,10 +7,10 @@ pytestmark = pytest.mark.django_db
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_statistics_list(app, user):
|
|
|
|
|
Agenda.objects.create(label='Foo bar')
|
|
|
|
|
Agenda.objects.create(label='Bar foo')
|
|
|
|
|
Category.objects.create(label='Category A')
|
|
|
|
|
Category.objects.create(label='Category B')
|
|
|
|
|
agenda = Agenda.objects.create(label='Foo bar')
|
|
|
|
|
agenda2 = Agenda.objects.create(label='Bar foo')
|
|
|
|
|
category = Category.objects.create(label='Category A')
|
|
|
|
|
category2 = Category.objects.create(label='Category B')
|
|
|
|
|
|
|
|
|
|
# unauthorized
|
|
|
|
|
app.get('/api/statistics/', status=401)
|
|
|
|
@ -20,7 +20,51 @@ def test_statistics_list(app, user):
|
|
|
|
|
category_filter = [x for x in resp.json['data'][0]['filters'] if x['id'] == 'category'][0]
|
|
|
|
|
assert len(category_filter['options']) == 3
|
|
|
|
|
agenda_filter = [x for x in resp.json['data'][0]['filters'] if x['id'] == 'agenda'][0]
|
|
|
|
|
assert len(agenda_filter['options']) == 3
|
|
|
|
|
assert agenda_filter['options'] == [
|
|
|
|
|
{'id': '_all', 'label': 'All'},
|
|
|
|
|
{'id': 'bar-foo', 'label': 'Bar foo'},
|
|
|
|
|
{'id': 'foo-bar', 'label': 'Foo bar'},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
agenda.category = category
|
|
|
|
|
agenda.save()
|
|
|
|
|
|
|
|
|
|
resp = app.get('/api/statistics/')
|
|
|
|
|
agenda_filter = [x for x in resp.json['data'][0]['filters'] if x['id'] == 'agenda'][0]
|
|
|
|
|
assert agenda_filter['options'] == [
|
|
|
|
|
[None, [{'id': '_all', 'label': 'All'}]],
|
|
|
|
|
[
|
|
|
|
|
'Category A',
|
|
|
|
|
[
|
|
|
|
|
{'id': 'category:category-a', 'label': 'All agendas of category Category A'},
|
|
|
|
|
{'id': 'foo-bar', 'label': 'Foo bar'},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
['Misc', [{'id': 'bar-foo', 'label': 'Bar foo'}]],
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
agenda2.category = category2
|
|
|
|
|
agenda2.save()
|
|
|
|
|
|
|
|
|
|
resp = app.get('/api/statistics/')
|
|
|
|
|
agenda_filter = [x for x in resp.json['data'][0]['filters'] if x['id'] == 'agenda'][0]
|
|
|
|
|
assert agenda_filter['options'] == [
|
|
|
|
|
[None, [{'id': '_all', 'label': 'All'}]],
|
|
|
|
|
[
|
|
|
|
|
'Category A',
|
|
|
|
|
[
|
|
|
|
|
{'id': 'category:category-a', 'label': 'All agendas of category Category A'},
|
|
|
|
|
{'id': 'foo-bar', 'label': 'Foo bar'},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'Category B',
|
|
|
|
|
[
|
|
|
|
|
{'id': 'category:category-b', 'label': 'All agendas of category Category B'},
|
|
|
|
|
{'id': 'bar-foo', 'label': 'Bar foo'},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_statistics_bookings(app, user, freezer):
|
|
|
|
@ -58,6 +102,11 @@ def test_statistics_bookings(app, user, freezer):
|
|
|
|
|
Booking.objects.create(event=event3)
|
|
|
|
|
|
|
|
|
|
# category filter
|
|
|
|
|
resp = app.get(url + '?agenda=category:category-a')
|
|
|
|
|
assert resp.json['data']['x_labels'] == ['2020-10-25']
|
|
|
|
|
assert resp.json['data']['series'] == [{'label': 'Bookings Count', 'data': [1]}]
|
|
|
|
|
|
|
|
|
|
# legacy, category filter
|
|
|
|
|
resp = app.get(url + '?category=category-a')
|
|
|
|
|
assert resp.json['data']['x_labels'] == ['2020-10-25']
|
|
|
|
|
assert resp.json['data']['series'] == [{'label': 'Bookings Count', 'data': [1]}]
|
|
|
|
|