See #192: replaced old stats endpoint with nodeinfo
This commit is contained in:
parent
e31bed050e
commit
b4ad7a4a71
7 changed files with 239 additions and 15 deletions
107
api/tests/instance/test_nodeinfo.py
Normal file
107
api/tests/instance/test_nodeinfo.py
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
from django.urls import reverse
|
||||
|
||||
import funkwhale_api
|
||||
|
||||
from funkwhale_api.instance import nodeinfo
|
||||
|
||||
|
||||
def test_nodeinfo_dump(preferences, mocker):
|
||||
preferences['instance__nodeinfo_stats_enabled'] = True
|
||||
stats = {
|
||||
'users': 1,
|
||||
'tracks': 2,
|
||||
'albums': 3,
|
||||
'artists': 4,
|
||||
'track_favorites': 5,
|
||||
'music_duration': 6,
|
||||
'listenings': 7,
|
||||
}
|
||||
mocker.patch('funkwhale_api.instance.stats.get', return_value=stats)
|
||||
|
||||
expected = {
|
||||
'version': '2.0',
|
||||
'software': {
|
||||
'name': 'funkwhale',
|
||||
'version': funkwhale_api.__version__
|
||||
},
|
||||
'protocols': ['activitypub'],
|
||||
'services': {
|
||||
'inbound': [],
|
||||
'outbound': []
|
||||
},
|
||||
'openRegistrations': preferences['users__registration_enabled'],
|
||||
'usage': {
|
||||
'users': {
|
||||
'total': stats['users'],
|
||||
},
|
||||
'localPosts': 0,
|
||||
'localComments': 0,
|
||||
},
|
||||
'metadata': {
|
||||
'shortDescription': preferences['instance__short_description'],
|
||||
'longDescription': preferences['instance__long_description'],
|
||||
'name': preferences['instance__name'],
|
||||
'library': {
|
||||
'federationEnabled': preferences['federation__enabled'],
|
||||
'federationNeedsApproval': preferences['federation__music_needs_approval'],
|
||||
'tracks': {
|
||||
'total': stats['tracks'],
|
||||
},
|
||||
'artists': {
|
||||
'total': stats['artists'],
|
||||
},
|
||||
'albums': {
|
||||
'total': stats['albums'],
|
||||
},
|
||||
'music': {
|
||||
'hours': stats['music_duration']
|
||||
},
|
||||
},
|
||||
'usage': {
|
||||
'favorites': {
|
||||
'tracks': {
|
||||
'total': stats['track_favorites'],
|
||||
}
|
||||
},
|
||||
'listenings': {
|
||||
'total': stats['listenings']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assert nodeinfo.get() == expected
|
||||
|
||||
|
||||
def test_nodeinfo_dump_stats_disabled(preferences, mocker):
|
||||
preferences['instance__nodeinfo_stats_enabled'] = False
|
||||
|
||||
expected = {
|
||||
'version': '2.0',
|
||||
'software': {
|
||||
'name': 'funkwhale',
|
||||
'version': funkwhale_api.__version__
|
||||
},
|
||||
'protocols': ['activitypub'],
|
||||
'services': {
|
||||
'inbound': [],
|
||||
'outbound': []
|
||||
},
|
||||
'openRegistrations': preferences['users__registration_enabled'],
|
||||
'usage': {
|
||||
'users': {
|
||||
'total': 0,
|
||||
},
|
||||
'localPosts': 0,
|
||||
'localComments': 0,
|
||||
},
|
||||
'metadata': {
|
||||
'shortDescription': preferences['instance__short_description'],
|
||||
'longDescription': preferences['instance__long_description'],
|
||||
'name': preferences['instance__name'],
|
||||
'library': {
|
||||
'federationEnabled': preferences['federation__enabled'],
|
||||
'federationNeedsApproval': preferences['federation__music_needs_approval'],
|
||||
},
|
||||
}
|
||||
}
|
||||
assert nodeinfo.get() == expected
|
||||
|
|
@ -3,16 +3,6 @@ from django.urls import reverse
|
|||
from funkwhale_api.instance import stats
|
||||
|
||||
|
||||
def test_can_get_stats_via_api(db, api_client, mocker):
|
||||
stats = {
|
||||
'foo': 'bar'
|
||||
}
|
||||
mocker.patch('funkwhale_api.instance.stats.get', return_value=stats)
|
||||
url = reverse('api:v1:instance:stats')
|
||||
response = api_client.get(url)
|
||||
assert response.data == stats
|
||||
|
||||
|
||||
def test_get_users(mocker):
|
||||
mocker.patch(
|
||||
'funkwhale_api.users.models.User.objects.count', return_value=42)
|
||||
|
|
|
|||
22
api/tests/instance/test_views.py
Normal file
22
api/tests/instance/test_views.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
from django.urls import reverse
|
||||
|
||||
|
||||
def test_nodeinfo_endpoint(db, api_client, mocker):
|
||||
payload = {
|
||||
'test': 'test'
|
||||
}
|
||||
mocked_nodeinfo = mocker.patch(
|
||||
'funkwhale_api.instance.nodeinfo.get', return_value=payload)
|
||||
url = reverse('api:v1:instance:nodeinfo')
|
||||
response = api_client.get(url)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.data == payload
|
||||
|
||||
|
||||
def test_nodeinfo_endpoint_disabled(db, api_client, preferences):
|
||||
preferences['instance__nodeinfo_enabled'] = False
|
||||
url = reverse('api:v1:instance:nodeinfo')
|
||||
response = api_client.get(url)
|
||||
|
||||
assert response.status_code == 404
|
||||
Loading…
Add table
Add a link
Reference in a new issue