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
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)
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(
......
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