journal: empty references qs should return no statistics (#49670)
This commit is contained in:
parent
2d803b4a91
commit
e2fa4ca689
|
@ -143,7 +143,7 @@ class EventTypeDefinition(metaclass=EventTypeDefinitionMeta):
|
|||
qs = qs.annotate(**{group_by_field: KeyTextTransform(group_by_field, 'data')})
|
||||
values.append(group_by_field)
|
||||
|
||||
if which_references:
|
||||
if which_references is not None:
|
||||
qs = qs.which_references(which_references)
|
||||
|
||||
if users_ou:
|
||||
|
|
|
@ -648,3 +648,18 @@ def test_statistics_deleted_service(db, freezer):
|
|||
stats = event_type_definition.get_service_statistics('month')
|
||||
stats['series'].sort(key=lambda x: x['label'])
|
||||
assert stats == {'x_labels': ['2020-02'], 'series': [{'label': 'None', 'data': [1]}]}
|
||||
|
||||
|
||||
def test_statistics_ou_with_no_service(db, freezer):
|
||||
user = User.objects.create(username='john.doe', email='john.doe@example.com')
|
||||
portal = Service.objects.create(name='portal', slug='portal', ou=get_default_ou())
|
||||
|
||||
method = {'how': 'password-on-https'}
|
||||
event_type = EventType.objects.get_for_name('user.login')
|
||||
event_type_definition = event_type.definition
|
||||
|
||||
event = Event.objects.create(type=event_type, references=[user, portal], user=user, data=method)
|
||||
|
||||
ou_with_no_service = OU.objects.create(name='Second OU')
|
||||
stats = event_type_definition.get_method_statistics('month', services_ou=ou_with_no_service)
|
||||
assert stats == {'x_labels': [], 'series': []}
|
||||
|
|
Loading…
Reference in New Issue