2032 |
2032 |
|
2033 |
2033 |
@pytest.mark.skipif(drf_version.startswith('3.4'), reason='no support for old django rest framework')
|
2034 |
2034 |
def test_api_statistics_list(app, admin):
|
|
2035 |
OU = get_ou_model()
|
2035 |
2036 |
headers = basic_authorization_header(admin)
|
2036 |
2037 |
resp = app.get('/api/statistics/', headers=headers)
|
2037 |
2038 |
assert len(resp.json['data']) == 6
|
... | ... | |
2051 |
2052 |
"required": True,
|
2052 |
2053 |
"default": "month",
|
2053 |
2054 |
},
|
2054 |
|
{
|
2055 |
|
'id': 'services_ou',
|
2056 |
|
'label': 'Services organizational unit',
|
2057 |
|
'options': [{'id': 'default', 'label': 'Default organizational unit'}],
|
2058 |
|
},
|
2059 |
|
{
|
2060 |
|
'id': 'users_ou',
|
2061 |
|
'label': 'Users organizational unit',
|
2062 |
|
'options': [{'id': 'default', 'label': 'Default organizational unit'}],
|
2063 |
|
},
|
2064 |
2055 |
{'id': 'service', 'label': 'Service', 'options': []},
|
2065 |
2056 |
],
|
2066 |
2057 |
}
|
... | ... | |
2086 |
2077 |
|
2087 |
2078 |
service = Service.objects.create(name='Service1', slug='service1', ou=get_default_ou())
|
2088 |
2079 |
service = Service.objects.create(name='Service2', slug='service2', ou=get_default_ou())
|
2089 |
|
login_stats['filters'][3]['options'].append({'id': 'service1 default', 'label': 'Service1'})
|
2090 |
|
login_stats['filters'][3]['options'].append({'id': 'service2 default', 'label': 'Service2'})
|
|
2080 |
login_stats['filters'][1]['options'].append({'id': 'service1 default', 'label': 'Service1'})
|
|
2081 |
login_stats['filters'][1]['options'].append({'id': 'service2 default', 'label': 'Service2'})
|
|
2082 |
|
|
2083 |
resp = app.get('/api/statistics/', headers=headers)
|
|
2084 |
assert login_stats in resp.json['data']
|
2091 |
2085 |
|
|
2086 |
# adding second ou doesn't change anything
|
|
2087 |
ou = OU.objects.create(name='Second OU', slug='second')
|
|
2088 |
resp = app.get('/api/statistics/', headers=headers)
|
|
2089 |
assert login_stats in resp.json['data']
|
|
2090 |
|
|
2091 |
# if there are services in two differents OUs, filter is shown
|
|
2092 |
service.ou = ou
|
|
2093 |
service.save()
|
|
2094 |
login_stats['filters'][1]['options'][1]['id'] = 'service2 second'
|
|
2095 |
login_stats['filters'].append(
|
|
2096 |
{
|
|
2097 |
'id': 'services_ou',
|
|
2098 |
'label': 'Services organizational unit',
|
|
2099 |
'options': [
|
|
2100 |
{'id': 'default', 'label': 'Default organizational unit'},
|
|
2101 |
{'id': 'second', 'label': 'Second OU'}
|
|
2102 |
],
|
|
2103 |
}
|
|
2104 |
)
|
|
2105 |
resp = app.get('/api/statistics/', headers=headers)
|
|
2106 |
assert login_stats in resp.json['data']
|
|
2107 |
|
|
2108 |
# same goes with users
|
|
2109 |
user = User.objects.create(username='john.doe', email='john.doe@example.com', ou=ou)
|
|
2110 |
login_stats['filters'].append(
|
|
2111 |
{
|
|
2112 |
'id': 'users_ou',
|
|
2113 |
'label': 'Users organizational unit',
|
|
2114 |
'options': [
|
|
2115 |
{'id': 'default', 'label': 'Default organizational unit'},
|
|
2116 |
{'id': 'second', 'label': 'Second OU'}
|
|
2117 |
],
|
|
2118 |
}
|
|
2119 |
)
|
2092 |
2120 |
resp = app.get('/api/statistics/', headers=headers)
|
2093 |
2121 |
assert login_stats in resp.json['data']
|
2094 |
2122 |
|
2095 |
|
-
|