<commit_before>import pytest

from model_bakery import baker

from django.contrib.auth.models import AnonymousUser
from django.contrib.sessions.middleware import SessionMiddleware
from django.test import RequestFactory


@pytest.fixture
def pre_request():
    factory = RequestFactory()
    request = factory.get('/')
    request.user = AnonymousUser()
    return request


def _get_request_with_session_setted(pre_request):
    middleware = SessionMiddleware()
    middleware.process_request(pre_request)
    pre_request.session.save()
    return pre_request


@pytest.fixture
def mocked_request(pre_request):
    return _get_request_with_session_setted(pre_request)


@pytest.fixture
def mocked_request_2(pre_request):
    return _get_request_with_session_setted(pre_request)


@pytest.fixture
def mocked_request_logged(pre_request, logged_user):
    pre_request.user = logged_user
    middleware = SessionMiddleware()
    middleware.process_request(pre_request)
    pre_request.session.save()

    return pre_request


@pytest.fixture
def user_session(logged_user):
    return baker.make('UserSession', user=logged_user)


@pytest.fixture
def mocked_request_with_analytics(mocked_request, user_session):
    mocked_request.session['analytics'] = {
        'id': user_session.id,
        'uuid': str(user_session.uuid)
    }
    return mocked_request
<commit_msg>Corrected alert RemovedInDjango40Warning<commit_after>import pytest

from model_bakery import baker

from django.contrib.auth.models import AnonymousUser
from django.contrib.sessions.middleware import SessionMiddleware
from django.test import RequestFactory


@pytest.fixture
def pre_request():
    factory = RequestFactory()
    request = factory.get('/')
    request.user = AnonymousUser()
    return request


def dummy_get_response(request):
    return None


def _get_request_with_session_setted(pre_request):
    middleware = SessionMiddleware(dummy_get_response)
    middleware.process_request(pre_request)
    pre_request.session.save()
    return pre_request


@pytest.fixture
def mocked_request(pre_request):
    return _get_request_with_session_setted(pre_request)


@pytest.fixture
def mocked_request_2(pre_request):
    return _get_request_with_session_setted(pre_request)


@pytest.fixture
def mocked_request_logged(pre_request, logged_user):
    pre_request.user = logged_user
    middleware = SessionMiddleware(dummy_get_response)
    middleware.process_request(pre_request)
    pre_request.session.save()

    return pre_request


@pytest.fixture
def user_session(logged_user):
    return baker.make('UserSession', user=logged_user)


@pytest.fixture
def mocked_request_with_analytics(mocked_request, user_session):
    mocked_request.session['analytics'] = {
        'id': user_session.id,
        'uuid': str(user_session.uuid)
    }
    return mocked_request

{'fraction_non_alphanumeric': 0.07911392405063292, 'fraction_numerical': 0.0014064697609001407, 'mean_word_length': 5.252747252747253, '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': '6423020', 'n_tokens_mistral': 906, 'n_tokens_neox': 902, 'n_words': 158}