<commit_before>import json
import logging

import graphene
import pytest
from django.contrib.auth.models import AnonymousUser
from django.core.serializers.json import DjangoJSONEncoder
from django.shortcuts import reverse
from django.test.client import MULTIPART_CONTENT, Client
from graphql_jwt.shortcuts import get_token

from saleor.account.models import User
from saleor.app.models import App
from saleor.graphql.tests.utils import assert_no_permission
from saleor.graphql.views import handled_errors_logger, unhandled_errors_logger
from saleor.tests.utils import flush_post_commit_hooks

API_PATH = reverse("api")


class ApiClient(Client):
    """GraphQL API client."""

    def __init__(self, *args, **kwargs):
        user = kwargs.pop("user", AnonymousUser())
        app = kwargs.pop("app", None)
        self._user = None
        self.token = None
        self.user = user
        self.app_token = None
        self.app = app
        if not user.is_anonymous:
            self.token = get_token(user)
        elif app:
            token = app.tokens.first()
            self.app_token = token.auth_token if token else None
        super().__init__(*args, **kwargs)

    def _base_environ(self, **request):
        environ = super()._base_environ(**request)<commit_msg>Refactor import in api fixtures<commit_after>import json
import logging

import graphene
import pytest
from django.contrib.auth.models import AnonymousUser
from django.core.serializers.json import DjangoJSONEncoder
from django.shortcuts import reverse
from django.test.client import MULTIPART_CONTENT, Client
from graphql_jwt.shortcuts import get_token

from ...account.models import User
from ...app.models import App
from ...tests.utils import flush_post_commit_hooks
from ..views import handled_errors_logger, unhandled_errors_logger
from .utils import assert_no_permission

API_PATH = reverse("api")


class ApiClient(Client):
    """GraphQL API client."""

    def __init__(self, *args, **kwargs):
        user = kwargs.pop("user", AnonymousUser())
        app = kwargs.pop("app", None)
        self._user = None
        self.token = None
        self.user = user
        self.app_token = None
        self.app = app
        if not user.is_anonymous:
            self.token = get_token(user)
        elif app:
            token = app.tokens.first()
            self.app_token = token.auth_token if token else None
        super().__init__(*args, **kwargs)

    def _base_environ(self, **request):
        environ = super()._base_environ(**request)
{'fraction_non_alphanumeric': 0.09087317265902806, 'fraction_numerical': 0.0, 'mean_word_length': 3.298811544991511, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7369437', 'n_tokens_mistral': 729, 'n_tokens_neox': 720, 'n_words': 201}