<commit_before>from django.contrib.auth.models import Permission
from main.tests.test_base import MainTestCase
from api.models import Team, OrganizationProfile
from api.utils import create_organization, add_user_to_team
from api.utils import create_organization_team


class TestModels(MainTestCase):
    def test_create_organization_creates_team_and_perms(self):
        # create a user - bob
        profile = create_organization("modilabs", self.user)
        self.assertIsInstance(profile, OrganizationProfile)
        organization_profile = OrganizationProfile.objects.get(
            user__username="modilabs")

        # check organization was created
        self.assertTrue(organization_profile.is_organization)

        # check that the default team was created
        team_name = "modilabs#%s" % Team.OWNER_TEAM_NAME
        team = Team.objects.get(
            organization=organization_profile.user, name=team_name)
        self.assertIsInstance(team, Team)
        self.assertIn(team.group_ptr, self.user.groups.all())
        self.assertTrue(self.user.has_perm('api.is_org_owner'))

    def test_create_organization_team(self):
        profile = create_organization("modilabs", self.user)
        organization = profile.user
        team_name = 'dev'
        perms = ['is_org_owner', ]
        create_organization_team(organization, team_name, perms)
        team_name = "modilabs#%s" % team_name
        dev_team = Team.objects.get(organization=organization, name=team_name)
        self.assertIsInstance(dev_team, Team)
        self.assertIsInstance(
            dev_team.permissions.get(codename='is_org_owner'), Permission)

    def test_assign_user_to_team(self):
        # create the organization
        profile = create_organization("modilabs", self.user)
        organization = profile.user
        user_deno = self._create_user('deno', 'deno')

        # create another team
        team_name = 'managers'
        team = create_organization_team(
            organization, team_name)
        add_user_to_team(team, user_deno)
        self.assertIn(team.group_ptr, user_deno.groups.all())<commit_msg>tests helper function to create an organization<commit_after>from django.contrib.auth.models import Permission
from main.tests.test_base import MainTestCase
from api.models import Team, OrganizationProfile
from api.utils import create_organization, add_user_to_team
from api.utils import create_organization_team


class TestModels(MainTestCase):
    def test_create_organization_creates_team_and_perms(self):
        # create a user - bob
        profile = create_organization("modilabs", self.user)
        self.assertIsInstance(profile, OrganizationProfile)
        organization_profile = OrganizationProfile.objects.get(
            user__username="modilabs")

        # check organization was created
        self.assertTrue(organization_profile.is_organization)

        # check that the default team was created
        team_name = "modilabs#%s" % Team.OWNER_TEAM_NAME
        team = Team.objects.get(
            organization=organization_profile.user, name=team_name)
        self.assertIsInstance(team, Team)
        self.assertIn(team.group_ptr, self.user.groups.all())
        self.assertTrue(self.user.has_perm('api.is_org_owner'))

    def test_create_organization_team(self):
        profile = create_organization("modilabs", self.user)
        organization = profile.user
        team_name = 'dev'
        perms = ['is_org_owner', ]
        create_organization_team(organization, team_name, perms)
        team_name = "modilabs#%s" % team_name
        dev_team = Team.objects.get(organization=organization, name=team_name)
        self.assertIsInstance(dev_team, Team)
        self.assertIsInstance(
            dev_team.permissions.get(codename='is_org_owner'), Permission)

    def _create_organization(self, org_name, user):
        profile = create_organization(org_name, user)
        self.organization = profile.user
        return self.organization

    def test_assign_user_to_team(self):
        # create the organization
        organization = self._create_organization("modilabs", self.user)
        user_deno = self._create_user('deno', 'deno')

        # create another team
        team_name = 'managers'
        team = create_organization_team(organization, team_name)
        add_user_to_team(team, user_deno)
        self.assertIn(team.group_ptr, user_deno.groups.all())
{'fraction_non_alphanumeric': 0.08489501016030707, 'fraction_numerical': 0.0, 'mean_word_length': 3.4211576846307383, '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': '7023823', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1228, 'n_words': 239}