<commit_before>from django.contrib.auth.models import AnonymousUser
from django.test import TestCase
from incuna_test_utils.testcases.request import BaseRequestTestCase
from rest_framework.test import APIRequestFactory, force_authenticate

from .factories import UserFactory


class APIRequestTestCase(TestCase):
    user_factory = UserFactory

    def create_request(self, method='get', url='/', user=None, auth=True, **kwargs):
        if not user:
            if auth:
                user = self.user_factory.create()
            else:
                user = AnonymousUser()
        kwargs['format'] = 'json'
        request = getattr(APIRequestFactory(), method)(url, **kwargs)
        request.user = user
        if auth:
            force_authenticate(request, user)
        if 'data' in kwargs:
            request.DATA = kwargs['data']
        return request


class RequestTestCase(BaseRequestTestCase):
    user_factory = UserFactory<commit_msg>Refactor APIRequestTestCase<commit_after>from incuna_test_utils.testcases.api_request import BaseAPIRequestTestCase
from incuna_test_utils.testcases.request import BaseRequestTestCase

from .factories import UserFactory


class APIRequestTestCase(BaseAPIRequestTestCase):
    user_factory = UserFactory


class RequestTestCase(BaseRequestTestCase):
    user_factory = UserFactory
{'fraction_non_alphanumeric': 0.07415730337078652, 'fraction_numerical': 0.0, 'mean_word_length': 3.7544483985765122, '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': '1869763', 'n_tokens_mistral': 347, 'n_tokens_neox': 337, 'n_words': 86}