Verified Commit 6fbf8fa4 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Actor factory and fixture

parent 3650c369
...@@ -5,6 +5,7 @@ import requests_http_signature ...@@ -5,6 +5,7 @@ import requests_http_signature
from funkwhale_api.factories import registry from funkwhale_api.factories import registry
from . import keys from . import keys
from . import models
registry.register(keys.get_key_pair, name='federation.KeyPair') registry.register(keys.get_key_pair, name='federation.KeyPair')
...@@ -48,14 +49,23 @@ class SignedRequestFactory(factory.Factory): ...@@ -48,14 +49,23 @@ class SignedRequestFactory(factory.Factory):
self.headers.update(default_headers) self.headers.update(default_headers)
# @registry.register @registry.register
# class ActorFactory(factory.DjangoModelFactory): class ActorFactory(factory.DjangoModelFactory):
# url = factory.Faker('url') url = factory.Faker('url')
# inbox_url = factory.Faker('url') inbox_url = factory.Faker('url')
# outbox_url = factory.Faker('url') outbox_url = factory.Faker('url')
# public_key = factory.LazyFunction(lambda: keys.get_key_pair()[1]) public_key = None
# preferred_username = factory.Faker('username') private_key = None
# summary = factory.Faker('paragraph') preferred_username = factory.Faker('user_name')
# summary = factory.Faker('paragraph')
# class Meta:
# model = models.Actor 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)
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): ...@@ -21,19 +21,19 @@ def test_instance_actors(system_actor, db, settings, api_client):
assert response.data == serializer.data assert response.data == serializer.data
# @pytest.mark.parametrize('route', [ @pytest.mark.parametrize('route,kwargs', [
# 'instance-outbox', ('instance-actors-outbox', {'actor': 'library'}),
# 'instance-inbox', ('instance-actors-inbox', {'actor': 'library'}),
# 'instance-actor', ('instance-actors-detail', {'actor': 'library'}),
# 'well-known-webfinger', ('well-known-webfinger', {}),
# ]) ])
# def test_instance_inbox_405_if_federation_disabled( def test_instance_inbox_405_if_federation_disabled(
# db, settings, api_client, route): authenticated_actor, db, settings, api_client, route, kwargs):
# settings.FEDERATION_ENABLED = False settings.FEDERATION_ENABLED = False
# url = reverse('federation:{}'.format(route)) url = reverse('federation:{}'.format(route), kwargs=kwargs)
# response = api_client.get(url) response = api_client.get(url)
#
# assert response.status_code == 405 assert response.status_code == 405
def test_wellknown_webfinger_validates_resource( def test_wellknown_webfinger_validates_resource(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment