Skip to content
Snippets Groups Projects
Commit b306a938 authored by jan.bednarik's avatar jan.bednarik
Browse files

Factories for tests and call_api fixture

parent 65aff20f
No related branches found
No related tags found
No related merge requests found
import pytest
from pytest_factoryboy import register
from django_elasticsearch_dsl.test import ESTestCase
import json
from openlobby.core.auth import create_access_token
from . import factories
register(factories.UserFactory)
register(factories.AuthorFactory)
register(factories.ReportFactory)
class DummyTestCase:
......@@ -38,3 +48,30 @@ def issuer(request):
if url is None:
pytest.skip("Missing OpenID Provider URL.")
return url
@pytest.fixture
def author_fix(author_factory):
return author_factory(
id=42,
username="wolfe",
first_name="Winston",
last_name="Wolfe",
extra={"movies": 1},
)
@pytest.fixture
def call_api(client):
def _call_api(query, input=None, user=None):
variables = json.dumps({"input": input or {}})
payload = {"query": query, "variables": variables}
if user is None:
res = client.post("/graphql", payload)
else:
token = create_access_token(user.username)
auth_header = "Bearer {}".format(token)
res = client.post("/graphql", payload, HTTP_AUTHORIZATION=auth_header)
return res.json()
return _call_api
from factory import DjangoModelFactory, Faker, SubFactory
from django.conf import settings
from openlobby.core.models import Report
class UserFactory(DjangoModelFactory):
class Meta:
model = settings.AUTH_USER_MODEL
username = Faker("user_name")
first_name = Faker("first_name")
last_name = Faker("last_name")
class AuthorFactory(DjangoModelFactory):
class Meta:
model = settings.AUTH_USER_MODEL
username = Faker("user_name")
first_name = Faker("first_name")
last_name = Faker("last_name")
is_author = True
class ReportFactory(DjangoModelFactory):
class Meta:
model = Report
author = SubFactory(AuthorFactory)
date = Faker("past_datetime")
title = Faker("sentence")
body = Faker("sentence")
received_benefit = Faker("word")
provided_benefit = Faker("word")
our_participants = Faker("name")
other_participants = Faker("name")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment