def test_activate_user(self): request = self.factory.request() with self.assertRaises(Http404): InvitationBackend().activate_view(request, self.user.id, self.tokenizer.make_token(self.user)) self.assertEqual(200, InvitationBackend().activate_view(request, self.pending_user.id, self.tokenizer.make_token(self.pending_user)).status_code)
def test_activate_orgs(self): """Ensure method activates organizations and w/o specified org_model""" org = Organization.objects.create(name="Test", slug="kjadkjkaj", is_active=False) org.add_user(self.user) self.assertFalse(org.is_active) backend = InvitationBackend() backend.activate_organizations(self.user) refreshed_org = Organization.objects.get(pk=org.pk) self.assertTrue(refreshed_org.is_active)
def test_send_notification_inactive_user(self): """ This test verifies that calling the send_notification function from the OrganizationsCoreInvitationBackend with an inactive Django user causes the function to return False without sending an email. """ org = Organization.objects.create(name="Test Organization") result = InvitationBackend().send_notification( self.pending_user, domain="example.com", organization=org, sender=self.user ) self.assertEqual(result, False) self.assertEqual(0, len(mail.outbox))
def test_send_notification_active_user(self): """ This test verifies that calling the send_notification function from the OrganizationsCoreInvitationBackend with an active Django user causes the function send an email to that user. """ org = Organization.objects.create(name="Test Organization") InvitationBackend().send_notification( self.user, domain="example.com", organization=org, sender=self.pending_user ) self.assertEqual(1, len(mail.outbox)) self.assertEqual(mail.outbox[0].subject, "You've been added to an organization")
def test_activate_orgs_abstract(self, account_user): backend = InvitationBackend(org_model=CustomOrganization) backend.activate_organizations(account_user)
def test_activate_orgs_vendor(self, account_user): """Ensure no errors raised because correct relation name used""" backend = InvitationBackend(org_model=Vendor) backend.activate_organizations(account_user)
def test_create_existing_user(self): invited = InvitationBackend().invite_by_email(self.user.email) self.assertEqual(self.user, invited) self.assertEqual(0, len(mail.outbox)) # User is active
def test_create_user(self): invited = InvitationBackend().invite_by_email("*****@*****.**") self.assertTrue(isinstance(invited, User)) self.assertFalse(invited.is_active) self.assertEqual(1, len(mail.outbox)) mail.outbox = []
def test_backend_urls(self): self.assertTrue(InvitationBackend().get_urls())
def test_send_reminder(self): InvitationBackend().send_reminder(self.pending_user) self.assertEqual(1, len(mail.outbox)) InvitationBackend().send_reminder(self.user) self.assertEqual(1, len(mail.outbox)) # User is active mail.outbox = []
def test_activate_orgs(self): """Ensure no errors raised because correct relation name used""" user = User.objects.create(username="******", email="*****@*****.**") backend = InvitationBackend(org_model=Vendor) backend.activate_organizations(user)
def test_activate_orgs_abstract(self): user = User.objects.create(username="******", email="*****@*****.**") backend = InvitationBackend(org_model=CustomOrganization) backend.activate_organizations(user)