<commit_before>"""
Tests for the OPAL API
"""
import json
from datetime import date, timedelta, datetime
from django.utils import timezone
from django.conf import settings
from django.contrib.auth.models import User
from django.test import TestCase
from django.db import DataError
from django.contrib.contenttypes.models import ContentType
from mock import patch, MagicMock

from rest_framework.reverse import reverse

from opal import models
from opal.tests.models import Colour, PatientColour, HatWearer, Hat
from opal.core import metadata
from opal.core.test import OpalTestCase
from opal.core.views import _build_json_response
from opal.core.exceptions import APIError

# this is used just to import the class for
# EpisodeListApiTestCase and OptionsViewSetTestCase
from opal.tests.test_patient_lists import TaggingTestPatientList # flake8: noqa

from opal.core import api


class OPALRouterTestCase(TestCase):
    def test_default_base_name(self):
        class ViewSet:
            base_name = 'the name'
        self.assertEqual(api.OPALRouter().get_default_base_name(ViewSet), 'the name')


class RecordTestCase(TestCase):

    @patch('opal.core.api.schemas')
    def test_records(self, schemas):
        schemas.list_records.return_value = [{}]
        self.assertEqual([{}], api.RecordViewSet().list(None).data)


class EpisodeListApiTestCase(OpalTestCase):
    def test_episode_list_view(self):
        request = MagicMock(name='mock request')
        request.user = self.user
        view = api.EpisodeListApi()
        view.request = request
        resp = view.get(tag="eater", subtag="herbivore")
        self.assertEqual(200, resp.status_code)


class ExtractSchemaTestCase(TestCase):

    @patch('opal.core.api.schemas')
    def test_records(self, schemas):
        schemas.extract_schema.return_value = [{}]
        self.assertEqual([{}], api.ExtractSchemaViewSet().list(None).data)


class OptionTestCase(TestCase):<commit_msg>Should test default opalrouter case<commit_after>"""
Tests for the OPAL API
"""
import json
from datetime import date, timedelta, datetime
from django.utils import timezone
from django.conf import settings
from django.contrib.auth.models import User
from django.test import TestCase
from django.db import DataError
from django.contrib.contenttypes.models import ContentType
from mock import patch, MagicMock

from rest_framework.reverse import reverse

from opal import models
from opal.tests.models import Colour, PatientColour, HatWearer, Hat
from opal.core import metadata
from opal.core.test import OpalTestCase
from opal.core.views import _build_json_response
from opal.core.exceptions import APIError

# this is used just to import the class for
# EpisodeListApiTestCase and OptionsViewSetTestCase
from opal.tests.test_patient_lists import TaggingTestPatientList # flake8: noqa

from opal.core import api


class OPALRouterTestCase(TestCase):

    def test_default_base_name(self):
        class ViewSet:
            base_name = 'the name'
        self.assertEqual(api.OPALRouter().get_default_base_name(ViewSet), 'the name')

    def test_default_base_name_unset(self):
        class ColourViewSet:
            queryset = Colour.objects.all()
        self.assertEqual(api.OPALRouter().get_default_base_name(ColourViewSet), 'colour')


class RecordTestCase(TestCase):

    @patch('opal.core.api.schemas')
    def test_records(self, schemas):
        schemas.list_records.return_value = [{}]
        self.assertEqual([{}], api.RecordViewSet().list(None).data)


class EpisodeListApiTestCase(OpalTestCase):
    def test_episode_list_view(self):
        request = MagicMock(name='mock request')
        request.user = self.user
        view = api.EpisodeListApi()
        view.request = request
        resp = view.get(tag="eater", subtag="herbivore")
        self.assertEqual(200, resp.status_code)


class ExtractSchemaTestCase(TestCase):

    @patch('opal.core.api.schemas')
    def test_records(self, schemas):
        schemas.extract_schema.return_value = [{}]
        self.assertEqual([{}], api.ExtractSchemaViewSet().list(None).data)


class OptionTestCase(TestCase):
{'fraction_non_alphanumeric': 0.09143827310211011, 'fraction_numerical': 0.0019403347077370846, 'mean_word_length': 4.362808842652796, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3673436', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1164, 'n_words': 303}