Пример #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))
Пример #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))
Пример #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')
Пример #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')
Пример #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']])
Пример #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)
Пример #7
0
 def setUp(self):
     if not Site.__table__.exists():
         Site.__table__.create()
     site = Site(id=settings.SITE_ID,
                 domain='example.com',
                 name=u'example.com')
     self.session.add(site)
     self.session.commit()
Пример #8
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']])
Пример #9
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)
Пример #10
0
 def setUpClass(cls):
     super(RegistrationModelTests, cls).setUpClass()
     Site.__table__.create()
     User.__table__.create()
     orm = ORM.get()
     cls.session = orm.sessionmaker()
     cls.user_info['session'] = cls.session
     site = Site(id=settings.SITE_ID,
                 domain='example.com',
                 name=u'example.com')
     cls.session.add(site)
     cls.session.commit()
Пример #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)
Пример #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)
Пример #13
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)
Пример #14
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)
Пример #15
0
 def create_inactive_user(self):
     site = Site.get_current()
     return RegistrationProfile.create_inactive_user(site=site,
                                                     **self.user_info)
Пример #16
0
 def create_inactive_user(self):
     site = Site.get_current()
     return RegistrationProfile.create_inactive_user(site=site,
                                                     **self.user_info)