def initialize_consultants(self): self.crete_certification_groups() consultants = [(4, 'Sevilla,CONSULTANT Spain', [CONSULTANT, COACH]), (2, 'London, United Kingdom', [CONSULTANT]), (6, 'Barcelona, Spain', [CONSULTANT]), (18, 'Rostock, Germany', [CONSULTANT, COACH]), (7, 'Berlin, Germany', [CONSULTANT, COACH]), (14, 'Tokyo, Japan', [CONSULTANT]), (8, 'Buenos Aires, Argentina', []), (3, 'Munich, Germany', [CONSULTANT])] for num_project, location, certified_roles in consultants: user = FakeUserFactory.create(password='******', is_active=True, location=location) consultant = FakeConsultantFactory( user=user, status=settings.CONSULTANT_STATUS_CH_ACTIVE) self.add_certifications_to_consultant(consultant, certified_roles) member = consultant.user.ecosystem_member member.num_projects = num_project member.save() self.user = user FakeConsultantFactory.create_batch( size=4, user__location='Jaen, Spain', status=settings.CONSULTANT_STATUS_CH_DISABLED) FakeConsultantFactory.create_batch( size=16, user__location='Granada, Spain', status=settings.CONSULTANT_STATUS_CH_ACTIVE)
def test_zoom_settings(self): """ Check that ZoomSettings for ZoomRoom and the related object settings are the same """ sprint = FakeSprintAutomatedFactory.create() coaches = FakeConsultantFactory.create_batch( size=3, user__is_active=True, status=settings.CONSULTANT_STATUS_CH_ACTIVE, ) for coach in coaches: ConsultantProjectRole.objects.get_or_create_consultant( user_from=self.super_user, consultant=coach, project=sprint.project_ptr, exo_role=ExORole.objects.get( code=settings.EXO_ROLE_CODE_SPRINT_COACH), ) team = FakeTeamFactory( project=sprint.project_ptr, coach=Consultant.objects.last(), ) self.assertEqual(team.settings, team.project.zoom_settings)
def create_team_api(self): coaches = FakeConsultantFactory.create_batch( size=4, user__is_active=True, status=settings.CONSULTANT_STATUS_CH_ACTIVE, ) for coach in coaches: ConsultantProjectRole.objects.get_or_create_consultant( user_from=self.super_user, consultant=coach, project=self.sprint.project_ptr, exo_role=ExORole.objects.get( code=settings.EXO_ROLE_CODE_SPRINT_COACH), ) self.client.login(username=self.super_user.username, password='******') url = reverse('api:project:team:create', kwargs={'project_id': self.sprint.project_ptr.pk}) members = [] for k in range(5): name = faker.word() email = faker.email() members.append({'short_name': name, 'email': email}) data = { 'name': faker.first_name(), 'stream': 'S', 'zoom_id': faker.word(), 'coach': coaches[0].pk, 'team_members': members, } response = self.client.post(url, data=data, format='json') return response, coaches
def test_api_create_no_members(self, task_handler): coaches = FakeConsultantFactory.create_batch( size=3, user__is_active=True, status=settings.CONSULTANT_STATUS_CH_ACTIVE, ) for coach in coaches: ConsultantProjectRole.objects.get_or_create_consultant( user_from=self.super_user, consultant=coach, project=self.sprint.project_ptr, exo_role=ExORole.objects.get( code=settings.EXO_ROLE_CODE_SPRINT_COACH), ) self.client.login(username=self.super_user.username, password='******') url = reverse('api:project:team:create', kwargs={'project_id': self.sprint.project_ptr.pk}) data = { 'name': faker.first_name(), 'stream': 'S', 'zoom_id': faker.word(), 'coach': coaches[0].pk, 'team_members': [], } response = self.client.post(url, data=data, format='json') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual( Team.objects.filter(project=self.sprint.project_ptr).count(), 1)
def test_coach_and_head_coach(self): # PREPARE DATA sprint = FakeSprintAutomatedFactory.create( category=settings.PROJECT_CH_CATEGORY_TRANSFORMATION, created_by=self.super_user) consultant_manager = FakeConsultantFactory.create( user__is_active=True, ) consultant_coaches = FakeConsultantFactory.create_batch( size=3, user__is_active=True, ) ConsultantProjectRole.objects.get_or_create_consultant( user_from=self.super_user, consultant=consultant_manager, project=sprint.project_ptr, exo_role=ExORole.objects.get( code=settings.EXO_ROLE_CODE_SPRINT_HEAD_COACH)) for coach in consultant_coaches: ConsultantProjectRole.objects.get_or_create_consultant( user_from=self.super_user, consultant=coach, project=sprint.project_ptr, exo_role=ExORole.objects.get( code=settings.EXO_ROLE_CODE_SPRINT_COACH)) self.assertEqual(self.hub.users.count(), 0, 'No users yet') # DO ACTION add_coaches_and_head_coach_as_alumni() # ASSERTS self.assertEqual(self.hub.users.count(), 4, 'No coaches/head coach added yet')
def test_settings_room(self): """ Test settings for this ZoomRoom """ sprint = FakeSprintAutomatedFactory.create() coaches = FakeConsultantFactory.create_batch( size=3, user__is_active=True, status=settings.CONSULTANT_STATUS_CH_ACTIVE, ) for coach in coaches: ConsultantProjectRole.objects.get_or_create_consultant( user_from=self.super_user, consultant=coach, project=sprint.project_ptr, exo_role=ExORole.objects.get(code=settings.EXO_ROLE_CODE_SPRINT_COACH), ) meeting_id = faker.word() team = FakeTeamFactory( project=sprint.project_ptr, coach=Consultant.objects.last(), zoom_id=meeting_id, ) self.assertEqual(team.room.meeting_object, team) self.assertEqual(team.room.meeting_id, meeting_id) self.assertEqual( team.room.zoom_settings, team.room._zoom_settings, )
def test_notifiable_consultants(self): # PREPARE DATA consultants = FakeConsultantFactory.create_batch( size=16, status=settings.CONSULTANT_STATUS_CH_ACTIVE) for consultant in consultants: consultant.user.add_django_permission( settings.EXO_ACCOUNTS_PERMS_MARKETPLACE_FULL, ) param = ConfigParam.objects.get(name='new_open_opportunity') param.set_value_for_agent(consultants[0], False) param.set_value_for_agent(consultants[1], False) param.set_value_for_agent(consultants[1], True) param.set_value_for_agent(consultants[1], False) param.set_value_for_agent(consultants[2], True) self.consultants_not_active = consultants[0:2] consultant_not_activated = consultants[3] param.set_value_for_agent(consultant_not_activated, True) user = consultant_not_activated.user user.is_active = False user.save() url = reverse('api:accounts:user-can-receive-opportunities') # DO ACTION response = self.client.get(url, HTTP_USERNAME=settings.AUTH_SECRET_KEY) # ASSERTS data = response.json() self.assertTrue(status.is_success(response.status_code)) self.assertEqual(len(data), 13) param = ConfigParam.objects.get( name='new_open_opportunity') emails_not_active = [d.user.email for d in self.consultants_not_active] for result in data: consultant = Consultant.objects.get( user__email=result['email']) self.assertTrue(param.get_value_for_agent(consultant)) self.assertFalse(result['email'] in emails_not_active)
def test_api_edit_team(self, task_handler): # edit a team changing the coach to team members self.sprint.project_ptr.launch(self.super_user) coaches = FakeConsultantFactory.create_batch( size=4, user__is_active=True, status=settings.CONSULTANT_STATUS_CH_ACTIVE, ) for coach in coaches: ConsultantProjectRole.objects.get_or_create_consultant( user_from=self.super_user, consultant=coach, project=self.sprint.project_ptr, exo_role=ExORole.objects.get( code=settings.EXO_ROLE_CODE_SPRINT_COACH), ) self.client.login(username=self.super_user.username, password='******') url = reverse('api:project:team:create', kwargs={'project_id': self.sprint.project_ptr.pk}) members = [] for k in range(2): name = faker.word() email = faker.email() members.append({'short_name': name, 'email': email}) for k in coaches[1:]: members.append({ 'short_name': k.user.short_name, 'email': k.user.email, }) data = { 'name': faker.first_name(), 'stream': 'S', 'zoom_id': faker.word(), 'coach': coaches[0].pk, 'team_members': members, } response = self.client.post(url, data=data, format='json') team = Team.objects.filter(project=self.sprint.project_ptr)[0] url = reverse( 'api:project:team:edit', kwargs={ 'project_id': self.sprint.project_ptr.pk, 'pk': team.pk, }, ) members.append({ 'short_name': coaches[0].user.short_name, 'email': coaches[0].user.email, }) response = self.client.put(url, data=data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) team.refresh_from_db() self.assertEqual( Team.objects.filter_by_project( self.sprint.project_ptr, ).filter_by_user( self.sprint.project_ptr, coaches[0].user, ).count(), 1, ) data['coach'] = coaches[1].pk response = self.client.put(url, data=data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual( Team.objects.filter_by_project( self.sprint.project_ptr, ).filter_by_user( self.sprint.project_ptr, coaches[0].user, ).count(), 1, )