2018-04-03 19:30:15 +00:00
|
|
|
import pytest
|
|
|
|
from django import db
|
|
|
|
|
2018-12-26 22:03:27 +00:00
|
|
|
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-06 16:49:29 +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)
|
2018-09-06 18:35:02 +00:00
|
|
|
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"](
|
2018-09-06 18:35:02 +00:00
|
|
|
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"](
|
2018-09-06 18:35:02 +00:00
|
|
|
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"](
|
2018-09-06 18:35:02 +00:00
|
|
|
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"](
|
2018-09-06 18:35:02 +00:00
|
|
|
library=library,
|
|
|
|
import_status="finished",
|
|
|
|
audio_file__from_path=None,
|
|
|
|
audio_file__data=b"aaaa",
|
|
|
|
)
|
2019-03-21 09:32:12 +00:00
|
|
|
|
|
|
|
# this one is imported in place and don't count
|
|
|
|
factories["music.Upload"](
|
|
|
|
library=library,
|
|
|
|
import_status="finished",
|
|
|
|
source="file://test",
|
|
|
|
audio_file=None,
|
|
|
|
size=42,
|
|
|
|
)
|
|
|
|
# this one is imported in place but count because there is a mapped file
|
|
|
|
factories["music.Upload"](
|
|
|
|
library=library,
|
|
|
|
import_status="finished",
|
|
|
|
source="file://test2",
|
|
|
|
audio_file__from_path=None,
|
|
|
|
audio_file__data=b"aaaa",
|
|
|
|
)
|
|
|
|
|
|
|
|
expected = {"total": 14, "pending": 1, "skipped": 2, "errored": 3, "finished": 8}
|
2018-09-06 18:35:02 +00:00
|
|
|
|
|
|
|
assert library.actor.get_current_usage() == expected
|
2018-12-05 11:13:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
@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
|
2018-12-26 22:03:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2019-01-03 16:10:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|