<commit_before>import mock
import pytest
from django.contrib.auth.models import User
from rest_framework.test import APIClient
from elasticgit.tests.base import ModelBaseTest

from molo.core.tests.base import MoloTestCaseMixin
from molo.core.content_import.tests.base import ElasticGitTestMixin
from molo.core.content_import.api import Repo
from molo.core.content_import.errors import SiteResponseError


@pytest.mark.django_db
class ContentImportAPITestCase(
        ModelBaseTest, MoloTestCaseMixin, ElasticGitTestMixin):

    def setUp(self):
        self.client = APIClient()

    @mock.patch('molo.core.content_import.views.api')
    def test_get_repos(self, api):
        User.objects.create_superuser('testuser', '<EMAIL>', '1234')
        self.client.login(username='testuser', password='<PASSWORD>')

        api.get_repo_summaries = lambda: ['foo']
        resp = self.client.get('/import/repos/')

        self.assertEquals(resp.data, {'repos': ['foo']})
        self.assertEquals(resp.status_code, 200)

    @mock.patch('molo.core.content_import.views.api')
    def test_get_repos_site_response_error(self, api):
        def get_repo_summaries():
            raise SiteResponseError(':/')

        User.objects.create_superuser('testuser', '<EMAIL>', '1234')
        self.client.login(username='testuser', password='<PASSWORD>')

        api.get_repo_summaries = get_repo_summaries
        resp = self.client.get('/import/repos/')

        self.assertEquals(resp.data, {'type': 'site_response_error'})
        self.assertEquals(resp.status_code, 422)

    @mock.patch('molo.core.content_import.views.api')
    def test_get_languages(self, api):
        User.objects.create_superuser('testuser', '<EMAIL>', '1234')
        self.client.login(username='testuser', password='<PASSWORD>')
<commit_msg>Fix test names for get_repo_summaries view tests<commit_after>import mock
import pytest
from django.contrib.auth.models import User
from rest_framework.test import APIClient
from elasticgit.tests.base import ModelBaseTest

from molo.core.tests.base import MoloTestCaseMixin
from molo.core.content_import.tests.base import ElasticGitTestMixin
from molo.core.content_import.api import Repo
from molo.core.content_import.errors import SiteResponseError


@pytest.mark.django_db
class ContentImportAPITestCase(
        ModelBaseTest, MoloTestCaseMixin, ElasticGitTestMixin):

    def setUp(self):
        self.client = APIClient()

    @mock.patch('molo.core.content_import.views.api')
    def test_get_repo_summaries(self, api):
        User.objects.create_superuser('testuser', '<EMAIL>', '1234')
        self.client.login(username='testuser', password='<PASSWORD>')

        api.get_repo_summaries = lambda: ['foo']
        resp = self.client.get('/import/repos/')

        self.assertEquals(resp.data, {'repos': ['foo']})
        self.assertEquals(resp.status_code, 200)

    @mock.patch('molo.core.content_import.views.api')
    def test_get_repo_summaries_site_response_error(self, api):
        def get_repo_summaries():
            raise SiteResponseError(':/')

        User.objects.create_superuser('testuser', '<EMAIL>', '1234')
        self.client.login(username='testuser', password='<PASSWORD>')

        api.get_repo_summaries = get_repo_summaries
        resp = self.client.get('/import/repos/')

        self.assertEquals(resp.data, {'type': 'site_response_error'})
        self.assertEquals(resp.status_code, 422)

    @mock.patch('molo.core.content_import.views.api')
    def test_get_languages(self, api):
        User.objects.create_superuser('testuser', '<EMAIL>', '<PASSWORD>')
        self.client.login(username='testuser', password='<PASSWORD>')

{'fraction_non_alphanumeric': 0.12789115646258503, 'fraction_numerical': 0.008707482993197279, 'mean_word_length': 4.126917712691771, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, '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': '1877435', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1148, 'n_words': 190}