Esempio n. 1
0
  def test_can_revoke_invite(self):
    """ Test it's possible to revoke invitation """
    self.test_can_invite_user()

    mail.outbox = []
    self.assertTrue(len(mail.outbox) == 0)
    self.assertTrue(OrganizationInvite.objects.all().count() == 2)
    response = self.client.post(reverse("organization-revoke-invite", ["test-organization"]), {"email": "*****@*****.**"}, format="json")
    self.assertTrue(response.status_code == 200)
    self.assertTrue(response.data["detail"] == "Invite has been revoked.")
    self.assertTrue(OrganizationInvite.objects.all().count() == 1)

    subjects = [x.subject for x in mail.outbox]
    if is_email_enabled("userInvitedRevoked-toUser"): # pragma: no cover
      self.assertTrue(get_email_subject("userInvitedRevoked-toUser", "Your invitation to an organization has been revoked"))
    if is_email_enabled("userInvitedRevoked-toOwnerInviter"): # pragma: no cover
      self.assertTrue(get_email_subject("userInvitedRevoked-toOwnerInviter", "You have revoked an user invitation"))


    mail.outbox = []
    self.client.force_authenticate(User.objects.get(email="*****@*****.**"))
    response = self.client.post(reverse("organization-revoke-invite", ["test-organization"]), {"email": "*****@*****.**"}, format="json")

    subjects = [x.subject for x in mail.outbox]
    if is_email_enabled("userInvitedRevoked-toUser"): # pragma: no cover
      self.assertTrue(get_email_subject("userInvitedRevoked-toUser", "Your invitation to an organization has been revoked"))
    if is_email_enabled("userInvitedRevoked-toOwner"): # pragma: no cover
      self.assertTrue(get_email_subject("userInvitedRevoked-toOwner", "An invitation to join your organization has been revoked"))
    if is_email_enabled("userInvitedRevoked-toMemberInviter"): # pragma: no cover
      self.assertTrue(get_email_subject("userInvitedRevoked-toMemberInviter", "You have revoked an user invitation"))
Esempio n. 2
0
  def test_can_remove_member(self):
    """ Test it's possible to remove a member """
    mail.outbox = []
    self.client.force_authenticate(self.user)
    response = self.client.post(reverse("organization-remove-member", ["test-organization"]), {"email": "*****@*****.**"}, format="json")

    self.assertTrue(response.status_code == 200)
    self.assertTrue(response.data["detail"] == "Member was removed.")

    subjects = [x.subject for x in mail.outbox]
    if is_email_enabled("userRemoved-toUser"): # pragma: no cover
      self.assertTrue(get_email_subject("userRemoved-toUser", "You have have been removed from an organization"))
    if is_email_enabled("userRemoved-toOwner"): # pragma: no cover
      self.assertTrue(get_email_subject("userRemoved-toOwner", "You have removed an user from an organization you own"))
Esempio n. 3
0
    def sendEmail(self, template_name, subject, context={}):
        if not is_email_enabled(template_name):
            return False

        self.__setLocale()
        subject = get_email_subject(template_name, subject)

        ctx = Context(inject_client_url(context))
        text_content = get_template(
            'email/{}.txt'.format(template_name)).render(ctx)
        html_content = get_template(
            'email/{}.html'.format(template_name)).render(ctx)
        self.__resetLocale()

        msg = EmailMultiAlternatives(subject, text_content, self.from_email,
                                     [self.email_address])
        msg.attach_alternative(html_content, "text/html")

        if self.async_mail:
            async_flag = "async"
        elif self.async_mail == None:
            async_flag = getattr(settings, "DEFAULT_SEND_EMAIL", "async")

        if async_flag == "async":
            t = EmailThread(msg)
            t.start()
            result = t
        else:
            result = msg.send() > 0

        return result
 def test_organization_creation_trigger_email(self):
     """Assert that email is triggered when creating an organization"""
     if is_email_enabled("organizationCreated"):  # pragma: no cover
         self.assertTrue(len(mail.outbox) == 1)
         self.assertTrue(mail.outbox[0].subject == get_email_subject(
             "organizationCreated", "Your organization was created"))
     else:  # pragma: no cover
         self.assertTrue(len(mail.outbox) == 0)
Esempio n. 5
0
  def test_can_leave_organization(self):
    """ Test it's possible to leave the organization """
    mail.outbox = []
    self.assertTrue(len(mail.outbox) == 0)
    self.assertTrue(self.user2 in self.organization.members.all())
    self.client.force_authenticate(self.user2)
    response = self.client.post(reverse("organization-leave", ["test-organization"]), {}, format="json")

    self.assertTrue(response.status_code == 200)
    self.assertTrue(response.data["detail"] == "You've left the organization.")
    self.assertTrue(self.user2 not in self.organization.members.all())


    subjects = [x.subject for x in mail.outbox]
    if is_email_enabled("userLeft-toUser"): # pragma: no cover
      self.assertTrue(get_email_subject("userLeft-toUser", "You have left an organization"))
    if is_email_enabled("userLeft-toOwner"): # pragma: no cover
      self.assertTrue(get_email_subject("userLeft-toOwner", "An user has left an organization you own"))
Esempio n. 6
0
  def test_can_invite_user(self):
    """ Test it's possible to invite user """
    mail.outbox = []
    self.assertTrue(OrganizationInvite.objects.all().count() == 0)
    self.assertTrue(len(mail.outbox) == 0)

    response = self.client.post(reverse("organization-invite-user", ["test-organization"]), {"email": "*****@*****.**"}, format="json")
    self.assertTrue(response.status_code == 200)
    self.assertTrue(response.data["detail"] == "User invited.")

    self.assertTrue(OrganizationInvite.objects.all().count() == 1)
    invite = OrganizationInvite.objects.last()
    self.assertTrue(invite.invitator == self.user)
    self.assertTrue(invite.invited == self.user2)

    subjects = [x.subject for x in mail.outbox]
    if is_email_enabled("userInvited-toUser"): # pragma: no cover
      self.assertTrue(get_email_subject("userInvited-toUser", "You are invited to an organization"))
    if is_email_enabled("userInvited-toOwnerInviter"): # pragma: no cover
      self.assertTrue(get_email_subject("userInvited-toOwnerInviter", "You invited a member to an organization you own"))


    third_user = User(email="*****@*****.**")
    third_user.save()

    fourth_user = User(email="*****@*****.**")
    fourth_user.save()

    self.organization.members.add(third_user)
    self.client.force_authenticate(third_user)

    mail.outbox = []
    self.assertTrue(len(mail.outbox) == 0)
    response = self.client.post(reverse("organization-invite-user", ["test-organization"]), {"email": "*****@*****.**"}, format="json")


    subjects = [x.subject for x in mail.outbox]
    if is_email_enabled("userInvited-toUser"): # pragma: no cover
      self.assertTrue(get_email_subject("userInvited-toUser", "You are invited to an organization"))
    if is_email_enabled("userInvited-toOwner"): # pragma: no cover
      self.assertTrue(get_email_subject("userInvited-toOwner", "A member has been invited to your organization"))
    if is_email_enabled("userInvited-toMemberInviter"): # pragma: no cover
      self.assertTrue(get_email_subject("userInvited-toInviter", "You invited a member to an organization you are part of"))
Esempio n. 7
0
  def test_can_join_if_invited(self):
    """ Test it's possible to join organization if invited """
    self.test_can_invite_user()
    self.assertTrue(self.user2 not in self.organization.members.all())

    mail.outbox = []
    self.assertTrue(len(mail.outbox) == 0)

    client = APIClient()
    client.force_authenticate(self.user2)
    response = client.post(reverse("organization-join", ["test-organization"]), {}, format="json")
    self.assertTrue(response.status_code == 200)
    self.assertTrue(response.data["detail"] == "Joined organization.")
    self.assertTrue(self.user2 in self.organization.members.all())


    subjects = [x.subject for x in mail.outbox]
    if is_email_enabled("userJoined-toUser"): # pragma: no cover
      self.assertTrue(get_email_subject("userJoined-toUser", "You have joined an organization"))
    if is_email_enabled("userJoined-toOwner"): # pragma: no cover
      self.assertTrue(get_email_subject("userJoined-toOwner", "An user has joined an organization you own"))
    def test_organization_publishing_trigger_email(self):
        """Assert that email is triggered when publishing an organization"""
        mail.outbox = []
        self.organization.published = True
        self.organization.save()

        if is_email_enabled("organizationPublished"):  # pragma: no cover
            self.assertTrue(len(mail.outbox) == 1)
            self.assertTrue(mail.outbox[0].subject == get_email_subject(
                "organizationPublished", "Your organization was published"))
        else:  # pragma: no cover
            self.assertTrue(len(mail.outbox) == 0)