<commit_before>from nose.tools import *  # flake8: noqa

from osf.models.metaschema import MetaSchema
from website.project.metadata.schemas import LATEST_SCHEMA_VERSION

from api.base.settings.defaults import API_BASE

from tests.base import ApiTestCase
from osf_tests.factories import (
    AuthUserFactory
)


class TestMetaSchemaList(ApiTestCase):
    def setUp(self):
        super(TestMetaSchemaList, self).setUp()
        self.user = AuthUserFactory()
        self.url = '/{}metaschemas/'.format(API_BASE)

    def test_pass_authenticated_user_can_view_schemas(self):
        res = self.app.get(self.url, auth=self.user.auth)
        assert_equal(res.status_code, 200)
        assert_equal(
            len(res.json['data']),
            MetaSchema.objects.filter(active=True, schema_version=LATEST_SCHEMA_VERSION).count()
        )

    def test_cannot_update_metaschemas(self):
        res = self.app.put_json_api(self.url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 405)

    def test_cannot_post_metaschemas(self):
        res = self.app.post_json_api(self.url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 405)

    def test_pass_unauthenticated_user_can_view_schemas(self):
        res = self.app.get(self.url)
        assert_equal(res.status_code, 200)<commit_msg>Convert metaschemas list to pytest<commit_after>import pytest

from api.base.settings.defaults import API_BASE
from osf.models.metaschema import MetaSchema
from osf_tests.factories import (
    AuthUserFactory
)
from website.project.metadata.schemas import LATEST_SCHEMA_VERSION

@pytest.mark.django_db
class TestMetaSchemaList:

    @pytest.fixture()
    def user(self):
        return AuthUserFactory()

    @pytest.fixture()
    def url_metaschemas_list(self):
        return '/{}metaschemas/'.format(API_BASE)

    def test_metaschemas_list_visibility_create_update(self, app, url_metaschemas_list, user):
        #test_pass_authenticated_user_can_view_schemas
        res = app.get(url_metaschemas_list, auth=user.auth)
        assert res.status_code == 200
        assert (
            len(res.json['data']) ==
            MetaSchema.objects.filter(active=True, schema_version=LATEST_SCHEMA_VERSION).count())

        #test_cannot_update_metaschemas
        res = app.put_json_api(url_metaschemas_list, auth=user.auth, expect_errors=True)
        assert res.status_code == 405

        #test_cannot_post_metaschemas
        res = app.post_json_api(url_metaschemas_list, auth=user.auth, expect_errors=True)
        assert res.status_code == 405

        #test_pass_unauthenticated_user_can_view_schemas
        res = app.get(url_metaschemas_list)
        assert res.status_code == 200
{'fraction_non_alphanumeric': 0.09100877192982457, 'fraction_numerical': 0.009137426900584795, 'mean_word_length': 3.76, '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': '5521545', 'n_tokens_mistral': 936, 'n_tokens_neox': 892, 'n_words': 140}