def test_draft_user_as_guest_application_consultant(self): # PREPARE DATA consultant_1 = FakeConsultantFactory.create() FakeCertificationRequestFactory.create( status=settings.EXO_CERTIFICATION_REQUEST_STATUS_CH_APPROVED, user=consultant_1.user, ) consultant = FakeConsultantFactory.create() user = consultant.user user.set_password('123456') user.save() payload = { 'email': user.email, 'fullName': user.full_name, 'level': settings.EXO_CERTIFICATION_CERTIFICATION_CH_LEVEL_2, 'recaptcha': faker.word(), } url = reverse('api:exo-certification:applications-list') # DO ACTION response = self.client.post(url, data=payload) # ASSERTS self.assertTrue(status.is_success(response.status_code)) data = response.json() self.assertIsNotNone(data.get('pk')) self.assertEqual(data.get('fullName'), user.full_name) self.assertEqual(data.get('email'), user.email) self.assertEqual(data.get('level'), payload.get('level'))
def setUp(self): self.create_user() self.create_superuser() sprint = FakeSprintAutomatedFactory.create( status=settings.PROJECT_CH_PROJECT_STATUS_WAITING) new_team = FakeTeamFactory.create(project=sprint.project_ptr) new_team.add_member( user_from=self.super_user, email=self.user.email, name=self.user.short_name, ) consultant_manager_user = FakeUserFactory.create() consultant_for_manager_role = FakeConsultantFactory.create( user=consultant_manager_user, status=settings.CONSULTANT_STATUS_CH_ACTIVE, ) self.manager_role = ConsultantProjectRole.objects.get_or_create_consultant( user_from=self.super_user, project=sprint.project_ptr, consultant=consultant_for_manager_role, exo_role=ExORole.objects.get( code=settings.EXO_ROLE_CODE_SPRINT_HEAD_COACH), ) self.team = new_team self.sprint = sprint self.step = sprint.project_ptr.steps.first() ConsultantProjectRole.objects.get_or_create_consultant( user_from=self.super_user, project=self.sprint.project_ptr, consultant=FakeConsultantFactory.create( status=settings.CONSULTANT_STATUS_CH_ACTIVE), exo_role=ExORole.objects.get( code=settings.EXO_ROLE_CODE_SPRINT_HEAD_COACH), )
def setUp(self): self.create_superuser() self.consultant_1 = FakeConsultantFactory.create( user__is_active=True, activities=[ settings.EXO_ACTIVITY_CH_ACTIVITY_CONSULTING, settings.EXO_ACTIVITY_CH_ACTIVITY_COACHING, ]) self.consultant_1.user.set_password('123456') self.consultant_1.user.save() self.certificate_consultant( email=self.consultant_1.user.email, _type='consultantrole-foundations', user_from=self.super_user, ) for c in ['ecosystem', 'ambassadors', 'trainers']: circle = Circle.objects.get(slug=c) circle.add_user(self.consultant_1.user) self.consultant_2 = FakeConsultantFactory.create( user__is_active=True, activities=[settings.EXO_ACTIVITY_CH_ACTIVITY_CONSULTING]) self.consultant_2.user.set_password('123456') self.consultant_2.user.save()
def setUp(self): self.create_user() self.create_superuser() FakeConsultantFactory.create( user=self.user, ) self.sprint_automated = FakeSprintAutomatedFactory.create( status=settings.PROJECT_CH_PROJECT_STATUS_DRAFT, start=decrease_date(days=1), created_by=self.user)
def test_user_title(self): # PREPARE DATA role_foundations = CertificationRole.objects.get( code=settings.EXO_ROLE_CODE_CERTIFICATION_FOUNDATIONS) role_consultant = CertificationRole.objects.get( code=settings.EXO_ROLE_CODE_CERTIFICATION_CONSULTANT) role_coach = CertificationRole.objects.get( code=settings.EXO_ROLE_CODE_CERTIFICATION_SPRINT_COACH) regular_user = FakeUserFactory(is_active=True) consultant1 = FakeConsultantFactory.create(user__is_active=True) consultant2 = FakeConsultantFactory.create(user__is_active=True) organization = FakeInternalOrganizationFactory() position = ' '.join(faker.words()) # DO ACTION organization.users_roles.create( user=consultant1.user, position=position, status=settings.RELATION_ROLE_CH_ACTIVE) ConsultantRole.objects.create( consultant=consultant1, certification_role=role_foundations, ) ConsultantRole.objects.create( consultant=consultant1, certification_role=role_consultant, ) ConsultantRole.objects.create( consultant=consultant1, certification_role=role_coach, ) ConsultantRole.objects.create( consultant=consultant2, certification_role=role_foundations, ) consultant1.refresh_from_db() consultant2.refresh_from_db() # ASSERTS self.assertIsNone(regular_user.user_title) self.assertTrue(organization.name in consultant1.user.user_title) self.assertTrue(position in consultant1.user.user_title) self.assertTrue(role_foundations.name in consultant1.user.user_title) self.assertTrue(role_consultant.name in consultant1.user.user_title) self.assertTrue(role_coach.name in consultant1.user.user_title) self.assertTrue(role_foundations.name in consultant2.user.user_title)
def setUp(self): self.create_superuser() self.create_user() self.consultant = FakeConsultantFactory.create( user=self.user, status=settings.CONSULTANT_STATUS_CH_ACTIVE) self.client.login(username=self.super_user.username, password='******')
def test_get_next_step_public_url(self): # DO ACTION consultant = FakeConsultantFactory.create() process = RegistrationProcess._create_process( self.super_user, consultant.user, process_template=self.template, ) # ASSERTS first_step_url = process.get_next_step_public_url() self.assertEqual( process.get_next_step_public_url(), process.steps.first().public_url, ) invitation = process.current_step.invitation invitation.accept(consultant.user) self.assertNotEqual( first_step_url, process.get_next_step_public_url(), ) self.assertEqual( process.get_next_step_public_url(), process.steps.all()[1].public_url, )
def test_change_exo_attributes_consultant(self): consultant = FakeConsultantFactory.create( user__is_active=True, user__password='******', ) self.client.login( username=consultant.user.email, password='******', ) url = reverse( 'api:profile:change-profile-exo-attributes', kwargs={'pk': consultant.pk}, ) data = {'exo_attributes': []} for attr in consultant.exo_attributes.all(): value = {'level': random.randint(0, 5), 'id': attr.pk} data['exo_attributes'].append(value) response = self.client.put(url, data=data, format='json') self.assertTrue(status.is_success(response.status_code)) consultant.refresh_from_db() for value in data.get('exo_attributes'): attr = ConsultantExOAttribute.objects.get(pk=value['id']) self.assertEqual(attr.level, value.get('level')) self.assertEqual(attr.consultant, consultant)
def test_cancel_step(self): # DO ACTION consultant = FakeConsultantFactory.create() process = RegistrationProcess._create_process( self.super_user, consultant.user, process_template=self.template, ) # ASSERTS invitation = process.current_step.invitation self.assertTrue(invitation.can_be_accepted(consultant.user)) self.assertTrue(invitation.can_be_accepted(self.super_user)) invitation.cancel(consultant.user) self.assertIsNotNone(process.current_step) self.assertEqual(process.steps.first().code, process.current_step.code) current_step = process.steps.first() invitation = current_step.invitation self.assertTrue(current_step.is_current) self.assertTrue(current_step.invitation.is_pending) self.assertTrue(invitation.can_be_accepted(consultant.user)) self.assertTrue(invitation.can_be_accepted(self.super_user))
def test_change_mtp_consultant(self): consultant = FakeConsultantFactory.create( user__is_active=True, user__password='******', ) self.client.login( username=consultant.user.email, password='******', ) url = reverse( 'api:profile:change-profile-mtp', kwargs={'pk': consultant.pk}, ) data = { 'personal_mtp': faker.paragraph(), 'mtp_mastery': 1, } response = self.client.put(url, data=data, format='json') self.assertTrue(status.is_success(response.status_code)) consultant.refresh_from_db() consultant.exo_profile.refresh_from_db() self.assertEqual( consultant.exo_profile.personal_mtp, data['personal_mtp'], ) self.assertEqual( consultant.exo_profile.mtp_mastery, data['mtp_mastery'], )
def test_answer_like_unlike_success(self): # PREPARE DATA consultant = FakeConsultantFactory.create( user__is_active=True, user__password='******') self.circle.add_user(consultant.user) answer = self.post.reply(consultant.user, faker.text()) url = reverse('api:forum:answer-like', kwargs={'pk': answer.pk}) url_unlike = reverse('api:forum:answer-unlike', kwargs={'pk': answer.pk}) # DO ACTION self.client.login(username=self.user.username, password='******') self.client.put(url) response_self_like = self.client.put(url) self.client.login(username=consultant.user.username, password='******') response_other_like = self.client.put(url) self.client.put(url_unlike) response_unlike = self.client.put(url_unlike) # ASSERTS self.assertTrue(status.is_success(response_self_like.status_code)) data = response_self_like.json() self.assertTrue(data.get('liked')) self.assertEqual(data.get('numLikes'), 1) self.assertTrue(status.is_success(response_other_like.status_code)) data = response_other_like.json() self.assertTrue(data.get('liked')) self.assertEqual(data.get('numLikes'), 2) self.assertTrue(status.is_success(response_unlike.status_code)) data = response_unlike.json() self.assertFalse(data.get('liked')) self.assertEqual(data.get('numLikes'), 1)
def test_edit_contracting_data(self): # PREPARE DATA consultant = FakeConsultantFactory.create( status=settings.CONSULTANT_STATUS_CH_ACTIVE) contracting_data = ContractingData.objects.create( profile=consultant.exo_profile, name=faker.name(), address=faker.address(), company_name=faker.company(), ) url = reverse( 'api:accounts:user-contracting-data', kwargs={'uuid': consultant.user.uuid.__str__()}) new_data = { 'name': faker.name(), 'address': faker.address(), 'company_name': faker.company(), 'tax_id': '2522', } # DO ACTION response = self.client.put( url, format='json', data=new_data, HTTP_USERNAME=settings.AUTH_SECRET_KEY) # ASSERTS contracting_data.refresh_from_db() self.assertTrue(status.is_success(response.status_code)) self.assertEqual(contracting_data.name, new_data['name'])
def test_cohorts_level_3_with_coupon(self): # PREPARE DATA certification = ExOCertification.objects.get( level=settings.EXO_CERTIFICATION_CERTIFICATION_CH_LEVEL_3) coupon = Coupon.objects.create( code=faker.word(), certification=certification, max_uses=10, uses=0, discount=500, ) consultant = FakeConsultantFactory.create() user = consultant.user user.set_password('123456') user.save() url = reverse('api:exo-certification:cohorts') # DO ACTION self.client.login(username=user.username, password='******') response = self.client.get(url, data={ 'level': 'L3', 'coupon': coupon.code }) # ASSERTS self.assertTrue(status.is_success(response.status_code)) data = response.json() self.assertEquals(len(data), 4) self.assertEquals(data[0].get('price'), 2500) self.assertEquals(data[0].get('finalPrice'), 2000) self.assertEquals(data[0].get('discount'), 500)
def test_post_list_from_circle_removed(self): # PREPARE DATA consultant = FakeConsultantFactory.create(user__is_active=True, user__password='******') circle = Circle.objects.get(name=settings.CIRCLES_ECOSYSTEM_NAME) circle.add_user(consultant.user) self.client.login(username=consultant.user.username, password='******') for i in range(5): Post.objects.create_circle_post(user_from=self.super_user, circle=circle, title=' '.join(faker.words()), description=faker.text()) url = reverse('api:forum:circle-post-list', kwargs={'circle_slug': circle.slug}) # DO ACTION response = self.client.get(url) # ASSERTS self.assertTrue(status.is_success(response.status_code)) # DO ACTION circle.mark_as_removed() response = self.client.get(url) # ASSERTS self.assertTrue(status.is_client_error(response.status_code)) self.assertEqual(response.status_code, status.HTTP_410_GONE)
def test_create_circle_post(self, post_emails_task_mock): # PREPARE DATA consultant = FakeConsultantFactory.create(user__is_active=True, user__password='******') circle = Circle.objects.first() circle.add_user(consultant.user) keyword = FakeKeywordFactory.create() num_files = 4 data = { 'title': ' '.join(faker.words()), 'description': faker.text(), 'tags': [ { 'pk': keyword.pk, 'name': keyword.name, }, { 'name': faker.word() + faker.numerify(), }, ], 'uploaded_files': self.get_files_example(num_files), } url = reverse('api:circles:circles-create', kwargs={'slug': circle.slug}) # DO ACTION self.client.login(username=consultant.user.username, password='******') response = self.client.post(url, data) # ASSERTS self.assertTrue(status.is_success(response.status_code)) self.assertEqual(len(response.data.get('uploaded_files')), num_files)
def test_retrieve_project_post_success(self): # PREPARE DATA post = Post.objects.create_project_team_post( title=''.join(faker.words()), user_from=self.super_user, team=FakeTeamFactory.create()) consultant = FakeConsultantFactory.create() self.certificate_consultant( email=consultant.user.email, _type='consultantrole-foundations', user_from=self.super_user, ) user = consultant.user user.set_password('123456') user.save() url = reverse('api:forum:post-slug-detail', kwargs={'slug': post.slug}) # DO ACTION self.client.login(username=user.username, password='******') response = self.client.get(url) # ASSERTS self.assertTrue(status.is_success(response.status_code))
def test_announcement_post_list(self): # PREPARE DATA consultant = FakeConsultantFactory.create(user__is_active=True, user__password='******') for i in range(5): Post.objects.create_announcement_post(user_from=self.super_user, title=' '.join( faker.words()), description=faker.text()) url = reverse('api:forum:circle-post-list', kwargs={'circle_slug': 'announcements'}) all_announcements = Post.objects.filter_by__type( settings.FORUM_CH_ANNOUNCEMENT) search = all_announcements.first().title search_announcements = all_announcements.filter_by_search(search) # DO ACTIONS self.client.login(username=consultant.user.username, password='******') response = self.client.get(url) response_search = self.client.get(url, data={'search': search}) self.client.login(username=self.super_user.username, password='******') response_su = self.client.get(url) # ASSERTS self.assertTrue(status.is_success(response.status_code)) self.assertTrue(status.is_success(response_search.status_code)) self.assertTrue(status.is_success(response_su.status_code)) data = response.json() data_search = response_search.json() self.assertEqual(data.get('count'), all_announcements.count()) self.assertEqual(data_search.get('count'), search_announcements.count())
def get_reporters(self): relation1, _ = ConsultantProjectRole.objects.get_or_create_consultant( user_from=self.super_user, project=self.sprint.project_ptr, 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) ) relation2, _ = ConsultantProjectRole.objects.get_or_create_consultant( user_from=self.super_user, project=self.sprint_training.project_ptr, 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) ) return [relation1, relation2]
def test_change_contracting(self): consultant = FakeConsultantFactory.create() ContractingData.objects.create( profile=consultant.exo_profile, name=faker.name(), address=faker.address(), company_name=faker.company(), ) self.client.login( username=self.super_user.username, password='******', ) url = reverse( 'api:profile:change-contracting', kwargs={'pk': consultant.user.pk}, ) data = { 'name': faker.name(), 'address': faker.address(), 'company_name': faker.company(), } response = self.client.put(url, data=data, format='json') self.assertTrue(status.is_success(response.status_code)) self.assertTrue( consultant.exo_profile.contracting_data.name, data['name'], ) self.assertEqual(ContractingData.objects.count(), 1)
def test_not_create_achievement_reward(self): consultant = FakeConsultantFactory.create() Achievement.objects.create_reward_for_consultant( consultant=consultant, ) user_reward = UserReward.objects.filter(user=consultant.user).first() self.assertIsNone(user_reward)
def test_change_summary_not_required(self): # PREPARE DATA consultant = FakeConsultantFactory.create( user__is_active=True, user__bio_me=None, user__password='******', ) self.client.login( username=consultant.user.email, password='******', ) url = reverse( 'api:profile:summary', kwargs={'pk': consultant.user.pk}, ) data = { 'short_name': faker.first_name(), 'full_name': '', 'timezone': 'Canada/Eastern', } # DO ACTION response = self.client.put(url, data=data, format='json') # ASSERTS self.assertTrue(status.is_success(response.status_code)) consultant.user.refresh_from_db() consultant.refresh_from_db() user = consultant.user self.assertEqual(user.short_name, data['short_name']) self.assertEqual(consultant.languages.count(), 0) self.assertEqual(user.timezone.zone, 'Canada/Eastern')
def test_change_activities_consultant(self): consultant = FakeConsultantFactory.create( user__is_active=True, user__password='******', ) self.client.login( username=consultant.user.email, password='******', ) self.assertEqual(consultant.exo_profile.exo_activities.count(), 0) url = reverse( 'api:profile:change-profile-activities', kwargs={'pk': consultant.pk}, ) data = { 'exo_activities': [ ExOActivity.objects.all()[1].code, ExOActivity.objects.all()[2].code, ], } response = self.client.put(url, data=data, format='json') self.assertTrue(status.is_success(response.status_code)) consultant.refresh_from_db() consultant.exo_profile.refresh_from_db() self.assertEqual(consultant.exo_profile.exo_activities.count(), 2)
def test_registration_step(self): # ## # Test for regular Invitation ### role = FakeCustomerUserRoleFactory.create(user__is_active=True) user_to = role.user invitation = Invitation.objects.create_role_invitation( self.super_user, user_to, role, ) self.assertIsNone(invitation.registration_step) # ## # Test for Registration invitation # ## consultant = FakeConsultantFactory.create() process = RegistrationProcess._create_process( self.super_user, consultant.user, ) step = process.current_step invitation = step.invitation self.assertEqual( invitation.registration_step, step, ) self.assertEqual( invitation.registration_step.content_object, step.content_object, )
def setUp(self): self.create_superuser() self.create_user() self.consultant = FakeConsultantFactory.create( user=self.user, status=settings.CONSULTANT_STATUS_CH_ACTIVE) self.exo_role = ExORole.objects.get( code=settings.EXO_ROLE_CODE_SPRINT_COACH)
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_change_profile_summary_optional(self): # PREPARE DATA consultant = FakeConsultantFactory.create( user__is_active=True, user__password='******', ) self.client.login( username=consultant.user.email, password='******', ) url = reverse( 'api:profile:change-profile-summary', kwargs={'pk': consultant.user.pk}, ) user = consultant.user user.about_me = ','.join(faker.paragraphs()) user.bio_me = faker.paragraph() user.save() data = { 'about_me': '', 'bio_me': '', } # DO ACTION response = self.client.put(url, data=data, format='json') # ASSERTS self.assertTrue(status.is_success(response.status_code)) user.refresh_from_db() self.assertEqual(user.bio_me, '') self.assertEqual(user.about_me, '')
def test_unlock_achievement_reward(self): consultant = FakeConsultantFactory.create() user_achievement = Achievement.objects.create_reward_for_consultant( consultant=consultant, number_of_coins=10, ) user_reward = UserReward.objects.filter(user=consultant.user).first() user = consultant.user user.profile_picture_origin = settings.EXO_ACCOUNTS_PROFILE_PICTURE_CH_USER user.location = faker.city() + ', ' + faker.country() user.about_me = faker.paragraph() user.save() user_achievement.refresh_from_db() user_reward.refresh_from_db() self.assertTrue(user_achievement.is_pending) self.assertTrue(user_reward.is_pending) for language in Language.objects.all(): consultant.languages.add(language) for consultant_exo_attribute in ConsultantExOAttribute.objects.filter( consultant=consultant): consultant_exo_attribute.level = 3 consultant_exo_attribute.save() for industry in Industry.objects.all()[:5]: consultant.industries.create( industry=industry, level=3, ) user_achievement.refresh_from_db() user_reward.refresh_from_db() self.assertTrue(user_achievement.is_completed) self.assertTrue(user_reward.is_completed)
def test_filter_queryset_by_content_object(self): # DO ACTION consultant = FakeConsultantFactory.create() RegistrationProcess._create_process( self.super_user, consultant.user, process_template=self.template, ) process = RegistrationProcess._create_process( self.super_user, self.consultant.user, ) step = process.steps.first() validation = step.content_object object_id = validation.id content_type_id = ContentType.objects.get_for_model(validation).id p1 = RegistrationProcess.objects.filter_by_content_object_pending( object_id, content_type_id, ) self.assertEqual(p1.count(), 1) process.execute_step(self.consultant.user, step.code) p1 = RegistrationProcess.objects.filter_by_content_object_pending( object_id, content_type_id, ) self.assertEqual(p1.count(), 0)
def test_accept_new_agreement_user(self): # PREPARE DATA consultant = FakeConsultantFactory.create(user=self.user) previous_agreement = FakeAgreementFactory( status=settings.AGREEMENT_STATUS_ACTIVE, ) user_agreement = UserAgreement.objects.create( agreement=previous_agreement, user=consultant.user, ) invitation = Invitation.objects.create_user_agreement( self.super_user, consultant.user, user_agreement, ) url = reverse( 'api:invitation:invitation-accept', kwargs={'hash': invitation.hash}, ) # DO ACTION self.client.login( username=consultant.user.email, password='******', ) data = {} response = self.client.post(url, data=data, format='json') self.assertTrue(status.is_success(response.status_code)) invitation.refresh_from_db() self.assertTrue(invitation.is_active) url, zone = UserRedirectController.redirect_url(consultant.user) self.assertEqual(url, settings.FRONTEND_CIRCLES_PAGE) self.assertFalse(zone)
def setUp(self): self.create_superuser() group = Group.objects.get(name=settings.REGISTRATION_GROUP_NAME) group.user_set.add(self.super_user) self.template = RegistrationProcessTemplate.objects.filter( version=2).last() self.consultant = FakeConsultantFactory.create()