kopia lustrzana https://dev.funkwhale.audio/funkwhale/funkwhale
Actor factory and fixture
rodzic
3650c3699b
commit
6fbf8fa44c
|
@ -5,6 +5,7 @@ import requests_http_signature
|
|||
from funkwhale_api.factories import registry
|
||||
|
||||
from . import keys
|
||||
from . import models
|
||||
|
||||
|
||||
registry.register(keys.get_key_pair, name='federation.KeyPair')
|
||||
|
@ -48,14 +49,23 @@ class SignedRequestFactory(factory.Factory):
|
|||
self.headers.update(default_headers)
|
||||
|
||||
|
||||
# @registry.register
|
||||
# class ActorFactory(factory.DjangoModelFactory):
|
||||
# url = factory.Faker('url')
|
||||
# inbox_url = factory.Faker('url')
|
||||
# outbox_url = factory.Faker('url')
|
||||
# public_key = factory.LazyFunction(lambda: keys.get_key_pair()[1])
|
||||
# preferred_username = factory.Faker('username')
|
||||
# summary = factory.Faker('paragraph')
|
||||
#
|
||||
# class Meta:
|
||||
# model = models.Actor
|
||||
@registry.register
|
||||
class ActorFactory(factory.DjangoModelFactory):
|
||||
url = factory.Faker('url')
|
||||
inbox_url = factory.Faker('url')
|
||||
outbox_url = factory.Faker('url')
|
||||
public_key = None
|
||||
private_key = None
|
||||
preferred_username = factory.Faker('user_name')
|
||||
summary = factory.Faker('paragraph')
|
||||
|
||||
class Meta:
|
||||
model = models.Actor
|
||||
|
||||
@classmethod
|
||||
def _generate(cls, create, attrs):
|
||||
has_public = attrs.get('public_key') is None
|
||||
has_private = attrs.get('private_key') is None
|
||||
if not has_public and not has_private:
|
||||
attrs['private_key'], attrs['public'] = keys.get_key_pair()
|
||||
return super()._generate(create, attrs)
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def authenticated_actor(nodb_factories, mocker):
|
||||
actor = nodb_factories['federation.Actor']()
|
||||
mocker.patch(
|
||||
'funkwhale_api.federation.authentication.SignatureAuthentication.authenticate_actor',
|
||||
return_value=actor)
|
||||
yield actor
|
|
@ -21,19 +21,19 @@ def test_instance_actors(system_actor, db, settings, api_client):
|
|||
assert response.data == serializer.data
|
||||
|
||||
|
||||
# @pytest.mark.parametrize('route', [
|
||||
# 'instance-outbox',
|
||||
# 'instance-inbox',
|
||||
# 'instance-actor',
|
||||
# 'well-known-webfinger',
|
||||
# ])
|
||||
# def test_instance_inbox_405_if_federation_disabled(
|
||||
# db, settings, api_client, route):
|
||||
# settings.FEDERATION_ENABLED = False
|
||||
# url = reverse('federation:{}'.format(route))
|
||||
# response = api_client.get(url)
|
||||
#
|
||||
# assert response.status_code == 405
|
||||
@pytest.mark.parametrize('route,kwargs', [
|
||||
('instance-actors-outbox', {'actor': 'library'}),
|
||||
('instance-actors-inbox', {'actor': 'library'}),
|
||||
('instance-actors-detail', {'actor': 'library'}),
|
||||
('well-known-webfinger', {}),
|
||||
])
|
||||
def test_instance_inbox_405_if_federation_disabled(
|
||||
authenticated_actor, db, settings, api_client, route, kwargs):
|
||||
settings.FEDERATION_ENABLED = False
|
||||
url = reverse('federation:{}'.format(route), kwargs=kwargs)
|
||||
response = api_client.get(url)
|
||||
|
||||
assert response.status_code == 405
|
||||
|
||||
|
||||
def test_wellknown_webfinger_validates_resource(
|
||||
|
|
Ładowanie…
Reference in New Issue