Exemplo n.º 1
0
 def test_add_member_to_organization(self):
     invitation = PrescriberWithOrgSentInvitationFactory(email="*****@*****.**")
     UserFactory(email=invitation.email)
     org_members = invitation.organization.members.count()
     invitation.add_invited_user_to_organization()
     org_members_after = invitation.organization.members.count()
     self.assertEqual(org_members + 1, org_members_after)
Exemplo n.º 2
0
 def test_connected_user_is_not_the_invited_user(self):
     invitation = PrescriberWithOrgSentInvitationFactory(sender=self.sender, organization=self.organization)
     self.client.login(email=self.sender.email, password=DEFAULT_PASSWORD)
     response = self.client.get(invitation.acceptance_link, follow=True)
     self.assertRedirects(response, reverse("account_logout"))
     invitation.refresh_from_db()
     self.assertFalse(invitation.accepted)
     self.assertContains(response, escape("Un utilisateur est déjà connecté."))
Exemplo n.º 3
0
    def test_expired_invitation_with_new_user(self):
        invitation = PrescriberWithOrgSentInvitationFactory(sender=self.sender, organization=self.organization)
        invitation.sent_at -= timedelta(days=invitation.EXPIRATION_DAYS)
        invitation.save()
        self.assertTrue(invitation.has_expired)

        post_data = {
            "first_name": invitation.first_name,
            "last_name": invitation.last_name,
            "password1": "Erls92#32",
            "password2": "Erls92#32",
        }
        response = self.client.post(invitation.acceptance_link, data=post_data, follow=True)
        self.assertContains(response, escape("Cette invitation n'est plus valide."))
Exemplo n.º 4
0
    def test_existing_user_is_not_prescriber(self):
        user = SiaeWithMembershipFactory().members.first()
        invitation = PrescriberWithOrgSentInvitationFactory(
            sender=self.sender,
            organization=self.organization,
            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)
        invitation.refresh_from_db()
        self.assertFalse(invitation.accepted)
Exemplo n.º 5
0
 def test_accept_existing_user_belongs_to_another_organization(self):
     user = PrescriberOrganizationWithMembershipFactory().members.first()
     invitation = PrescriberWithOrgSentInvitationFactory(
         sender=self.sender,
         organization=self.organization,
         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.assert_invitation_is_accepted(response, user, invitation)
Exemplo n.º 6
0
    def test_accept_prescriber_org_invitation(self):
        invitation = PrescriberWithOrgSentInvitationFactory(sender=self.sender, organization=self.organization)
        post_data = {
            "first_name": invitation.first_name,
            "last_name": invitation.last_name,
            "password1": "Erls92#32",
            "password2": "Erls92#32",
        }

        response = self.client.post(invitation.acceptance_link, data=post_data, follow=True)
        user = User.objects.get(email=invitation.email)
        self.assert_invitation_is_accepted(response, user, invitation)
Exemplo n.º 7
0
    def test_expired_invitation_with_existing_user(self):
        user = PrescriberFactory()
        invitation = PrescriberWithOrgSentInvitationFactory(
            first_name=user.first_name,
            last_name=user.last_name,
            email=user.email,
            sender=self.sender,
            organization=self.organization,
        )
        invitation.sent_at -= timedelta(days=invitation.EXPIRATION_DAYS)
        invitation.save()
        self.assertTrue(invitation.has_expired)

        # GET or POST in this case
        response = self.client.get(invitation.acceptance_link, follow=True)
        self.assertContains(response, escape("Cette invitation n'est plus valide."))

        self.client.login(email=user.email, password=DEFAULT_PASSWORD)
        # Try to bypass the first check by directly reaching the join endpoint
        join_url = reverse("invitations_views:join_prescriber_organization", kwargs={"invitation_id": invitation.id})
        response = self.client.get(join_url, follow=True)
        # The 2 views return the same error message
        self.assertContains(response, escape("Cette invitation n'est plus valide."))
Exemplo n.º 8
0
    def test_accept_existing_user_not_logged_in(self):
        invitation = PrescriberWithOrgSentInvitationFactory(sender=self.sender, organization=self.organization)
        user = PrescriberFactory()
        # The user verified its email
        EmailAddress(user_id=user.pk, email=user.email, verified=True, primary=True).save()
        invitation = PrescriberWithOrgSentInvitationFactory(
            sender=self.sender,
            organization=self.organization,
            first_name=user.first_name,
            last_name=user.last_name,
            email=user.email,
        )
        response = self.client.get(invitation.acceptance_link, follow=True)
        self.assertIn(reverse("account_login"), response.wsgi_request.get_full_path())
        self.assertFalse(invitation.accepted)

        response = self.client.post(
            response.wsgi_request.get_full_path(),
            data={"login": user.email, "password": DEFAULT_PASSWORD},
            follow=True,
        )
        self.assertTrue(response.context["user"].is_authenticated)
        self.assert_invitation_is_accepted(response, user, invitation)
Exemplo n.º 9
0
    def test_email_invitation(self):
        invitation = PrescriberWithOrgSentInvitationFactory()
        email = invitation.email_invitation

        # Subject
        self.assertIn(invitation.organization.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.organization.display_name, email.body)

        # To
        self.assertIn(invitation.email, email.to)
Exemplo n.º 10
0
    def test_accepted_notif_sender(self):
        invitation = PrescriberWithOrgSentInvitationFactory()
        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.organization.display_name, email.body)

        # To
        self.assertIn(invitation.sender.email, email.to)