from django.test import TestCase, RequestFactory
from graphene.test import Client

from api.schema import schema
from core.tests.helpers import GQLResult
from users.models import SchoolClass, User
from users.services import create_users

class GQLClient(Client):
    def get_result(self, *args, **kwargs):
        return GQLResult(self.execute(*args, **kwargs))



class SkillboxTestCase(TestCase):
    def createDefault(self) -> None:
        create_users()
        self.teacher = User.objects.get(username='teacher')
        self.teacher2 = User.objects.get(username='teacher2')
        self.student1 = User.objects.get(username='student1')
        self.student2 = User.objects.get(username='student2')
        self.student_second_class = User.objects.get(username='student_second_class')

        self.school_class = SchoolClass.objects.get(name='skillbox')

    def get_client(self, user=None) -> Client:
        request = RequestFactory().get('/')
        if user is None:
            user = self.teacher
        request.user = user
        return GQLClient(schema=schema, context_value=request)


