<commit_before>import pytest

from django.contrib.auth.models import User

from unicoremc.tests.base import UnicoremcTestCase
from unicoremc.models import Project, AppType


@pytest.mark.django_db
class ModelsTestCase(UnicoremcTestCase):
    fixtures = ['test_users.json', 'test_social_auth.json']

    def setUp(self):
        self.user = User.objects.get(username='testuser')

    def test_app_type_title(self):
        app_type = AppType._for('gem', 'Girl Effect', 'unicore-cms')
        self.assertEquals(str(app_type), 'Girl Effect (unicore-cms)')

    def test_project_app_type(self):
        app_type = AppType._for('gem', 'Girl Effect', 'unicore-cms')

        p = Project(
            base_repo_url='http://some-git-repo.com',
            country='ZA',
            owner=self.user)
        p.save()

        self.assertEquals(p.app_type, '')

        p = Project(
            application_type=app_type,
            base_repo_url='http://some-git-repo.com',
            country='ZA',
            owner=self.user)
        p.save()

        self.assertEquals(p.app_type, 'gem')<commit_msg>fix up model tests<commit_after>import pytest

from django.core.exceptions import MultipleObjectsReturned
from django.contrib.auth.models import User

from unicoremc.tests.base import UnicoremcTestCase
from unicoremc.models import Project, AppType, ProjectRepo


@pytest.mark.django_db
class ModelsTestCase(UnicoremcTestCase):
    fixtures = ['test_users.json', 'test_social_auth.json']

    def setUp(self):
        self.user = User.objects.get(username='testuser')

    def test_app_type_title(self):
        app_type = AppType._for('gem', 'Girl Effect', 'unicore-cms')
        self.assertEquals(str(app_type), 'Girl Effect (unicore-cms)')

    def test_project_app_type(self):
        app_type = AppType._for('gem', 'Girl Effect', 'unicore-cms')

        p = Project(
            country='ZA',
            owner=self.user)
        p.save()

        self.assertEquals(p.app_type, '')

        p = Project(
            application_type=app_type,
            country='ZA',
            owner=self.user)
        p.save()

        self.assertEquals(p.app_type, 'gem')

    def test_get_repo_attributes(self):
        app_type = AppType._for('gem', 'Girl Effect', 'unicore-cms')
        project = Project.objects.create(
            application_type=app_type,
            country='ZA',
            owner=self.user)
        repo = ProjectRepo.objects.create(
            project=project,
            base_url='http://some-git-repo.com',
            url='http://some-git-repo-clone.com',
            git_url='git://some-git-repo-clone.com')

        self.assertEqual(project.base_repo_url, repo.base_url)
        self.assertEqual(project.repo_url, repo.url)
        self.assertEqual(project.repo_git_url, repo.git_url)

        ProjectRepo.objects.create(
            project=project,
            base_url='http://some-git-repo2.com',
            url='http://some-git-repo2-clone.com',
            git_url='git://some-git-repo2-clone.com')

        with self.assertRaises(MultipleObjectsReturned):
            project.base_repo_url
{'fraction_non_alphanumeric': 0.12564102564102564, 'fraction_numerical': 0.0009615384615384616, 'mean_word_length': 2.6039260969976907, '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': '6487911', 'n_tokens_mistral': 992, 'n_tokens_neox': 963, 'n_words': 155}