<commit_before>import json
import os

import pytest
from django.conf import settings
from django.utils.encoding import force_text
from rest_framework.authtoken.models import Token

from grandchallenge.evaluation.models import Submission
from grandchallenge.subdomains.utils import reverse
from tests.factories import UserFactory, ChallengeFactory


def get_staff_user_with_token():
    user = UserFactory(is_staff=True)
    token = Token.objects.create(user=user)

    return user, token.key


@pytest.mark.django_db
@pytest.mark.parametrize(
    "test_input, expected",
    [("submission", "Submission List"), ("image", "Image List")],
)
def test_api_pages(client, test_input, expected):
    _, token = get_staff_user_with_token()

    # Check for the correct HTML view
    url = reverse(f"api:{test_input}-list")
    response = client.get(
        url, HTTP_ACCEPT="text/html", HTTP_AUTHORIZATION="Token " + token
    )
    assert expected in force_text(response.content)
    assert response.status_code == 200

    # There should be no content, but we should be able to do json.loads
    response = client.get(
        url,
        HTTP_ACCEPT="application/json",
        HTTP_AUTHORIZATION="Token " + token,
    )
    assert response.status_code == 200
    assert not json.loads(response.content)
<commit_msg>Corrects the expected response with Pagenation<commit_after>import json
import os

import pytest
from django.conf import settings
from django.utils.encoding import force_text
from rest_framework.authtoken.models import Token

from grandchallenge.evaluation.models import Submission
from grandchallenge.subdomains.utils import reverse
from tests.factories import UserFactory, ChallengeFactory


def get_staff_user_with_token():
    user = UserFactory(is_staff=True)
    token = Token.objects.create(user=user)

    return user, token.key


@pytest.mark.django_db
@pytest.mark.parametrize(
    "test_input, expected",
    [("submission", "Submission List"), ("image", "Image List")],
)
def test_api_pages(client, test_input, expected):
    _, token = get_staff_user_with_token()

    # Check for the correct HTML view
    url = reverse(f"api:{test_input}-list")
    response = client.get(
        url, HTTP_ACCEPT="text/html", HTTP_AUTHORIZATION="Token " + token
    )
    assert expected in force_text(response.content)
    assert response.status_code == 200

    # There should be no content, but we should be able to do json.loads
    response = client.get(
        url,
        HTTP_ACCEPT="application/json",
        HTTP_AUTHORIZATION="Token " + token,
    )
    assert response.status_code == 200
    assert json.loads(response.content)["count"] == 0

{'fraction_non_alphanumeric': 0.09441738478831023, 'fraction_numerical': 0.004870738104158861, 'mean_word_length': 4.1247600767754315, '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': '4987665', 'n_tokens_mistral': 813, 'n_tokens_neox': 788, 'n_words': 209}