<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright 2017 EMBL - European Bioinformatics Institute
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest

from model_mommy import mommy

from django.core.urlresolvers import reverse
from django.urls.exceptions import NoReverseMatch

from rest_framework import status

# import fixtures
from test_utils.emg_fixtures import *  # noqa


class TestDefaultAPI(object):

    def test_default(self, client, api_version):
        url = reverse('emgapi:api-root')
        response = client.get(url)
        assert response.status_code == status.HTTP_200_OK
        rsp = response.json()

        host = "http://testserver/%s" % api_version
        expected = {
            "biomes": "%s/biomes" % host,
            "studies": "%s/studies" % host,
            "samples": "%s/samples" % host,
            "runs": "%s/runs" % host,
            "pipelines": "%s/pipelines" % host,
            "experiment-types": "%s/experiment-types" % host,
            "publications": "%s/publications" % host,
            "pipeline-tools": "%s/pipeline-tools" % host,
            "annotations/go-terms": "%s/annotations/go-terms" % host,
            "annotations/interpro-identifiers":
                "%s/annotations/interpro-identifiers" % host,
            "mydata": "%s/mydata" % host,
        }
        assert rsp['data'] == expected

    @pytest.mark.parametrize(
        '_view',
        [
            'emgapi:biomes',
            'emgapi:experiment-types',
            'emgapi:pipelines',
            'emgapi:publications',
            'emgapi:samples',
            'emgapi:runs',
            'emgapi:studies',
            'emgapi:pipeline-tools',
            pytest.mark.xfail('viewdoesnotexist', raises=NoReverseMatch),
        ]
    )
    @pytest.mark.django_db
    def test_empty_list(self, client, _view):
        view_name = "%s-list" % _view
        url = reverse(view_name)
        response = client.get(url)
        assert response.status_code == status.HTTP_200_OK
        rsp = response.json()
        assert rsp['meta']['pagination']['page'] == 1
        assert rsp['meta']['pagination']['pages'] == 1
        assert rsp['meta']['pagination']['count'] == 0

    @pytest.mark.parametrize(
        '_model, _camelcase, _view, _view_args, relations',
        [
            ('ExperimentType', 'experiment-types', 'emgapi:experiment-types',
             [], ['samples']),<commit_msg>update default tests<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright 2017 EMBL - European Bioinformatics Institute
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest

from model_mommy import mommy

from django.core.urlresolvers import reverse
from django.urls.exceptions import NoReverseMatch

from rest_framework import status

# import fixtures
from test_utils.emg_fixtures import *  # noqa


class TestDefaultAPI(object):

    def test_default(self, client, api_version):
        url = reverse('emgapi:api-root')
        response = client.get(url)
        assert response.status_code == status.HTTP_200_OK
        rsp = response.json()

        host = "http://testserver/%s" % api_version
        expected = {
            "biomes": "%s/biomes" % host,
            "studies": "%s/studies" % host,
            "samples": "%s/samples" % host,
            "runs": "%s/runs" % host,
            "pipelines": "%s/pipelines" % host,
            "experiment-types": "%s/experiment-types" % host,
            "publications": "%s/publications" % host,
            "pipeline-tools": "%s/pipeline-tools" % host,
            "annotations/go-terms": "%s/annotations/go-terms" % host,
            "annotations/interpro-identifiers":
                "%s/annotations/interpro-identifiers" % host,
            "annotations/organisms": "%s/annotations/organisms" % host,
            "mydata": "%s/mydata" % host,
        }
        assert rsp['data'] == expected

    @pytest.mark.parametrize(
        '_view',
        [
            'emgapi:biomes',
            'emgapi:experiment-types',
            'emgapi:pipelines',
            'emgapi:publications',
            'emgapi:samples',
            'emgapi:runs',
            'emgapi:studies',
            'emgapi:pipeline-tools',
            'emgapi:goterms',
            'emgapi:interproidentifier',
            'emgapi:organisms',
            pytest.mark.xfail('viewdoesnotexist', raises=NoReverseMatch),
        ]
    )
    @pytest.mark.django_db
    def test_empty_list(self, client, _view):
        view_name = "%s-list" % _view
        url = reverse(view_name)
        response = client.get(url)
        assert response.status_code == status.HTTP_200_OK
        rsp = response.json()
        assert rsp['meta']['pagination']['page'] == 1
        assert rsp['meta']['pagination']['pages'] == 1
        assert rsp['meta']['pagination']['count'] == 0

    @pytest.mark.parametrize(
        '_model, _camelcase, _view, _view_args, relations',
        [
            ('ExperimentType', 'experiment-types', 'emgapi:experiment-types',
             [], ['samples']),
{'fraction_non_alphanumeric': 0.12776129244971976, 'fraction_numerical': 0.005934718100890208, 'mean_word_length': 2.533488642981945, 'pattern_counts': {'":': 23, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3290879', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1788, 'n_words': 437}