Added stats endpoint for domain

This commit is contained in:
Eliot Berriot 2018-12-27 19:58:34 +01:00
commit 032197da3f
No known key found for this signature in database
GPG key ID: DD6965E2476E5C27
5 changed files with 71 additions and 1 deletions

View file

@ -77,3 +77,23 @@ def test_external_domains(factories, settings):
settings.FEDERATION_HOSTNAME = d1.pk
assert list(models.Domain.objects.external()) == [d2]
def test_domain_stats(factories):
expected = {
"actors": 0,
"libraries": 0,
"tracks": 0,
"albums": 0,
"uploads": 0,
"artists": 0,
"outbox_activities": 0,
"received_library_follows": 0,
"emitted_library_follows": 0,
"media_total_size": 0,
"media_downloaded_size": 0,
}
domain = factories["federation.Domain"]()
assert domain.get_stats() == expected

View file

@ -103,3 +103,14 @@ def test_domain_nodeinfo(factories, superuser_api_client, mocker):
assert response.data == {"status": "ok", "payload": {"hello": "world"}}
update_domain_nodeinfo.assert_called_once_with(domain_name=domain.name)
def test_domain_stats(factories, superuser_api_client, mocker):
domain = factories["federation.Domain"]()
get_stats = mocker.patch.object(
domain.__class__, "get_stats", return_value={"hello": "world"}
)
url = reverse("api:v1:manage:federation:domains-stats", kwargs={"pk": domain.name})
response = superuser_api_client.get(url)
assert response.status_code == 200
assert response.data == {"hello": "world"}