def test_actives_filter(self): project = FakeProjectFactory() consultant_1 = FakeConsultantFactory(user__is_active=True) consultant_2 = FakeConsultantFactory(user__is_active=True) self.assertTrue(consultant_1.user.is_active) self.assertTrue(consultant_2.user.is_active) # Create another project to check filter relation_p_1 = FakeConsultantProjectRoleFactory( consultant=consultant_1, project=project, status=settings.RELATION_ROLE_CH_ACTIVE, ) self.assertIsNotNone(relation_p_1) relation_p_2 = FakeConsultantProjectRoleFactory( consultant=consultant_2, project=project, status=settings.RELATION_ROLE_CH_INACTIVE, ) self.assertIsNotNone(relation_p_2) # ## # Work with self.project # ## relation_1 = FakeConsultantProjectRoleFactory( consultant=consultant_1, project=self.project, status=settings.RELATION_ROLE_CH_ACTIVE, ) self.assertIsNotNone(relation_1) relation_2 = FakeConsultantProjectRoleFactory( consultant=consultant_2, project=self.project, status=settings.RELATION_ROLE_CH_INACTIVE, ) self.assertIsNotNone(relation_2) self.assertEqual(self.project.consultants_roles.actives().count(), 1) self.assertEqual(ConsultantProjectRole.objects.actives().count(), 2) relation_2.activate(consultant_2.user) self.assertEqual(self.project.consultants_roles.count(), 2) self.assertEqual(self.project.consultants_roles.actives().count(), 2) self.assertEqual(ConsultantProjectRole.objects.actives().count(), 3) self.assertEqual(ConsultantProjectRole.objects.count(), 4)
def test_coach_consultant_change(self): sprint = FakeSprintAutomatedFactory(status=settings.PROJECT_CH_PROJECT_STATUS_STARTED) consultant = FakeConsultantFactory(user__is_active=True) consultant2 = FakeConsultantFactory(user__is_active=True) ConsultantProjectRole.objects.get_or_create_consultant( user_from=self.super_user, consultant=consultant2, project=sprint.project_ptr, exo_role=ExORole.objects.get(code=settings.EXO_ROLE_CODE_SPRINT_COACH), ) new_team = Team.objects.create( project=sprint.project_ptr, user_from=self.super_user, created_by=self.super_user, name=faker.name(), coach=consultant, stream=settings.PROJECT_STREAM_CH_STRATEGY, ) member = consultant.user self.assertTrue(member.has_perm( settings.TEAM_PERMS_FULL_VIEW_TEAM, new_team, )) self.assertTrue(member.has_perm( settings.TEAM_PERMS_COACH_TEAM, new_team, )) new_team.update_coach( self.super_user, consultant2, ) member2 = consultant2.user self.assertFalse(member.has_perm( settings.TEAM_PERMS_FULL_VIEW_TEAM, new_team, )) self.assertFalse(member.has_perm( settings.TEAM_PERMS_COACH_TEAM, new_team, )) self.assertTrue(member2.has_perm( settings.TEAM_PERMS_FULL_VIEW_TEAM, new_team, )) self.assertTrue(member2.has_perm( settings.TEAM_PERMS_COACH_TEAM, new_team, )) self.assertTrue(member.has_perm( settings.PROJECT_PERMS_VIEW_PROJECT, new_team.project, ))
def test_ecosystem_filters(self): # PREPARE DATA consultant = FakeConsultantFactory(user=self.user) url = reverse('api:ecosystem:filters') outputs = [ filters.get_industries_filter_data(), filters.get_attributes_filter_data(), filters.get_roles_filter_data(), filters.get_activities_filter_data(), filters.get_technologies_filter_data(), filters.get_languages_filter_data(), filters.get_location_filter_data(), filters.get_certifications_filter_data(), ] # DO ACTION self.client.login(username=consultant.user.username, password='******') response = self.client.get(url) # ASSERTS index = 0 self.assertTrue(status.is_success(response.status_code)) for data in response.json(): self.assertEqual(data.get('title'), outputs[index].get('title')) self.assertEqual(data.get('queryparam'), outputs[index].get('queryparam')) self.assertEqual(data.get('multiselect'), outputs[index].get('multiselect')) self.assertEqual(len(data.get('items')), len(outputs[index].get('items'))) index += 1
def test_permissions_when_delete_consultant_as_coach_from_team(self): """ Check permissions for a Consultor that is Collaborator and Coach and is deleted as Coach """ new_consultant = FakeConsultantFactory(status=settings.CONSULTANT_STATUS_CH_ACTIVE) ConsultantProjectRole.objects.get_or_create_consultant( user_from=self.super_user, consultant=new_consultant, project=self.sprint.project_ptr, exo_role=ExORole.objects.get(code=settings.EXO_ROLE_CODE_SPRINT_COACH), ) new_team = FakeTeamFactory( project=self.sprint.project_ptr, coach=self.consultant, ) new_team.update_coach( user_from=self.super_user, coach=new_consultant, ) self.assertFalse(self.consultant.user.has_perm( settings.TEAM_PERMS_COACH_TEAM, new_team, ))
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_create_team_invitations_with_members(self): member_list = [{ 'email': faker.email(), 'short_name': faker.name() } for _ in range(2)] sprint = FakeSprintAutomatedFactory( status=settings.PROJECT_CH_PROJECT_STATUS_WAITING) project = sprint.project_ptr coach = FakeConsultantFactory(user__is_active=True) ConsultantProjectRole.objects.get_or_create_consultant( user_from=self.super_user, consultant=coach, project=project, exo_role=ExORole.objects.get( code=settings.EXO_ROLE_CODE_SPRINT_COACH), ) team = Team.objects.create( user_from=self.super_user, created_by=self.super_user, project=project, name=faker.name(), coach=coach, stream=settings.PROJECT_STREAM_CH_STARTUP, team_members=member_list, ) self.assertIsNotNone(team) self.assertEqual( Invitation.objects.filter( type=settings.INVITATION_TYPE_TEAM).count(), 3, )
def setUp(self): self.consultant = FakeConsultantFactory() self.agreement = FakeAgreementFactory( status=settings.AGREEMENT_STATUS_ACTIVE, recipient=settings.AGREEMENT_RECIPIENT_CONSULTANT, domain=settings.AGREEMENT_DOMAIN_CH_TOS, )
def test_post_save_consultant(self): # DO ACTION consultant = FakeConsultantFactory( user=self.user, status=settings.CONSULTANT_STATUS_CH_ACTIVE) # ASSERTS self.assertTrue(Member.objects.filter(user=consultant.user).exists())
def setUp(self): self.create_superuser() self.create_user() self.sprint = FakeSprintAutomatedFactory.create( status=settings.PROJECT_CH_PROJECT_STATUS_WAITING) self.team = FakeTeamFactory.create( coach=FakeConsultantFactory.create( user=self.user, status=settings.CONSULTANT_STATUS_CH_ACTIVE, ), project=self.sprint.project_ptr, ) for k in range(3): self.team.add_member(self.super_user, email=faker.email(), name=faker.name()) self.project = self.sprint.project_ptr self.head_role = FakeConsultantProjectRoleFactory.create( project=self.project, consultant=FakeConsultantFactory(user__is_active=True), exo_role=ExORole.objects.get( code=settings.EXO_ROLE_CODE_SPRINT_HEAD_COACH), status=settings.RELATION_ROLE_CH_ACTIVE, ) self.coach_role = self.project.consultants_roles.get( consultant=self.team.coach)
def test_managers_added_as_participant_removed(self): # PREPARE DATA super_user = FakeUserFactory(is_superuser=True) self.sprint.launch(super_user) project = self.sprint.project_ptr consultant = FakeConsultantFactory( status=settings.CONSULTANT_STATUS_CH_ACTIVE, ) FakeConsultantProjectRoleFactory( consultant=consultant, project=project, status=settings.RELATION_ROLE_CH_ACTIVE, exo_role=ExORole.objects.get(code=settings.EXO_ROLE_CODE_SPRINT_HEAD_COACH), ) new_team = FakeTeamFactory.create(project=project) new_team.add_member( user_from=super_user, email=consultant.user.email, name=consultant.user.short_name, ) # DO ACTION new_team.remove_member(super_user, consultant.user) # ASSERTS self.assertTrue( consultant.user.has_perm( settings.PROJECT_PERMS_VIEW_PROJECT, new_team.project, )) self.assertTrue( consultant.user.has_perm( settings.EXO_ACCOUNTS_PERMS_USER_EDIT, consultant.user, ))
def test_api_participant_questions(self): # PREPARE DATA exo_consulting = ExOActivity.objects.get( code=settings.EXO_ACTIVITY_CH_ACTIVITY_CONSULTING) consultant = FakeConsultantFactory(user__is_active=True) exo_activity, _ = consultant.exo_profile.exo_activities.get_or_create( exo_activity=exo_consulting) exo_activity.enable() expected_followers = Consultant.objects.filter_consulting_enabled( ).count() url = reverse( 'api:circles:followers', kwargs={'slug': settings.CIRCLES_QUESTIONS_PROJECTS_SLUG}) self.client.login(username=consultant.user.username, password=consultant.user.short_name) # ACTIONS response = self.client.get(url) # ASSERTIONS self.assertTrue(status.is_success(response.status_code)) data = response.json() self.assertEqual(data.get('count'), expected_followers)
def test_manager_can_edit_participants_profile(self): team = FakeTeamFactory.create(project=self.project) member = team.add_member( user_from=self.super_user, email=faker.email(), name=faker.name(), ) relation, _ = ConsultantProjectRole.objects.get_or_create_consultant( user_from=self.super_user, project=team.project, consultant=FakeConsultantFactory(user__is_active=True), exo_role=ExORole.objects.get( code=settings.EXO_ROLE_CODE_SPRINT_HEAD_COACH), ) self.assertTrue( relation.consultant.user.has_perm( settings.EXO_ACCOUNTS_PERMS_USER_EDIT, member)) # add a new member member2 = team.add_member( user_from=relation.consultant.user, email=faker.email(), name=faker.name(), ) has_perm = relation.consultant.user.has_perm( settings.EXO_ACCOUNTS_PERMS_USER_EDIT, member2) self.assertTrue(has_perm) team.remove_member(relation.consultant.user, member2) self.assertFalse( relation.consultant.user.has_perm( settings.EXO_ACCOUNTS_PERMS_USER_EDIT, member2))
def test_ecosytem_member_created_signal(self, patch_signal): # DO ACTION FakeConsultantFactory( user=self.user, status=settings.CONSULTANT_STATUS_CH_ACTIVE) # ASSERTS self.assertEqual(patch_signal.call_count, 1)
def setUp(self): super().setUp() self.create_superuser() self.consultant = FakeConsultantFactory(status=settings.CONSULTANT_STATUS_CH_ACTIVE) self.sprint = FakeSprintAutomatedFactory(status=settings.PROJECT_CH_PROJECT_STATUS_STARTED) # Sprint Teams self.team_s_a = FakeTeamFactory.create(project=self.sprint.project_ptr) self.team_s_b = FakeTeamFactory.create(project=self.sprint.project_ptr)
def setUp(self): super().setUp() self.create_user() self.create_superuser() self.consultant = FakeConsultantFactory( user=self.user, status=settings.CONSULTANT_STATUS_CH_ACTIVE) self.client.login( username=self.consultant.user.username, password='******')
def test_manager_sprint(self): consultant = FakeConsultantFactory( status=settings.CONSULTANT_STATUS_CH_ACTIVE, ) FakeConsultantProjectRoleFactory( consultant=consultant, project=self.sprint.project_ptr, status=settings.RELATION_ROLE_CH_ACTIVE, exo_role=ExORole.objects.get(code=settings.EXO_ROLE_CODE_SPRINT_HEAD_COACH), ) self.assertTrue(consultant.user.has_perm(settings.PROJECT_PERMS_PROJECT_MANAGER, self.sprint.project_ptr))
def test_project_collaborator(self): consultant = FakeConsultantFactory( status=settings.CONSULTANT_STATUS_CH_ACTIVE, ) FakeConsultantProjectRoleFactory( consultant=consultant, project=self.sprint.project_ptr, status=settings.RELATION_ROLE_CH_ACTIVE, exo_role=ExORole.objects.get(code=settings.EXO_ROLE_CODE_ADVISOR), ) self.assertFalse(consultant.user.has_perm(settings.PROJECT_PERMS_PROJECT_MANAGER, self.sprint.project_ptr))
def initialize_fastrack(self): fastrack = FakeFastrackFactory.create() project = fastrack.project_ptr role_team_leader = FakeConsultantProjectRoleFactory( consultant=FakeConsultantFactory( status=settings.CONSULTANT_STATUS_CH_ACTIVE, ), project=project, status=settings.RELATION_ROLE_CH_ACTIVE, exo_role=ExORole.objects.get( code=settings.EXO_ROLE_CODE_FASTRACK_TEAM_LEADER), ) role_curator = FakeConsultantProjectRoleFactory( consultant=FakeConsultantFactory( status=settings.CONSULTANT_STATUS_CH_ACTIVE, ), project=project, status=settings.RELATION_ROLE_CH_ACTIVE, exo_role=ExORole.objects.get( code=settings.EXO_ROLE_CODE_FASTRACK_CURATOR), ) return fastrack, project, role_team_leader, role_curator
def test_user_with_no_certification_request(self): consultant = FakeConsultantFactory() self.client.login(username=consultant.user.username, password=consultant.user.first_name) # DO ACTION response = self.client.get(reverse('api:accounts:me')) # ASSERTIONS certifications = response.json()[0].get('certificationRequests') self.assertEqual(certifications, []) self.assertEqual(consultant.user.certification_request.count(), 0)
def test_coach_one_team(self): # PREPARE DATA project = self.sprint.project_ptr consultant = FakeConsultantFactory( status=settings.CONSULTANT_STATUS_CH_ACTIVE, ) FakeTeamFactory.create(project=project, name='A', coach=consultant) # DO ACTION user_title = get_user_title_in_project(self.sprint.project_ptr, consultant.user) # ASSERTS self.assertEqual(user_title, 'A Sprint Coach')
def test_permissions_when_updating_coach_for_team(self): """ Change the Coach for this Team: - Old Coach: should not have permissions - New coach: shold have permissions """ coach_role, created = ConsultantProjectRole.objects.get_or_create_consultant( user_from=self.super_user, consultant=self.consultant, project=self.sprint.project_ptr, exo_role=ExORole.objects.get(code=settings.EXO_ROLE_CODE_SPRINT_COACH), ) new_team = FakeTeamFactory( project=self.sprint.project_ptr, coach=self.consultant, ) new_consultant = FakeConsultantFactory(status=settings.CONSULTANT_STATUS_CH_ACTIVE) ConsultantProjectRole.objects.get_or_create_consultant( user_from=self.super_user, consultant=new_consultant, project=self.sprint.project_ptr, exo_role=ExORole.objects.get(code=settings.EXO_ROLE_CODE_SPRINT_COACH), ) new_team.update_coach( user_from=self.super_user, coach=new_consultant, ) self.assertFalse(self.consultant.user.has_perm( settings.TEAM_PERMS_FULL_VIEW_TEAM, new_team, )) self.assertFalse(self.consultant.user.has_perm( settings.TEAM_PERMS_COACH_TEAM, new_team, )) self.assertTrue(new_consultant.user.has_perm( settings.TEAM_PERMS_FULL_VIEW_TEAM, new_team, )) self.assertTrue(new_consultant.user.has_perm( settings.TEAM_PERMS_COACH_TEAM, new_team, ))
def test_coach_consultant_role(self): sprint = FakeSprintAutomatedFactory(status=settings.PROJECT_CH_PROJECT_STATUS_WAITING) consultant = FakeConsultantFactory(user__is_active=True) Team.objects.create( project=sprint.project_ptr, user_from=self.super_user, created_by=self.super_user, name=faker.name(), coach=consultant, stream=settings.PROJECT_STREAM_CH_STRATEGY, ) sprint.refresh_from_db() self.assertEqual( sprint.consultants.all()[0], consultant, )
def test_get_questions_from_participants(self): # PREPARE DATA consultant = FakeConsultantFactory( user__is_active=True, user__password='******', activities=[settings.EXO_ACTIVITY_CH_ACTIVITY_CONSULTING]) team_a = FakeTeamFactory.create() team_b = FakeTeamFactory.create() participant_a = FakeUserFactory.create(password='******', is_active=True) participant_b = FakeUserFactory.create(password='******', is_active=True) self.add_user_to_team(participant_a, team_a) self.add_user_to_team(participant_b, team_b) for i in range(7): post = Post.objects.create_project_team_post( user_from=participant_a, team=team_a, title=' '.join(faker.words()), description=faker.text()) for i in range(12): Post.objects.create_project_team_post(user_from=participant_b, team=team_b, title=' '.join( faker.words()), description=faker.text()) url = reverse('api:forum:questions-participants-list') search = 'tosearch' post.title = '{} {}'.format(post.title, search) post.save() # DO ACTION self.client.login(username=consultant.user.username, password='******') response = self.client.get(url) response_search = self.client.get(url, data={'search': search}) # ASSERTS self.assertTrue(status.is_success(response.status_code)) data = response.json() self.assertEqual(data.get('count'), 19) self.assertTrue(status.is_success(response_search.status_code)) data = response_search.json() self.assertEqual(data.get('count'), 1)
def _build_sprint(self, number_of_members=2): sprint = FakeSprintAutomatedFactory() team_members = [{ 'email': faker.email(), 'short_name': faker.name(), } for _ in range(1, number_of_members + 1)] project = sprint.project_ptr consultant = FakeConsultantFactory() team = Team.objects.create( project=project, user_from=self.super_user, created_by=self.super_user, name=faker.name(), coach=consultant, stream=settings.PROJECT_STREAM_CH_STRATEGY, team_members=team_members, ) return sprint, team, consultant
def test_participant_one_team(self): # PREPARE DATA super_user = FakeUserFactory(is_superuser=True) project = self.sprint.project_ptr consultant = FakeConsultantFactory( status=settings.CONSULTANT_STATUS_CH_ACTIVE, ) team = FakeTeamFactory.create(project=project, name='A', coach=consultant) user = project.add_user_project_member(super_user, faker.email(), '123456') team.team_members.add(user) # DO ACTION user_title = get_user_title_in_project(self.sprint.project_ptr, user) # ASSERTS self.assertEqual(user_title, 'A Sprint Participant')
def _create_process(self, options, version): """ Create a default RegistrationTemplate for test """ template = registration_process_template.RegistrationProcessTemplate( name='Certification v1', version=version, ) template.save() # ## # Create Certification Process using the Previous template # ## steps_names = [ 'Agreement', ] notification = registration_process_template.NotificationStep( email_ok='certification_step_accept', email_ko='certification_step_decline', ) notification.save() step = registration_process_template.ProcessTemplateStep.objects.create( template=template, name=steps_names[0], code=slugify(steps_names[0]), action=settings.CONSULTANT_VALIDATION_AGREEMENT, email_tpl=notification, ) for opt in options: step.options.add(opt) consultant = FakeConsultantFactory() # ## # Create the certification using this Template # ## process = RegistrationProcess.create_process( user_from=self.super_user, user=consultant.user, version=version, ) return process
def test_manager_sprint(self): # PREPARE DATA consultant = FakeConsultantFactory( status=settings.CONSULTANT_STATUS_CH_ACTIVE, ) exo_role = ExORole.objects.get( code=settings.EXO_ROLE_CODE_SPRINT_HEAD_COACH) FakeConsultantProjectRoleFactory( consultant=consultant, project=self.sprint.project_ptr, status=settings.RELATION_ROLE_CH_ACTIVE, exo_role=exo_role, ) # DO ACTION user_title = get_user_title_in_project(self.sprint.project_ptr, consultant.user) # ASSERTS self.assertEqual(user_title, exo_role.name)
def test_request_consultant_certification_requires_foundation(self): consultant = FakeConsultantFactory() self.create_application(consultant=consultant) self.client.login(username=consultant.user.username, password=consultant.user.first_name) # DO ACTION response = self.client.get(reverse('api:accounts:me')) # ASSERTIONS certifications = response.json()[0].get('certificationRequests') self.assertEqual(len(certifications), 2) consultant_certification = list( filter( lambda x: x.get('level') == settings. EXO_CERTIFICATION_CERTIFICATION_CH_LEVEL_2, certifications, ))[0] exo_foundation_certification = list( filter( lambda x: x.get('level') == settings. EXO_CERTIFICATION_CERTIFICATION_CH_LEVEL_1, certifications, ))[0] self.assertEqual(consultant.user.certification_request.count(), 1) self.assertEqual( exo_foundation_certification.get('status'), CERTIFICATION_REQUIRED, ) self.assertEqual( exo_foundation_certification.get('certificationCode'), settings.EXO_ROLE_CODE_CERTIFICATION_FOUNDATIONS, ) self.assertEqual( consultant_certification.get('status'), settings.EXO_CERTIFICATION_REQUEST_STATUS_CH_PENDING, ) self.assertEqual( consultant_certification.get('certificationCode'), settings.EXO_ROLE_CODE_CERTIFICATION_CONSULTANT, )
def test_create_team_from_manager(self, mock_handler): # PREPARE DATA team_members = [{ 'email': faker.email(), 'short_name': faker.name(), } for _ in range(1, 3)] sprint = FakeSprintAutomatedFactory(status=settings.PROJECT_CH_PROJECT_STATUS_WAITING) project = sprint.project_ptr consultant = FakeConsultantFactory() # DO ACTION team = Team.objects.create( project=project, user_from=self.super_user, created_by=self.super_user, name='name', coach=consultant, stream=settings.PROJECT_STREAM_CH_STRATEGY, team_members=team_members, ) # ASSERTS self.assertFalse(mock_handler.called) self.assertIsNotNone(team) self.assertIsNotNone(team.project) self.assertIsNotNone(team.name) self.assertIsNotNone(team.stream) self.assertTrue(team.stream in [ x[0] for x in settings.PROJECT_STREAM_CH_TYPE ]) self.assertIsNotNone(team.coach) self.assertIsNotNone(team.team_members.all()) member_manager = team.members self.assertIsNotNone(member_manager) team_member = member_manager.get_by_user(team.team_members.first()) self.assertIsNotNone(team_member) self.assertEqual(team_member.user, team.team_members.first())
def test_change_team_leader(self): # PREPARE DATA fastrack, project, role_team_leader, role_curator = self.initialize_fastrack( ) team = Team.objects.create( project=project, user_from=role_curator.consultant.user, created_by=role_curator.consultant.user, name='name', coach=role_team_leader.consultant, stream=settings.PROJECT_STREAM_CH_STRATEGY, team_members=[], ) new_role_team_leader = FakeConsultantProjectRoleFactory( consultant=FakeConsultantFactory( status=settings.CONSULTANT_STATUS_CH_ACTIVE, ), project=project, status=settings.RELATION_ROLE_CH_ACTIVE, exo_role=ExORole.objects.get( code=settings.EXO_ROLE_CODE_FASTRACK_TEAM_LEADER), ) # DO ACTION team = Team.objects.update( instance=team, user_from=role_curator.consultant.user, name='name2', coach=new_role_team_leader.consultant, zoom_id=None, stream=team.stream, team_members=[], collaborators=[], ) # ASSERTS self.assertEqual(team.coach, new_role_team_leader.consultant) self.assertEqual(project.consultants_roles.count(), 3) self.assertEqual( ConsultantProjectRole.objects.filter_by_exo_role_code( settings.EXO_ROLE_CODE_SPRINT_COACH).filter_by_project( project).count(), 0) self.assertNotEqual(new_role_team_leader.get_data_email(None), {})