funkwhale/api/tests/federation/test_models.py

119 wiersze
3.1 KiB
Python
Czysty Zwykły widok Historia

2018-04-03 19:30:15 +00:00
import pytest
from django import db
from funkwhale_api.federation import models
2018-04-03 19:30:15 +00:00
def test_cannot_duplicate_actor(factories):
2018-06-09 13:36:16 +00:00
actor = factories["federation.Actor"]()
2018-04-03 19:30:15 +00:00
with pytest.raises(db.IntegrityError):
2018-06-09 13:36:16 +00:00
factories["federation.Actor"](
domain=actor.domain, preferred_username=actor.preferred_username
2018-04-03 19:30:15 +00:00
)
def test_cannot_duplicate_follow(factories):
2018-06-09 13:36:16 +00:00
follow = factories["federation.Follow"]()
2018-04-03 19:30:15 +00:00
with pytest.raises(db.IntegrityError):
2018-06-09 13:36:16 +00:00
factories["federation.Follow"](target=follow.target, actor=follow.actor)
2018-04-03 21:25:44 +00:00
2018-04-03 21:25:44 +00:00
def test_follow_federation_url(factories):
2018-06-09 13:36:16 +00:00
follow = factories["federation.Follow"](local=True)
expected = "{}#follows/{}".format(follow.actor.fid, follow.uuid)
assert follow.get_federation_id() == expected
def test_actor_get_quota(factories):
library = factories["music.Library"]()
2018-09-22 12:29:30 +00:00
factories["music.Upload"](
library=library,
import_status="pending",
audio_file__from_path=None,
audio_file__data=b"a",
)
2018-09-22 12:29:30 +00:00
factories["music.Upload"](
library=library,
import_status="skipped",
audio_file__from_path=None,
audio_file__data=b"aa",
)
2018-09-22 12:29:30 +00:00
factories["music.Upload"](
library=library,
import_status="errored",
audio_file__from_path=None,
audio_file__data=b"aaa",
)
2018-09-22 12:29:30 +00:00
factories["music.Upload"](
library=library,
import_status="finished",
audio_file__from_path=None,
audio_file__data=b"aaaa",
)
expected = {"total": 10, "pending": 1, "skipped": 2, "errored": 3, "finished": 4}
assert library.actor.get_current_usage() == expected
@pytest.mark.parametrize(
"value, expected",
[
("Domain.com", "domain.com"),
("hello-WORLD.com", "hello-world.com"),
("posés.com", "posés.com"),
],
)
def test_domain_name_saved_properly(value, expected, factories):
domain = factories["federation.Domain"](name=value)
assert domain.name == expected
def test_external_domains(factories, settings):
d1 = factories["federation.Domain"]()
d2 = factories["federation.Domain"]()
settings.FEDERATION_HOSTNAME = d1.pk
assert list(models.Domain.objects.external()) == [d2]
2018-12-27 18:58:34 +00:00
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
def test_actor_stats(factories):
expected = {
"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,
}
actor = factories["federation.Actor"]()
assert actor.get_stats() == expected