def initialize_team_users(self):
        team = self.project.teams.first()

        users = [{
            'name': faker.name(),
            'email': faker.email()
        } for _ in range(TOTAL_PARTICIPANTS)]
        for user in users:
            user_data = {
                'name': user['name'],
                'email': user['email'],
                'team': team,
                'project': self.project
            }
            UserProjectRole.objects.create_participant(**user_data)
        for _ in range(TOTAL_COACH):
            user = self.get_user()
            request_mock_account.add_mock(user,
                                          is_consultant=False,
                                          is_superuser=False)
            user_data = {
                'user':
                user,
                'project_role':
                self.project.project_roles.get(
                    code=settings.EXO_ROLE_CODE_SPRINT_COACH),
                'team':
                team,
            }
            UserProjectRole.objects.create(**user_data)
        return team
 def setUpTestData(cls):
     cls.create_super_user(cls)
     request_mock_account.reset()
     request_mock_account.add_mock(
         cls.super_user, is_consultant=False, is_superuser=True)
     cls.project = FakeProjectFactory.create(created_by=cls.super_user)
     cls.team = cls.project.teams.first()
    def test_assign_users_to_team(self, mock_request):
        # PREPARE DATA
        users = [{
            'name': faker.name(),
            'email': faker.email()
        } for _ in range(TOTAL_PARTICIPANTS)]
        for user in users:
            user_data = {
                'name': user['name'],
                'email': user['email'],
                'project': self.project
            }
            UserProjectRole.objects.create_participant(**user_data)
        for _ in range(TOTAL_COACH):
            user = self.get_user()
            request_mock_account.add_mock(user,
                                          is_consultant=False,
                                          is_superuser=False)
            user_data = {
                'user':
                user,
                'project_role':
                self.project.project_roles.get(
                    code=settings.EXO_ROLE_CODE_SPRINT_COACH),
            }
            UserProjectRole.objects.create(**user_data)
        team = self.project.teams.first()

        url = reverse('api:project-team-assign-users',
                      kwargs={
                          'project_pk': self.project.pk,
                          'pk': team.pk
                      })

        self.setup_credentials(self.super_user)
        data = {
            'project_roles':
            UserProjectRole.objects.filter(
                project_role__project=self.project).values_list(
                    'project_role__exo_role__code', flat=True)
        }

        # DO ACTION
        response = self.client.post(url, data=data)

        # ASSERTS
        self.assertTrue(status.is_success(response.status_code))
        self.assertEqual(team.members.count(), TOTAL_USERS)
    def test_add_coach(self, mock_request):
        # PREPARE DATA
        self.init_mock(mock_request)
        team = self.initialize_team_users()
        user = self.get_user()
        request_mock_account.add_mock(user,
                                      is_consultant=False,
                                      is_superuser=False)
        user_data = {
            'user':
            user,
            'project_role':
            self.project.project_roles.get(
                code=settings.EXO_ROLE_CODE_SPRINT_COACH)
        }
        UserProjectRole.objects.create(**user_data)
        data = {
            'user': user.uuid.__str__(),
            'team_role': settings.EXO_ROLE_CODE_SPRINT_COACH
        }
        url = reverse('api:project-team-add-user',
                      kwargs={
                          'project_pk': self.project.pk,
                          'pk': team.pk
                      })
        self.setup_credentials(self.super_user)

        # DO ACTION
        response = self.client.post(url, data=data)

        # ASSERTS
        self.assertTrue(status.is_success(response.status_code))
        data = response.json()
        self.assertEqual(team.members.count(), TOTAL_USERS + 1)
        self.assertEqual(team.participants.count(), TOTAL_PARTICIPANTS)
        self.assertEqual(team.coaches.count(), TOTAL_COACH + 1)
        self.assertEqual(
            team.user_team_roles.filter(
                team_role__code=settings.EXO_ROLE_CODE_SPRINT_COACH).count(),
            2)
        self.assertEqual(
            team.user_team_roles.filter(
                team_role__code=settings.EXO_ROLE_CODE_SPRINT_PARTICIPANT).
            count(), TOTAL_PARTICIPANTS)
Ejemplo n.º 5
0
    def init_project(cls):
        head_coach_role = cls.project.project_roles.get(
            code=settings.EXO_ROLE_CODE_SPRINT_HEAD_COACH)
        coach_role = cls.project.project_roles.get(
            code=settings.EXO_ROLE_CODE_SPRINT_COACH)

        user_hc = cls.get_user(cls)
        request_mock_account.add_mock(user_hc,
                                      is_consultant=False,
                                      is_superuser=False)
        models.UserProjectRole.objects.create(project_role=head_coach_role,
                                              user=user_hc)
        user_coach = cls.get_user(cls)
        request_mock_account.add_mock(user_coach,
                                      is_consultant=False,
                                      is_superuser=False)
        models.UserProjectRole.objects.create(project_role=coach_role,
                                              teams=cls.project.teams.all(),
                                              user=user_coach)
        users_participants = []
        for team in cls.project.teams.all():
            user_role = models.UserProjectRole.objects.create_participant(
                project=cls.project,
                teams=[team],
                name=faker.name(),
                email=faker.email())
            request_mock_account.add_mock(user_role.user,
                                          is_consultant=False,
                                          is_superuser=False)
            users_participants.append(user_role.user)
        cls.user_coach = user_coach
        cls.user_hc = user_hc
        cls.users_participants = users_participants
Ejemplo n.º 6
0
    def test_adding_users(self, mock_request):
        # PREPARE DATA
        TOTAL_GROUPS = 6
        TOTAL_USERS = 8
        TOTAL_COLLABORATORS = 4
        self.init_mock(mock_request)
        initialize_groups_for_project(self.project, self.project.created_by)
        head_coach_role = self.project.project_roles.get(
            code=settings.EXO_ROLE_CODE_SPRINT_HEAD_COACH)
        coach_role = self.project.project_roles.get(
            code=settings.EXO_ROLE_CODE_SPRINT_COACH)

        # DO ACTION
        user_hc = self.get_user()
        request_mock_account.add_mock(user_hc,
                                      is_consultant=False,
                                      is_superuser=False)
        models.UserProjectRole.objects.create(project_role=head_coach_role,
                                              user=user_hc)
        user_coach = self.get_user()
        request_mock_account.add_mock(user_coach,
                                      is_consultant=False,
                                      is_superuser=False)
        models.UserProjectRole.objects.create(project_role=coach_role,
                                              teams=self.project.teams.all(),
                                              user=user_coach)

        # ASSERTS
        self.assertEqual(self.project.groups.count(), TOTAL_GROUPS)
        self.assertEqual(
            self.project.groups.get(
                group_type=settings.COMMUNICATION_CH_GENERAL).users.count(),
            TOTAL_USERS)
        self.assertEqual(
            self.project.groups.get(
                group_type=settings.COMMUNICATION_CH_COLLABORATORS).users.
            count(), TOTAL_COLLABORATORS)
        for team in self.project.teams.all():
            self.assertEqual(team.group.users.count(), 5)
Ejemplo n.º 7
0
 def setUp(self):
     super().setUp()
     request_mock_account.reset()
     request_mock_account.add_mock(self.super_user,
                                   is_consultant=False,
                                   is_superuser=True)