Esempio n. 1
0
 def test_add_member_to_siae(self):
     invitation = SentSiaeStaffInvitationFactory(email="*****@*****.**")
     UserFactory(email=invitation.email)
     siae_members = invitation.siae.members.count()
     invitation.add_invited_user_to_siae()
     siae_members_after = invitation.siae.members.count()
     self.assertEqual(siae_members + 1, siae_members_after)
Esempio n. 2
0
    def test_can_be_accepted(self):
        invitation = ExpiredSiaeStaffInvitationFactory()
        self.assertFalse(invitation.can_be_accepted)

        invitation = SiaeStaffInvitationFactory(sent_at=timezone.now())
        self.assertFalse(invitation.can_be_accepted)

        invitation = SentSiaeStaffInvitationFactory(accepted=True)
        self.assertFalse(invitation.can_be_accepted)

        invitation = SentSiaeStaffInvitationFactory()
        self.assertTrue(invitation.can_be_accepted)
Esempio n. 3
0
 def test_non_existent_invitation(self):
     invitation = SentSiaeStaffInvitationFactory.build(
         first_name="Léonie",
         last_name="Bathiat",
         email="*****@*****.**")
     response = self.client.get(invitation.acceptance_link, follow=True)
     self.assertEqual(response.status_code, 404)
Esempio n. 4
0
 def test_if_siae_can_apply(self):
     invitation = SentSiaeStaffInvitationFactory()
     response = self.client.get(invitation.acceptance_link, follow=True)
     self.assertContains(
         response,
         '<button type="submit" class="btn btn-primary">Inscription</button>',
         html=True)
Esempio n. 5
0
 def test_accept_invitation_logged_in_user(self):
     # A logged in user should log out before accepting an invitation.
     logged_in_user = UserFactory()
     self.client.login(email=logged_in_user.email,
                       password=DEFAULT_PASSWORD)
     # Invitation for another user
     invitation = SentSiaeStaffInvitationFactory(email="*****@*****.**")
     response = self.client.get(invitation.acceptance_link, follow=True)
     self.assertRedirects(response, reverse("account_logout"))
Esempio n. 6
0
    def test_accept_connected_user_is_not_the_invited_user(self):
        invitation = SentSiaeStaffInvitationFactory()
        self.client.login(email=invitation.sender.email,
                          password=DEFAULT_PASSWORD)
        response = self.client.get(invitation.acceptance_link, follow=True)

        self.assertEqual(reverse("account_logout"), response.wsgi_request.path)
        self.assertFalse(invitation.accepted)
        self.assertContains(response, "Un utilisateur est déjà connecté.")
Esempio n. 7
0
    def test_pending(self):

        # Create some non-expired invitations.
        invitation1 = SentSiaeStaffInvitationFactory()
        invitation2 = SentSiaeStaffInvitationFactory()
        invitation3 = SentSiaeStaffInvitationFactory()

        # Add one expired invitation.
        invitation4 = ExpiredSiaeStaffInvitationFactory()

        pending_invitations = SiaeStaffInvitation.objects.pending()

        self.assertEqual(3, pending_invitations.count())
        self.assertIn(invitation1.pk, pending_invitations.values_list("pk", flat=True))
        self.assertIn(invitation2.pk, pending_invitations.values_list("pk", flat=True))
        self.assertIn(invitation3.pk, pending_invitations.values_list("pk", flat=True))

        self.assertNotIn(invitation4.pk, pending_invitations.values_list("pk", flat=True))
Esempio n. 8
0
 def test_inactive_siae(self):
     siae = SiaeFactory(convention__is_active=False)
     invitation = SentSiaeStaffInvitationFactory(siae=siae)
     user = SiaeStaffFactory(email=invitation.email)
     self.client.login(email=user.email, password=DEFAULT_PASSWORD)
     join_url = reverse("invitations_views:join_siae",
                        kwargs={"invitation_id": invitation.id})
     response = self.client.get(join_url, follow=True)
     self.assertContains(response,
                         escape("Cette structure n'est plus active."))
Esempio n. 9
0
    def test_accept_existing_user_is_not_employer(self):
        user = PrescriberOrganizationWithMembershipFactory().members.first()
        invitation = SentSiaeStaffInvitationFactory(
            first_name=user.first_name,
            last_name=user.last_name,
            email=user.email,
        )

        self.client.login(email=user.email, password=DEFAULT_PASSWORD)
        response = self.client.get(invitation.acceptance_link, follow=True)

        self.assertEqual(response.status_code, 403)
        self.assertFalse(invitation.accepted)
Esempio n. 10
0
    def test_email_invitation(self):
        invitation = SentSiaeStaffInvitationFactory()
        email = invitation.email_invitation

        # Subject
        self.assertIn(invitation.siae.display_name, email.subject)

        # Body
        self.assertIn(capfirst(invitation.first_name), email.body)
        self.assertIn(capfirst(invitation.last_name), email.body)
        self.assertIn(invitation.acceptance_link, email.body)
        self.assertIn(invitation.siae.display_name, email.body)

        # To
        self.assertIn(invitation.email, email.to)
Esempio n. 11
0
    def test_send_invitation(self):
        invitation = SentSiaeStaffInvitationFactory()
        email = invitation.email_invitation

        # Subject
        self.assertIn(invitation.sender.get_full_name().title(), email.subject)

        # Body
        self.assertIn(capfirst(invitation.first_name), email.body)
        self.assertIn(capfirst(invitation.last_name), email.body)
        self.assertIn(invitation.acceptance_link, email.body)

        self.assertIn(str(timezone.localdate(invitation.expiration_date).day), email.body)

        # To
        self.assertIn(invitation.email, email.to)
Esempio n. 12
0
    def test_accepted_notif_sender(self):
        invitation = SentSiaeStaffInvitationFactory()
        email = invitation.email_accepted_notif_sender

        # Subject
        self.assertIn(capfirst(invitation.first_name), email.subject)
        self.assertIn(capfirst(invitation.last_name), email.subject)

        # Body
        self.assertIn(capfirst(invitation.first_name), email.body)
        self.assertIn(capfirst(invitation.last_name), email.body)
        self.assertIn(invitation.email, email.body)
        self.assertIn(invitation.siae.display_name, email.body)

        # To
        self.assertIn(invitation.sender.email, email.to)
Esempio n. 13
0
 def test_accept_new_user_to_inactive_siae(self):
     siae = SiaeWithMembershipFactory(convention__is_active=False)
     sender = siae.members.first()
     invitation = SentSiaeStaffInvitationFactory(
         sender=sender,
         siae=siae,
     )
     form_data = {
         "first_name": invitation.first_name,
         "last_name": invitation.last_name,
         "email": invitation.email,
         "password1": "Erls92#32",
         "password2": "Erls92#32",
     }
     response = self.client.post(invitation.acceptance_link, data=form_data)
     self.assertContains(
         response,
         escape(
             "La structure que vous souhaitez rejoindre n'est plus active.")
     )
Esempio n. 14
0
    def test_accept_invitation_signup(self):
        invitation = SentSiaeStaffInvitationFactory()

        response = self.client.get(invitation.acceptance_link, follow=True)

        form_data = {
            "first_name": invitation.first_name,
            "last_name": invitation.last_name
        }

        # Assert data is already present and not editable
        form = response.context.get("form")
        for key, data in form_data.items():
            self.assertEqual(form.fields[key].initial, data)

        total_users_before = User.objects.count()

        # Fill in the password and send
        response = self.client.post(
            invitation.acceptance_link,
            data={
                **form_data, "password1": "Erls92#32",
                "password2": "Erls92#32"
            },
            follow=True,
        )
        self.assertRedirects(response, reverse("dashboard:index"))

        total_users_after = User.objects.count()
        self.assertEqual((total_users_before + 1), total_users_after)

        user = User.objects.get(email=invitation.email)
        self.assertTrue(user.emailaddress_set.first().verified)
        # `username` should be a valid UUID, see `User.generate_unique_username()`.
        self.assertEqual(user.username,
                         uuid.UUID(user.username, version=4).hex)
        self.assert_accepted_invitation(invitation, user)
Esempio n. 15
0
    def test_accept_invitation_signup_changed_email(self):
        invitation = SentSiaeStaffInvitationFactory()

        response = self.client.get(invitation.acceptance_link, follow=True)
        self.assertTrue(response.status_code, 200)

        # Email is based on the invitation object.
        # The user changes it because c'est un petit malin.
        form_data = {
            "first_name": invitation.first_name,
            "last_name": invitation.last_name,
            "email": "*****@*****.**",
            "password1": "Erls92#32",
            "password2": "Erls92#32",
        }

        # Fill in the password and send
        response = self.client.post(invitation.acceptance_link,
                                    data=form_data,
                                    follow=True)
        self.assertRedirects(response, reverse("dashboard:index"))

        user = User.objects.get(email=invitation.email)
        self.assertEqual(invitation.email, user.email)
Esempio n. 16
0
    def test_accept_existing_user_already_member_of_inactive_siae(self):
        """
        An inactive SIAE user (i.e. attached to a single inactive SIAE)
        can only be ressucitated by being invited to a new SIAE.
        We test here that this is indeed possible.
        """
        siae = SiaeWithMembershipFactory()
        sender = siae.members.first()
        user = SiaeWithMembershipFactory(
            convention__is_active=False).members.first()
        invitation = SentSiaeStaffInvitationFactory(
            sender=sender,
            siae=siae,
            first_name=user.first_name,
            last_name=user.last_name,
            email=user.email,
        )
        self.client.login(email=user.email, password=DEFAULT_PASSWORD)
        response = self.client.get(invitation.acceptance_link, follow=True)
        self.assertRedirects(response, reverse("dashboard:index"))

        current_siae = get_current_siae_or_404(response.wsgi_request)
        self.assertEqual(siae.pk, current_siae.pk)
        self.assert_accepted_invitation(invitation, user)
Esempio n. 17
0
 def test_accepted_invitation(self):
     invitation = SentSiaeStaffInvitationFactory(accepted=True)
     response = self.client.get(invitation.acceptance_link, follow=True)
     self.assertContains(response, escape("Invitation acceptée"))
Esempio n. 18
0
    def has_expired(self):
        invitation = ExpiredSiaeStaffInvitationFactory()
        self.assertTrue(invitation.has_expired)

        invitation = SentSiaeStaffInvitationFactory()
        self.assertFalse(invitation.has_expired)
Esempio n. 19
0
    def test_acceptance_link(self):
        invitation = SentSiaeStaffInvitationFactory()
        self.assertIn(str(invitation.pk), invitation.acceptance_link)

        # Must be an absolute URL
        self.assertTrue(invitation.acceptance_link.startswith("http"))