364 |
364 |
}
|
365 |
365 |
],
|
366 |
366 |
},
|
|
367 |
{
|
|
368 |
'url': 'https://authentic.example.com/api/statistics/filter-multiple/',
|
|
369 |
'name': 'Filter on multiple values',
|
|
370 |
'id': 'filter-multiple',
|
|
371 |
"filters": [
|
|
372 |
{
|
|
373 |
"id": "color",
|
|
374 |
"label": "Color",
|
|
375 |
"options": [
|
|
376 |
{"id": "red", "label": "Red"},
|
|
377 |
{"id": "green", "label": "Green"},
|
|
378 |
{"id": "blue", "label": "Blue"},
|
|
379 |
],
|
|
380 |
"multiple": True,
|
|
381 |
}
|
|
382 |
],
|
|
383 |
},
|
367 |
384 |
]
|
368 |
385 |
}
|
369 |
386 |
|
... | ... | |
419 |
436 |
},
|
420 |
437 |
}
|
421 |
438 |
return {'content': json.dumps(response), 'request': request, 'status_code': 200}
|
|
439 |
if url.path == '/api/statistics/filter-multiple/':
|
|
440 |
response = {
|
|
441 |
'data': {
|
|
442 |
'series': [
|
|
443 |
{'data': [None, 1], 'label': 'Red / Green'},
|
|
444 |
{'data': [1, 4], 'label': 'Red / Blue'},
|
|
445 |
],
|
|
446 |
'x_labels': ['2020-12-30', '2020-12-31'],
|
|
447 |
},
|
|
448 |
}
|
|
449 |
return {'content': json.dumps(response), 'request': request, 'status_code': 200}
|
422 |
450 |
|
423 |
451 |
|
424 |
452 |
@pytest.fixture
|
... | ... | |
1138 |
1166 |
statistics_field = resp.form[field_prefix + 'statistic']
|
1139 |
1167 |
assert len(statistics_field.options) == len(STATISTICS_LIST['data']) + 1
|
1140 |
1168 |
assert statistics_field.value == str(cell.statistic.pk)
|
1141 |
|
assert statistics_field.options[4][2] == 'Connection: One serie stat'
|
|
1169 |
selected_options = [option for option in statistics_field.options if option[1] is True]
|
|
1170 |
assert len(selected_options) == 1
|
|
1171 |
assert selected_options[0][2] == 'Connection: One serie stat'
|
1142 |
1172 |
|
1143 |
1173 |
time_interval_field = resp.form[field_prefix + 'time_interval']
|
1144 |
1174 |
assert time_interval_field.pos == statistics_field.pos + 1
|
... | ... | |
1203 |
1233 |
assert cell.filter_params == {}
|
1204 |
1234 |
assert cell.time_range == ''
|
1205 |
1235 |
|
|
1236 |
filter_multiple_stat = Statistic.objects.get(slug='filter-multiple')
|
|
1237 |
resp.form[field_prefix + 'statistic'] = filter_multiple_stat.pk
|
|
1238 |
resp = resp.form.submit().follow()
|
|
1239 |
resp.form[field_prefix + 'color'].select_multiple(texts=['Blue', 'Green'])
|
|
1240 |
resp = resp.form.submit().follow()
|
|
1241 |
assert resp.form[field_prefix + 'color'].value == ['green', 'blue']
|
|
1242 |
cell.refresh_from_db()
|
|
1243 |
assert cell.filter_params == {'color': ['green', 'blue']}
|
|
1244 |
|
|
1245 |
resp.form[field_prefix + 'color'].select_multiple(texts=[])
|
|
1246 |
resp = resp.form.submit().follow()
|
|
1247 |
assert resp.form[field_prefix + 'color'].value == None
|
|
1248 |
cell.refresh_from_db()
|
|
1249 |
assert cell.filter_params == {}
|
|
1250 |
|
1206 |
1251 |
|
1207 |
1252 |
@with_httmock(new_api_mock)
|
1208 |
1253 |
@pytest.mark.freeze_time('2021-10-06')
|
... | ... | |
1429 |
1474 |
assert 'time_interval=' not in request.url
|
1430 |
1475 |
assert 'ou=' not in request.url
|
1431 |
1476 |
|
1432 |
|
cell.filter_params = {'time_interval': 'month', 'ou': 'default'}
|
|
1477 |
cell.filter_params = {'time_interval': 'month', 'ou': 'default', 'color': ['green', 'blue']}
|
1433 |
1478 |
cell.save()
|
1434 |
1479 |
cell.get_chart()
|
1435 |
1480 |
request = new_api_mock.call['requests'][1]
|
1436 |
1481 |
assert 'time_interval=month' in request.url
|
1437 |
1482 |
assert 'ou=default' in request.url
|
|
1483 |
assert 'color=green&color=blue' in request.url
|
1438 |
1484 |
|
1439 |
1485 |
freezer.move_to(date)
|
1440 |
1486 |
cell.time_range = 'previous-year'
|
1441 |
|
-
|