def test_graphql_consultant_registered(self): email = faker.email() c = FakeConsultantFactory.create(user__email=email) RegistrationProcess._create_process( self.super_user, c.user, ) query = """ query MiQuery($email: String){ allConsultants(user_Email: $email) { edges { node { pk languages { edges { node { pk name } } } user { fullName shortName email invitations { edges { node { invStatus invType } } } } status } } } } """ c.languages.add(Language.objects.all()[0]) c.languages.add(Language.objects.all()[1]) variables = {'email': email} result = schema.execute(query, variable_values=variables) consultant = result.data['allConsultants']['edges'][0]['node'] self.assertEqual(consultant['status'], 'P') self.assertEqual(consultant['pk'], str(c.id)) self.assertEqual(len(consultant['languages']['edges']), 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 create_consultant( cls, short_name, email, invite_user=None, registration_process=False, *args, **kwargs ): user, created = get_user_model().objects.get_or_create( email=email, defaults={'short_name': short_name}, user_from=invite_user, ) cls.activate_existing_user(user, created) if created: cls.initialize_created_user(user, **kwargs) consultant = cls.model( user=user) consultant.save() Achievement.objects.create_reward_for_consultant(consultant, kwargs.get('coins', None)) if kwargs.get('waiting_list', False): user.groups.add(group_waiting_list()) cls.initialize_languages( consultant, kwargs.pop('languages', settings.CONSULTANT_DEFAULT_LANGUAGES), ) if registration_process: RegistrationProcess.create_process( user_from=invite_user or user, user=consultant.user, custom_text=kwargs.get('custom_text', None), skip_steps=kwargs.get('skip_steps', []), version=kwargs.get('version', None), entry_point=kwargs.get('entry_point', None), ) if kwargs.get('password') is not None: user = consultant.user user.set_password(kwargs.get('password')) user.save() return consultant
def test_disable_active_consultant_process_not_started(self): RegistrationProcess._create_process(self.super_user, self.consultant.user) # Disable consultant self.consultant.disable(self.super_user) self.assertTrue(self.consultant.is_disabled) self.assertEqual( self.consultant.status_detail, self.consultant.get_status_display(), ) # Re-activate consultant mail.outbox = [] self.consultant.reactivate(self.super_user) self.assertTrue(self.consultant.is_pending_validation) self.assertEqual(self.consultant.get_pending_validations().count(), 1) validation = self.consultant.get_pending_validations()[0] self.assertTrue(validation.is_sent) invitation = Invitation.objects.filter_by_object(validation)[0] self.assertTrue(invitation.is_pending) self.assertEqual(len(mail.outbox), 1)
def test_filter_status(self): FakeConsultantFactory.create( status=settings.CONSULTANT_STATUS_CH_ACTIVE) FakeConsultantFactory.create( status=settings.CONSULTANT_STATUS_CH_DISABLED) FakeConsultantFactory.create( status=settings.CONSULTANT_STATUS_CH_DISABLED) c1 = FakeConsultantFactory.create( status=settings.CONSULTANT_STATUS_CH_PENDING_VALIDATION) c2 = FakeConsultantFactory.create( status=settings.CONSULTANT_STATUS_CH_PENDING_VALIDATION) filter = {'status': settings.CONSULTANT_STATUS_CH_ACTIVE} self.assertEqual( Consultant.all_objects.filter_complex(*filter, **filter).count(), 1, ) filter = {'status': settings.CONSULTANT_STATUS_CH_DISABLED} self.assertEqual( Consultant.all_objects.filter_complex(*filter, **filter).count(), 2, ) RegistrationProcess.create_process( self.super_user, c1.user, ) RegistrationProcess.create_process( self.super_user, c2.user, ) filter = {'status': settings.REGISTRATION_STEPS_NAMES[2][0]} self.assertEqual( Consultant.all_objects.filter_complex(*filter, **filter).count(), 2, )
def reactivate(self, user_from): self.activate(user_from) registration = self.registration_process if registration: if registration.is_registered: status = settings.CONSULTANT_STATUS_CH_ACTIVE self.user.send_notification_change_password() else: registration.resume() last_validation = registration.current_step.content_object invitation = Invitation.objects.filter_by_object( last_validation).first() if invitation: invitation.reactivate(user_from) status = settings.CONSULTANT_STATUS_CH_PENDING_VALIDATION else: RegistrationProcess._create_process( user_from=user_from, user=self.user, ) status = settings.CONSULTANT_STATUS_CH_PENDING_VALIDATION self.status = status self.save(update_fields=['status'])
def test_disable_active_consultant_certified(self): process = RegistrationProcess._create_process(self.super_user, self.consultant.user) step = process.steps.first() invitation = step.invitation invitation.accept(self.super_user) step = process.steps.all()[1] step.invitation.accept(self.consultant.user) step = process.steps.all()[2] step.invitation.accept(self.consultant.user) self.assertTrue(process.is_registered) self.consultant.disable(self.super_user) self.assertTrue(self.consultant.is_disabled) self.assertEqual(self.consultant.get_pending_validations().count(), 0) self.consultant.reactivate(self.super_user) self.assertTrue(self.consultant.is_active) self.assertEqual( self.consultant.status_detail, self.consultant.get_status_display(), )
def test_has_registration(self): # ## # Create a 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.has_registration) # ## # Create a RegistrationProcess # ## consultant = FakeConsultantFactory.create() process = RegistrationProcess._create_process( self.super_user, consultant.user, ) step = process.current_step self.assertIsNotNone(step.invitation.has_registration)