Exemple #1
0
class InvitationTests(TestCase):

    fixtures = ['users.json', 'orgs.json']

    def setUp(self):
        mail.outbox = []
        self.factory = RequestFactory()
        self.tokenizer = RegistrationTokenGenerator()
        self.user = User.objects.get(username="******")
        self.pending_user = User.objects.create_user(username="******",
                                                     email="*****@*****.**",
                                                     password="******")
        self.pending_user.is_active = False
        self.pending_user.save()

    def test_backend_definition(self):
        from organizations.backends import invitation_backend
        self.assertTrue(isinstance(invitation_backend(), InvitationBackend))

    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_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_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_urls(self):
        """Ensure no error is raised"""
        reverse('invitations_register',
                kwargs={
                    'user_id': self.pending_user.id,
                    'token': self.tokenizer.make_token(self.pending_user)
                })

    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)
class InvitationTests(TestCase):
    fixtures = ['users.json', 'orgs.json']

    def setUp(self):
        mail.outbox = []
        self.factory = RequestFactory()
        self.tokenizer = RegistrationTokenGenerator()
        self.user = User.objects.get(username="******")
        self.pending_user = User.objects.create_user(username="******",
                                                     email="*****@*****.**", password="******")
        self.pending_user.is_active = False
        self.pending_user.save()

    def test_backend_definition(self):
        from organizations.backends import invitation_backend

        self.assertTrue(isinstance(invitation_backend(), InvitationBackend))

    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_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_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_urls(self):
        """Ensure no error is raised"""
        reverse('invitations_register', kwargs={
            'user_id': self.pending_user.id,
            'token': self.tokenizer.make_token(self.pending_user)})

    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)
class RegistrationTests(TestCase):

    fixtures = ['users.json', 'orgs.json']

    def setUp(self):
        mail.outbox = []
        self.factory = RequestFactory()
        self.tokenizer = RegistrationTokenGenerator()
        self.user = User.objects.get(username="******")
        self.pending_user = User.objects.create_user(username="******",
                email="*****@*****.**", password="******")
        self.pending_user.is_active = False
        self.pending_user.save()

    def test_backend_definition(self):
        from organizations.backends import registration_backend
        self.assertTrue(isinstance(registration_backend(), RegistrationBackend))

    def test_register_authenticated(self):
        """Ensure an already authenticated user is redirected"""
        backend = RegistrationBackend()
        request = request_factory_login(self.factory, self.user)
        self.assertEqual(302, backend.create_view(request).status_code)

    def test_register_existing(self):
        """Ensure that an existing user is redirected to login"""
        backend = RegistrationBackend()
        request = request_factory_login(self.factory)
        request.POST = QueryDict("name=Mudhoney&slug=mudhoney&[email protected]")
        self.assertEqual(302, backend.create_view(request).status_code)

    def test_create_user(self):
        registered = RegistrationBackend().register_by_email("*****@*****.**")
        self.assertTrue(isinstance(registered, User))
        self.assertFalse(registered.is_active)
        self.assertEqual(1, len(mail.outbox))
        mail.outbox = []

    def test_create_existing_user(self):
        registered = RegistrationBackend().register_by_email(self.user.email)
        self.assertEqual(self.user, registered)
        self.assertEqual(0, len(mail.outbox)) # User is active

    def test_send_reminder(self):
        RegistrationBackend().send_reminder(self.pending_user)
        self.assertEqual(1, len(mail.outbox))
        RegistrationBackend().send_reminder(self.user)
        self.assertEqual(1, len(mail.outbox)) # User is active
        mail.outbox = []

    def test_urls(self):
        reverse('registration_register', kwargs={
            'user_id': self.pending_user.id,
            'token': self.tokenizer.make_token(self.pending_user)})

    def test_activate_user(self):
        request = self.factory.request()
        with self.assertRaises(Http404):
            RegistrationBackend().activate_view(request, self.user.id,
                    self.tokenizer.make_token(self.user))
        self.assertEqual(200, RegistrationBackend().activate_view(request,
            self.pending_user.id,
            self.tokenizer.make_token(self.pending_user)).status_code)
Exemple #4
0
class InvitationTests(TestCase):

    fixtures = ["users.json", "orgs.json"]

    def setUp(self):
        mail.outbox = []
        self.factory = RequestFactory()
        self.tokenizer = RegistrationTokenGenerator()
        self.user = User.objects.get(username="******")
        self.pending_user = User.objects.create_user(username="******",
                                                     email="*****@*****.**",
                                                     password="******")
        self.pending_user.is_active = False
        self.pending_user.save()

    def test_backend_definition(self):
        from organizations.backends import invitation_backend

        self.assertTrue(isinstance(invitation_backend(), InvitationBackend))

    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_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_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_urls(self):
        """Ensure no error is raised"""
        reverse(
            "invitations_register",
            kwargs={
                "user_id": self.pending_user.pk,
                "token": self.tokenizer.make_token(self.pending_user),
            },
        )

    def test_activate_user(self):
        request = self.factory.request()
        with self.assertRaises(Http404):
            InvitationBackend().activate_view(
                request, self.user.pk, self.tokenizer.make_token(self.user))
        self.assertEqual(
            200,
            InvitationBackend().activate_view(
                request,
                self.pending_user.pk,
                self.tokenizer.make_token(self.pending_user),
            ).status_code,
        )

    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.assertEquals(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.assertEquals(1, len(mail.outbox))
        self.assertEquals(mail.outbox[0].subject,
                          u"You've been added to an organization")
Exemple #5
0
class RegistrationTests(TestCase):

    fixtures = ["users.json", "orgs.json"]

    def setUp(self):
        mail.outbox = []
        self.factory = RequestFactory()
        self.tokenizer = RegistrationTokenGenerator()
        self.user = User.objects.get(username="******")
        self.pending_user = User.objects.create_user(username="******",
                                                     email="*****@*****.**",
                                                     password="******")
        self.pending_user.is_active = False
        self.pending_user.save()

    def test_backend_definition(self):
        from organizations.backends import registration_backend

        self.assertTrue(isinstance(registration_backend(),
                                   RegistrationBackend))

    def test_register_authenticated(self):
        """Ensure an already authenticated user is redirected"""
        backend = RegistrationBackend()
        request = request_factory_login(self.factory, self.user)
        self.assertEqual(302, backend.create_view(request).status_code)

    def test_register_existing(self):
        """Ensure that an existing user is redirected to login"""
        backend = RegistrationBackend()
        request = request_factory_login(self.factory)
        request.POST = QueryDict(
            "name=Mudhoney&slug=mudhoney&[email protected]")
        self.assertEqual(302, backend.create_view(request).status_code)

    def test_create_user(self):
        registered = RegistrationBackend().register_by_email(
            "*****@*****.**")
        self.assertTrue(isinstance(registered, User))
        self.assertFalse(registered.is_active)
        self.assertEqual(1, len(mail.outbox))
        mail.outbox = []

    def test_create_existing_user(self):
        registered = RegistrationBackend().register_by_email(self.user.email)
        self.assertEqual(self.user, registered)
        self.assertEqual(0, len(mail.outbox))  # User is active

    def test_send_reminder(self):
        RegistrationBackend().send_reminder(self.pending_user)
        self.assertEqual(1, len(mail.outbox))
        RegistrationBackend().send_reminder(self.user)
        self.assertEqual(1, len(mail.outbox))  # User is active
        mail.outbox = []

    def test_urls(self):
        reverse(
            "registration_register",
            kwargs={
                "user_id": self.pending_user.pk,
                "token": self.tokenizer.make_token(self.pending_user),
            },
        )

    def test_activate_user(self):
        request = self.factory.request()
        with self.assertRaises(Http404):
            RegistrationBackend().activate_view(
                request, self.user.pk, self.tokenizer.make_token(self.user))
        self.assertEqual(
            200,
            RegistrationBackend().activate_view(
                request,
                self.pending_user.pk,
                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)
class InvitationTests(TestCase):

    fixtures = ['users.json', 'orgs.json']

    def setUp(self):
        mail.outbox = []
        self.factory = RequestFactory()
        self.tokenizer = RegistrationTokenGenerator()
        self.user = User.objects.get(username="******")
        self.pending_user = User.objects.create_user(username="******",
                email="*****@*****.**", password="******")
        self.pending_user.is_active = False
        self.pending_user.save()

    def test_backend_definition(self):
        from organizations.backends import invitation_backend
        self.assertTrue(isinstance(invitation_backend(), InvitationBackend))

    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_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_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_urls(self):
        """Ensure no error is raised"""
        reverse('invitations_register', kwargs={
            'user_id': self.pending_user.id,
            'token': self.tokenizer.make_token(self.pending_user)})

    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_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.assertEquals(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.assertEquals(1, len(mail.outbox))
        self.assertEquals(
            mail.outbox[0].subject,
            u"You've been added to an organization")
Exemple #7
0
class RegistrationTests(TestCase):

    fixtures = ['users.json', 'orgs.json']

    def setUp(self):
        mail.outbox = []
        self.factory = RequestFactory()
        self.tokenizer = RegistrationTokenGenerator()
        self.user = User.objects.get(username="******")
        self.pending_user = User.objects.create_user(username="******",
                                                     email="*****@*****.**",
                                                     password="******")
        self.pending_user.is_active = False
        self.pending_user.save()

    def test_backend_definition(self):
        from organizations.backends import registration_backend
        self.assertTrue(isinstance(registration_backend(),
                                   RegistrationBackend))

    def test_register_authenticated(self):
        """Ensure an already authenticated user is redirected"""
        backend = RegistrationBackend()
        request = request_factory_login(self.factory, self.user)
        self.assertEqual(302, backend.create_view(request).status_code)

    def test_register_existing(self):
        """Ensure that an existing user is redirected to login"""
        backend = RegistrationBackend()
        request = request_factory_login(self.factory)
        request.POST = QueryDict(
            "name=Mudhoney&slug=mudhoney&[email protected]")
        self.assertEqual(302, backend.create_view(request).status_code)

    def test_create_user(self):
        registered = RegistrationBackend().register_by_email(
            "*****@*****.**")
        self.assertTrue(isinstance(registered, User))
        self.assertFalse(registered.is_active)
        self.assertEqual(1, len(mail.outbox))
        mail.outbox = []

    def test_create_existing_user(self):
        registered = RegistrationBackend().register_by_email(self.user.email)
        self.assertEqual(self.user, registered)
        self.assertEqual(0, len(mail.outbox))  # User is active

    def test_send_reminder(self):
        RegistrationBackend().send_reminder(self.pending_user)
        self.assertEqual(1, len(mail.outbox))
        RegistrationBackend().send_reminder(self.user)
        self.assertEqual(1, len(mail.outbox))  # User is active
        mail.outbox = []

    def test_urls(self):
        reverse('registration_register',
                kwargs={
                    'user_id': self.pending_user.id,
                    'token': self.tokenizer.make_token(self.pending_user)
                })

    def test_activate_user(self):
        request = self.factory.request()
        with self.assertRaises(Http404):
            RegistrationBackend().activate_view(
                request, self.user.id, self.tokenizer.make_token(self.user))
        self.assertEqual(
            200,
            RegistrationBackend().activate_view(
                request, self.pending_user.id,
                self.tokenizer.make_token(self.pending_user)).status_code)
class RegistrationTests(TestCase):

    fixtures = ["users.json", "orgs.json"]

    def setUp(self):
        mail.outbox = []
        self.factory = RequestFactory()
        self.tokenizer = RegistrationTokenGenerator()
        self.user = User.objects.get(username="******")
        self.pending_user = User.objects.create_user(
            username="******", email="*****@*****.**", password="******"
        )
        self.pending_user.is_active = False
        self.pending_user.save()

    def test_backend_definition(self):
        from organizations.backends import registration_backend

        self.assertTrue(isinstance(registration_backend(), RegistrationBackend))

    def test_register_authenticated(self):
        """Ensure an already authenticated user is redirected"""
        backend = RegistrationBackend()
        request = request_factory_login(self.factory, self.user)
        self.assertEqual(302, backend.create_view(request).status_code)

    def test_register_existing(self):
        """Ensure that an existing user is redirected to login"""
        backend = RegistrationBackend()
        request = request_factory_login(self.factory)
        request.POST = QueryDict("name=Mudhoney&slug=mudhoney&[email protected]")
        self.assertEqual(302, backend.create_view(request).status_code)

    def test_create_user(self):
        registered = RegistrationBackend().register_by_email("*****@*****.**")
        self.assertTrue(isinstance(registered, User))
        self.assertFalse(registered.is_active)
        self.assertEqual(1, len(mail.outbox))
        mail.outbox = []

    def test_create_existing_user(self):
        registered = RegistrationBackend().register_by_email(self.user.email)
        self.assertEqual(self.user, registered)
        self.assertEqual(0, len(mail.outbox))  # User is active

    def test_send_reminder(self):
        RegistrationBackend().send_reminder(self.pending_user)
        self.assertEqual(1, len(mail.outbox))
        RegistrationBackend().send_reminder(self.user)
        self.assertEqual(1, len(mail.outbox))  # User is active
        mail.outbox = []

    def test_urls(self):
        reverse(
            "registration_register",
            kwargs={
                "user_id": self.pending_user.pk,
                "token": self.tokenizer.make_token(self.pending_user),
            },
        )

    def test_activate_user(self):
        request = self.factory.request()
        with self.assertRaises(Http404):
            RegistrationBackend().activate_view(
                request, self.user.pk, self.tokenizer.make_token(self.user)
            )
        self.assertEqual(
            200,
            RegistrationBackend().activate_view(
                request,
                self.pending_user.pk,
                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)