<commit_before>import pytest
from rest_framework.request import Request
from rest_framework.test import APIRequestFactory

from rest_framework.parsers import JSONParser, FormParser, MultiPartParser


factory = APIRequestFactory()


def test_content_type_override_query():
    from rest_url_override_content_negotiation import \
        URLOverrideContentNegotiation
    negotiation = URLOverrideContentNegotiation()
    parsers = (JSONParser, FormParser, MultiPartParser)

    requestWithQueryParam = Request(
        factory.post('/?content_type=application/x-www-form-urlencoded',
                     {'email': '<EMAIL>'},
                     content_type='text/plain'))
    parser = negotiation.select_parser(requestWithQueryParam, parsers)
    assert parser.media_type == 'application/x-www-form-urlencoded'

    requestWithoutQueryParam = Request(
        factory.post('/', {'email': '<EMAIL>'},
                     content_type='text/plain'))
    assert None is negotiation.select_parser(
        requestWithoutQueryParam, parsers)


def test_limited_overrides():
    """
    The content type shouldn't be overridden if the header is something other
    than 'text/plain', or missing entirely.

    """
    from rest_url_override_content_negotiation import \
        URLOverrideContentNegotiation
    negotiation = URLOverrideContentNegotiation()
    parsers = (JSONParser, FormParser, MultiPartParser)

    req = Request(
        factory.post('/?content_type=application/x-www-form-urlencoded',
                     {'email': '<EMAIL>'},
                     content_type='text/somethingelse'))
    assert negotiation.select_parser(req, parsers) is None
<commit_msg>Select from a list of instances<commit_after>import pytest
from rest_framework.request import Request
from rest_framework.test import APIRequestFactory

from rest_framework.parsers import JSONParser, FormParser, MultiPartParser


factory = APIRequestFactory()


def test_content_type_override_query():
    from rest_url_override_content_negotiation import \
        URLOverrideContentNegotiation
    negotiation = URLOverrideContentNegotiation()
    parsers = (JSONParser(), FormParser(), MultiPartParser())

    requestWithQueryParam = Request(
        factory.post('/?content_type=application/x-www-form-urlencoded',
                     {'email': '<EMAIL>'},
                     content_type='text/plain'))
    parser = negotiation.select_parser(requestWithQueryParam, parsers)
    assert parser.media_type == 'application/x-www-form-urlencoded'

    requestWithoutQueryParam = Request(
        factory.post('/', {'email': '<EMAIL>'},
                     content_type='text/plain'))
    assert None is negotiation.select_parser(
        requestWithoutQueryParam, parsers)


def test_limited_overrides():
    """
    The content type shouldn't be overridden if the header is something other
    than 'text/plain', or missing entirely.

    """
    from rest_url_override_content_negotiation import \
        URLOverrideContentNegotiation
    negotiation = URLOverrideContentNegotiation()
    parsers = (JSONParser(), FormParser(), MultiPartParser())

    req = Request(
        factory.post('/?content_type=application/x-www-form-urlencoded',
                     {'email': '<EMAIL>'},
                     content_type='text/somethingelse'))
    assert negotiation.select_parser(req, parsers) is None

{'fraction_non_alphanumeric': 0.09402720283855706, 'fraction_numerical': 0.0, 'mean_word_length': 3.510666666666667, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '6116337', 'n_tokens_mistral': 944, 'n_tokens_neox': 865, 'n_words': 193}