<commit_before>from django.test import TestCase

from apps.accounts.utils import set_group_permissions
from apps.core.testing.mixins import (
    TestListViewMixin,
    TestExportViewMixin,
    TestImportViewMixin,
    TestModelAPIViewMixin,
    TestListAPIViewMixin,
    TestRetrieveAPIViewMixin
)

from apps.conditions.models import Condition

from .models import OptionSet, Option


class OptionsTestCase(TestCase):

    lang = 'en'

    fixtures = (
        'users.json',
        'groups.json',
        'accounts.json',
        'conditions.json',
        'domain.json',
        'options.json',
    )

    users = (
        ('editor', 'editor'),
        ('reviewer', 'reviewer'),
        ('user', 'user'),
        ('api', 'api'),
        ('anonymous', None),
    )

    status_map = {
        'list': {'editor': 200, 'reviewer': 200, 'api': 200, 'user': 403, 'anonymous': 302},
        'export': {'editor': 200, 'reviewer': 200, 'api': 200, 'user': 403, 'anonymous': 302}
    }

    api_status_map = {
        'list': {'editor': 200, 'reviewer': 200, 'api': 200, 'user': 403, 'anonymous': 403},
        'retrieve': {'editor': 200, 'reviewer': 200, 'api': 200, 'user': 403, 'anonymous': 403},
        'create': {'editor': 201, 'reviewer': 403, 'api': 403, 'user': 403, 'anonymous': 403},
        'update': {'editor': 200, 'reviewer': 403, 'api': 403, 'user': 403, 'anonymous': 403},
        'delete': {'editor': 204, 'reviewer': 403, 'api': 403, 'user': 403, 'anonymous': 403}
    }

    def setUp(self):
        set_group_permissions()

class OptionsTests(TestListViewMixin, OptionsTestCase):

    url_names = {
        'list': 'options'
    }


class OptionSetTests(TestModelAPIViewMixin, OptionsTestCase):

    instances = OptionSet.objects.all()

    api_url_name = 'internal-options:optionset'

    def prepare_create_instance(self, instance):
        instance.key += '_new'
        return instance


class OptionTests(TestModelAPIViewMixin, OptionsTestCase):

    instances = Option.objects.all()

    api_url_name = 'internal-options:option'

    def prepare_create_instance(self, instance):
        instance.key += '_new'
        return instance


class ConditionTests(TestListAPIViewMixin, TestRetrieveAPIViewMixin, OptionsTestCase):

    instances = Condition.objects.all()

    api_url_name = 'internal-options:condition'


class OptionsExportTests(TestExportViewMixin, OptionsTestCase):

    url_names = {
        'export': 'options_export'
    }


class OptionsImportTests(TestImportViewMixin, TestCase):

    import_file = 'testing/xml/options.xml'


class OptionSetAPITests(TestListAPIViewMixin, TestRetrieveAPIViewMixin, OptionsTestCase):

    instances = OptionSet.objects.all()

    api_url_name = 'api-v1-options:optionset'


class OptionAPITests(TestListAPIViewMixin, TestRetrieveAPIViewMixin, OptionsTestCase):

    instances = Option.objects.all()

    api_url_name = 'api-v1-options:option'<commit_msg>refactor options tests<commit_after>from django.test import TestCase

from test_mixins.views import TestListViewMixin
from test_mixins.viewsets import TestModelViewsetMixin, TestListViewsetMixin, TestRetrieveViewsetMixin

from apps.core.testing.mixins import TestExportViewMixin, TestImportViewMixin
from apps.accounts.utils import set_group_permissions

from apps.conditions.models import Condition

from .models import OptionSet, Option


class OptionsTestCase(TestCase):

    lang = 'en'

    fixtures = (
        'users.json',
        'groups.json',
        'accounts.json',
        'conditions.json',
        'domain.json',
        'options.json',
    )

    users = (
        ('editor', 'editor'),
        ('reviewer', 'reviewer'),
        ('user', 'user'),
        ('api', 'api'),
        ('anonymous', None),
    )

    status_map = {
        'list_view': {
            'editor': 200, 'reviewer': 200, 'api': 200, 'user': 403, 'anonymous': 302
        },
        'export_view': {
            'editor': 200, 'reviewer': 200, 'api': 200, 'user': 403, 'anonymous': 302
        },
        'list_viewset': {
            'editor': 200, 'reviewer': 200, 'api': 200, 'user': 403, 'anonymous': 403
        },
        'retrieve_viewset': {
            'editor': 200, 'reviewer': 200, 'api': 200, 'user': 403, 'anonymous': 403
        },
        'create_viewset': {
            'editor': 201, 'reviewer': 403, 'api': 403, 'user': 403, 'anonymous': 403
        },
        'update_viewset': {
            'editor': 200, 'reviewer': 403, 'api': 403, 'user': 403, 'anonymous': 403
        },
        'delete_viewset': {
            'editor': 204, 'reviewer': 403, 'api': 403, 'user': 403, 'anonymous': 403
        }
    }

    def setUp(self):
        set_group_permissions()


class OptionsTests(TestListViewMixin, OptionsTestCase):

    url_names = {
        'list_view': 'options'
    }


class OptionSetTests(TestModelViewsetMixin, OptionsTestCase):

    instances = OptionSet.objects.all()
    url_names = {
        'viewset': 'internal-options:optionset'
    }

    def prepare_create_instance(self, instance):
        instance.key += '_new'
        return instance


class OptionTests(TestModelViewsetMixin, OptionsTestCase):

    instances = Option.objects.all()
    url_names = {
        'viewset': 'internal-options:option'
    }

    def prepare_create_instance(self, instance):
        instance.key += '_new'
        return instance


class ConditionTests(TestListViewsetMixin, TestRetrieveViewsetMixin, OptionsTestCase):

    instances = Condition.objects.all()
    url_names = {
        'viewset': 'internal-options:condition'
    }


class OptionsExportTests(TestExportViewMixin, OptionsTestCase):

    url_names = {
        'export_view': 'options_export'
    }


class OptionsImportTests(TestImportViewMixin, TestCase):

    import_file = 'testing/xml/options.xml'


class OptionSetAPITests(TestListViewsetMixin, TestRetrieveViewsetMixin, OptionsTestCase):

    instances = OptionSet.objects.all()
    url_names = {
        'viewset': 'api-v1-options:optionset'
    }


class OptionAPITests(TestListViewsetMixin, TestRetrieveViewsetMixin, OptionsTestCase):

    instances = Option.objects.all()
    url_names = {
        'viewset': 'api-v1-options:option'
    }
{'fraction_non_alphanumeric': 0.1340755082284608, 'fraction_numerical': 0.03452726686027751, 'mean_word_length': 3.1828609986504723, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '5409013', 'n_tokens_mistral': 2144, 'n_tokens_neox': 1886, 'n_words': 409}