forked from City-of-Turku/tunnistamo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
factories.py
37 lines (24 loc) · 983 Bytes
/
factories.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import factory
from users.factories import OIDCClientFactory
from .models import Api, ApiDomain, ApiScope
def create_oidc_client_for_api(api):
domain_identifier = api.domain.identifier.rstrip('/')
return OIDCClientFactory(client_id='{}/{}'.format(domain_identifier, api.name))
class ApiDomainFactory(factory.django.DjangoModelFactory):
identifier = factory.Faker('url')
class Meta:
model = ApiDomain
class ApiFactory(factory.django.DjangoModelFactory):
domain = factory.SubFactory(ApiDomainFactory)
name = factory.Faker('word')
oidc_client = factory.LazyAttribute(create_oidc_client_for_api)
class Meta:
model = Api
class ApiScopeFactory(factory.django.DjangoModelFactory):
api = factory.SubFactory(ApiFactory)
specifier = ''
identifier = factory.LazyAttribute(ApiScope._generate_identifier)
name = factory.Faker('word')
description = factory.Faker('sentence')
class Meta:
model = ApiScope