mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 04:09:16 +02:00
Moved actor domain to a dedicated table
This commit is contained in:
parent
060543f62c
commit
7ac3bb98da
14 changed files with 244 additions and 44 deletions
|
@ -12,12 +12,16 @@ from faker.providers import internet as internet_provider
|
|||
import factory
|
||||
import pytest
|
||||
|
||||
from django.core.management import call_command
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.core.cache import cache as django_cache, caches
|
||||
from django.core.files import uploadedfile
|
||||
from django.utils import timezone
|
||||
from django.test import client
|
||||
from django.db import connection
|
||||
from django.db.migrations.executor import MigrationExecutor
|
||||
from django.db.models import QuerySet
|
||||
|
||||
from dynamic_preferences.registries import global_preferences_registry
|
||||
from rest_framework import fields as rest_fields
|
||||
from rest_framework.test import APIClient, APIRequestFactory
|
||||
|
@ -400,3 +404,9 @@ def spa_html(r_mock, settings):
|
|||
@pytest.fixture
|
||||
def no_api_auth(preferences):
|
||||
preferences["common__api_authentication_required"] = False
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def migrator(transactional_db):
|
||||
yield MigrationExecutor(connection)
|
||||
call_command("migrate", interactive=False)
|
||||
|
|
34
api/tests/federation/test_migrations.py
Normal file
34
api/tests/federation/test_migrations.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
def test_domain_14_migration(migrator):
|
||||
a, f, t = ("federation", "0014_auto_20181205_0958", "0015_populate_domains")
|
||||
|
||||
migrator.migrate([(a, f)])
|
||||
old_apps = migrator.loader.project_state([(a, f)]).apps
|
||||
Actor = old_apps.get_model(a, "Actor")
|
||||
a1 = Actor.objects.create(
|
||||
fid="http://test1.com", preferred_username="test1", old_domain="dOmaiN1.com"
|
||||
)
|
||||
a2 = Actor.objects.create(
|
||||
fid="http://test2.com", preferred_username="test2", old_domain="domain1.com"
|
||||
)
|
||||
a3 = Actor.objects.create(
|
||||
fid="http://test3.com", preferred_username="test2", old_domain="domain2.com"
|
||||
)
|
||||
|
||||
migrator.loader.build_graph()
|
||||
migrator.migrate([(a, t)])
|
||||
new_apps = migrator.loader.project_state([(a, t)]).apps
|
||||
|
||||
Actor = new_apps.get_model(a, "Actor")
|
||||
Domain = new_apps.get_model(a, "Domain")
|
||||
|
||||
a1 = Actor.objects.get(pk=a1.pk)
|
||||
a2 = Actor.objects.get(pk=a2.pk)
|
||||
a3 = Actor.objects.get(pk=a3.pk)
|
||||
|
||||
assert Domain.objects.count() == 2
|
||||
assert a1.domain == Domain.objects.get(pk="domain1.com")
|
||||
assert a2.domain == Domain.objects.get(pk="domain1.com")
|
||||
assert a3.domain == Domain.objects.get(pk="domain2.com")
|
||||
|
||||
assert Domain.objects.get(pk="domain1.com").creation_date == a1.creation_date
|
||||
assert Domain.objects.get(pk="domain2.com").creation_date == a3.creation_date
|
|
@ -54,3 +54,16 @@ def test_actor_get_quota(factories):
|
|||
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
|
||||
|
|
|
@ -43,7 +43,7 @@ def test_actor_serializer_from_ap(db):
|
|||
assert actor.public_key == payload["publicKey"]["publicKeyPem"]
|
||||
assert actor.preferred_username == payload["preferredUsername"]
|
||||
assert actor.name == payload["name"]
|
||||
assert actor.domain == "test.federation"
|
||||
assert actor.domain.pk == "test.federation"
|
||||
assert actor.summary == payload["summary"]
|
||||
assert actor.type == "Person"
|
||||
assert actor.manually_approves_followers == payload["manuallyApprovesFollowers"]
|
||||
|
@ -71,7 +71,7 @@ def test_actor_serializer_only_mandatory_field_from_ap(db):
|
|||
assert actor.followers_url == payload["followers"]
|
||||
assert actor.following_url == payload["following"]
|
||||
assert actor.preferred_username == payload["preferredUsername"]
|
||||
assert actor.domain == "test.federation"
|
||||
assert actor.domain.pk == "test.federation"
|
||||
assert actor.type == "Person"
|
||||
assert actor.manually_approves_followers is None
|
||||
|
||||
|
@ -110,7 +110,7 @@ def test_actor_serializer_to_ap():
|
|||
public_key=expected["publicKey"]["publicKeyPem"],
|
||||
preferred_username=expected["preferredUsername"],
|
||||
name=expected["name"],
|
||||
domain="test.federation",
|
||||
domain=models.Domain(pk="test.federation"),
|
||||
summary=expected["summary"],
|
||||
type="Person",
|
||||
manually_approves_followers=False,
|
||||
|
@ -135,7 +135,7 @@ def test_webfinger_serializer():
|
|||
actor = models.Actor(
|
||||
fid=expected["links"][0]["href"],
|
||||
preferred_username="service",
|
||||
domain="test.federation",
|
||||
domain=models.Domain(pk="test.federation"),
|
||||
)
|
||||
serializer = serializers.ActorWebfingerSerializer(actor)
|
||||
|
||||
|
@ -898,7 +898,7 @@ def test_local_actor_serializer_to_ap(factories):
|
|||
public_key=expected["publicKey"]["publicKeyPem"],
|
||||
preferred_username=expected["preferredUsername"],
|
||||
name=expected["name"],
|
||||
domain="test.federation",
|
||||
domain=models.Domain.objects.create(pk="test.federation"),
|
||||
summary=expected["summary"],
|
||||
type="Person",
|
||||
manually_approves_followers=False,
|
||||
|
|
|
@ -137,7 +137,7 @@ def test_creating_actor_from_user(factories, settings):
|
|||
actor = models.create_actor(user)
|
||||
|
||||
assert actor.preferred_username == "Hello_M_world" # slugified
|
||||
assert actor.domain == settings.FEDERATION_HOSTNAME
|
||||
assert actor.domain.pk == settings.FEDERATION_HOSTNAME
|
||||
assert actor.type == "Person"
|
||||
assert actor.name == user.username
|
||||
assert actor.manually_approves_followers is False
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue