factories.py 773 Bytes
Newer Older
1
2
3
4
5
6
import factory
import requests
import requests_http_signature

from funkwhale_api.factories import registry

7
from . import keys
8
9


10
registry.register(keys.get_key_pair, name='federation.KeyPair')
11
12
13
14
15


@registry.register(name='federation.SignatureAuth')
class SignatureAuthFactory(factory.Factory):
    algorithm = 'rsa-sha256'
16
    key = factory.LazyFunction(lambda: keys.get_key_pair()[0])
17
    key_id = factory.Faker('url')
18
    use_auth_header = False
19
20
21
22
23
24
25
26
27
28
29
30
31

    class Meta:
        model = requests_http_signature.HTTPSignatureAuth


@registry.register(name='federation.SignedRequest')
class SignedRequestFactory(factory.Factory):
    url = factory.Faker('url')
    method = 'get'
    auth = factory.SubFactory(SignatureAuthFactory)

    class Meta:
        model = requests.Request