def test_create_supervisor(self): # PREPARE DATA project = FakeProjectFactory.create(status=settings.PROJECT_CH_PROJECT_STATUS_WAITING) project_settings = project.settings project_settings.launch['fix_password'] = '******' project_settings.save() # DO ACTION member = project.add_user_project_supervisor(self.super_user, faker.name(), faker.email()) # ASSERTS self.assertTrue(member.check_password('123456')) self.assertTrue(member.has_perm(settings.PROJECT_PERMS_VIEW_PROJECT, project)) self.assertTrue(member.has_perm(settings.PROJECT_PERMS_ONLY_VIEW_PROJECT, project)) FakeTeamFactory.create_batch(size=3, project=project, user_from=self.super_user) teams = Team.objects.filter_by_project(project).filter_by_user(project, member) self.assertEqual(teams.count(), 3)
def test_create_reporter(self): # PREPARE DATA project = FakeProjectFactory.create(status=settings.PROJECT_CH_PROJECT_STATUS_WAITING) FakeTeamFactory.create_batch(size=3, project=project) # DO ACTION relation, _ = ConsultantProjectRole.objects.get_or_create_consultant( user_from=self.super_user, project=project, status=settings.RELATION_ROLE_CH_ACTIVE, consultant=FakeConsultantFactory.create(user__is_active=True), exo_role=ExORole.objects.get(code=settings.EXO_ROLE_CODE_SPRINT_REPORTER) ) # ASSERTS member = relation.consultant.user self.assertTrue(member.has_perm(settings.PROJECT_PERMS_VIEW_PROJECT, project)) self.assertTrue(member.has_perm(settings.PROJECT_PERMS_ONLY_VIEW_PROJECT, project)) teams = Team.objects.filter_by_project(project).filter_by_user(project, member) self.assertEqual(teams.count(), 3)
def test_get_team_for_user(self): manager1 = FakeConsultantFactory.create(user__is_active=True) manager2 = FakeConsultantFactory.create(user__is_active=True) sprint = FakeSprintAutomatedFactory.create() sprint2 = FakeSprintAutomatedFactory.create() FakeConsultantProjectRoleFactory( consultant=manager1, project=sprint.project_ptr, exo_role=ExORole.objects.get( code=settings.EXO_ROLE_CODE_SPRINT_COACH), status=settings.RELATION_ROLE_CH_ACTIVE, ) FakeConsultantProjectRoleFactory( consultant=manager2, project=sprint2.project_ptr, exo_role=ExORole.objects.get( code=settings.EXO_ROLE_CODE_SPRINT_COACH), status=settings.RELATION_ROLE_CH_ACTIVE, ) coach1 = FakeConsultantFactory.create(user__is_active=True) teams_1 = FakeTeamFactory.create_batch( size=3, user_from=self.super_user, project=sprint.project_ptr, ) teams_2 = FakeTeamFactory.create_batch( size=2, user_from=self.super_user, project=sprint2.project_ptr, coach=coach1, ) sprint.project_ptr.launch(self.super_user) sprint2.project_ptr.launch(self.super_user) self.assertEqual( get_team_for_user( sprint.project_ptr, self.super_user, ).count(), 3, ) self.assertEqual( get_team_for_user( sprint2.project_ptr, self.super_user, ).count(), 2, ) self.assertEqual( get_team_for_user( sprint.project_ptr, manager2.user, ).count(), 0, ) self.assertEqual( get_team_for_user( sprint2.project_ptr, manager1.user, ).count(), 0, ) self.assertEqual( get_team_for_user( sprint.project_ptr, teams_1[0].coach.user, ).count(), 1, ) self.assertEqual( get_team_for_user( sprint.project_ptr, teams_1[0].coach.user, ).count(), 1, ) self.assertEqual( get_team_for_user( sprint2.project_ptr, coach1.user, ).count(), 2, ) member1 = teams_1[0].add_member( user_from=self.super_user, name=faker.first_name(), email=faker.email(), ) member2 = teams_2[0].add_member( user_from=self.super_user, name=faker.first_name(), email=faker.email(), ) self.assertEqual( get_team_for_user( sprint.project_ptr, member1, ).count(), 1, ) self.assertEqual( get_team_for_user( sprint2.project_ptr, member2, ).count(), 1, )