Ejemplo n.º 1
0
    def test_get_current(self):
        '''Make sure that get_current() does not return a deleted Site object.
        '''
        site = Site.get_current(session=self.session)
        self.assertIsInstance(site, Site)

        site.delete(session=self.session)
        self.assertIsNone(Site.get_current(session=self.session))
Ejemplo n.º 2
0
    def test_get_current(self):
        '''Make sure that get_current() does not return a deleted Site object.
        '''
        site = Site.get_current(session=self.session)
        self.assertIsInstance(site, Site)

        site.delete(session=self.session)
        self.assertIsNone(Site.get_current(session=self.session))
Ejemplo n.º 3
0
 def test_site_cache(self):
     '''After updating a ``Site`` object, we shouldn't return a bogus value
     from the ``SITE_CACHE``.
     '''
     site = Site.get_current(session=self.session)
     self.assertEqual(site.name, u'example.com')
     site2 = self.session.query(Site).get(settings.SITE_ID)
     site2.name = u'Example site'
     site2.save()
     site = Site.get_current(session=self.session)
     self.assertEqual(site.name, u'Example site')
Ejemplo n.º 4
0
 def test_site_cache(self):
     '''After updating a ``Site`` object, we shouldn't return a bogus value
     from the ``SITE_CACHE``.
     '''
     site = Site.get_current(session=self.session)
     self.assertEqual(site.name, u'example.com')
     site2 = self.session.query(Site).get(settings.SITE_ID)
     site2.name = u'Example site'
     site2.save()
     site = Site.get_current(session=self.session)
     self.assertEqual(site.name, u'Example site')
Ejemplo n.º 5
0
 def test_activation_email(self):
     ''':meth:`RegistrationProfile.send_activation_email` sends an email.
     '''
     new_user = User.create_user(**self.user_info)
     profile = RegistrationProfile.create_profile(new_user)
     profile.send_activation_email(Site.get_current())
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(mail.outbox[0].to, [self.user_info['email']])
Ejemplo n.º 6
0
 def test_user_creation_no_email(self):
     '''Passing ``send_email=False`` when creating a new user will not
     send an activation email.
     '''
     site = Site.get_current()
     RegistrationProfile.create_inactive_user(send_email=False, site=site,
                                              **self.user_info)
     self.assertEqual(len(mail.outbox), 0)
Ejemplo n.º 7
0
 def test_activation_email(self):
     ''':meth:`RegistrationProfile.send_activation_email` sends an email.
     '''
     new_user = User.create_user(**self.user_info)
     profile = RegistrationProfile.create_profile(new_user)
     profile.send_activation_email(Site.get_current())
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(mail.outbox[0].to, [self.user_info['email']])
Ejemplo n.º 8
0
 def test_user_creation_no_email(self):
     '''Passing ``send_email=False`` when creating a new user will not
     send an activation email.
     '''
     site = Site.get_current()
     RegistrationProfile.create_inactive_user(send_email=False,
                                              site=site,
                                              **self.user_info)
     self.assertEqual(len(mail.outbox), 0)
Ejemplo n.º 9
0
    def test_management_command(self):
        '''The ``cleanupregistration`` management command properly deletes
        expired accounts.
        '''
        site = Site.get_current()
        self.create_inactive_user()
        expired_user = \
            RegistrationProfile.create_inactive_user(username='******',
                                                     password='******',
                                                     email='*****@*****.**',
                                                     session=self.session,
                                                     site=site)
        expired_user.date_joined -= \
            timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS + 1)
        self.session.commit()

        management.call_command('cleanupregistration')
        ct = self.session.query(RegistrationProfile).count()
        self.assertEqual(ct, 1)
        user_count = self.session.query(User) \
                                 .filter_by(username=u'bob') \
                                 .count()
        self.assertEqual(user_count, 0)
Ejemplo n.º 10
0
    def test_expired_user_deletion(self):
        ''':meth:`RegistrationProfile.delete_expired_users` only deletes
        inactive users whose activation window has expired.
        '''
        site = Site.get_current()
        self.create_inactive_user()
        expired_user = \
            RegistrationProfile.create_inactive_user(username='******',
                                                     password='******',
                                                     email='*****@*****.**',
                                                     session=self.session,
                                                     site=site)
        expired_user.date_joined -= \
            timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS + 1)
        self.session.commit()

        RegistrationProfile.delete_expired_users()
        ct = self.session.query(RegistrationProfile).count()
        self.assertEqual(ct, 1)
        user_count = self.session.query(User) \
                                 .filter_by(username=u'bob') \
                                 .count()
        self.assertEqual(user_count, 0)
Ejemplo n.º 11
0
    def test_management_command(self):
        '''The ``cleanupregistration`` management command properly deletes
        expired accounts.
        '''
        site = Site.get_current()
        self.create_inactive_user()
        expired_user = \
            RegistrationProfile.create_inactive_user(username='******',
                                                     password='******',
                                                     email='*****@*****.**',
                                                     session=self.session,
                                                     site=site)
        expired_user.date_joined -= \
            timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS + 1)
        self.session.commit()

        management.call_command('cleanupregistration')
        ct = self.session.query(RegistrationProfile).count()
        self.assertEqual(ct, 1)
        user_count = self.session.query(User) \
                                 .filter_by(username=u'bob') \
                                 .count()
        self.assertEqual(user_count, 0)
Ejemplo n.º 12
0
    def test_expired_user_deletion(self):
        ''':meth:`RegistrationProfile.delete_expired_users` only deletes
        inactive users whose activation window has expired.
        '''
        site = Site.get_current()
        self.create_inactive_user()
        expired_user = \
            RegistrationProfile.create_inactive_user(username='******',
                                                     password='******',
                                                     email='*****@*****.**',
                                                     session=self.session,
                                                     site=site)
        expired_user.date_joined -= \
            timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS + 1)
        self.session.commit()

        RegistrationProfile.delete_expired_users()
        ct = self.session.query(RegistrationProfile).count()
        self.assertEqual(ct, 1)
        user_count = self.session.query(User) \
                                 .filter_by(username=u'bob') \
                                 .count()
        self.assertEqual(user_count, 0)
Ejemplo n.º 13
0
 def create_inactive_user(self):
     site = Site.get_current()
     return RegistrationProfile.create_inactive_user(site=site,
                                                     **self.user_info)
Ejemplo n.º 14
0
 def create_inactive_user(self):
     site = Site.get_current()
     return RegistrationProfile.create_inactive_user(site=site,
                                                     **self.user_info)