示例#1
0
 def test_remove_expired_users_uses_lazy_model(self):
     # remove_expired_users used to be hardcoded to look for an unusable
     # password and the Django user model. Make sure that it actually
     # uses the LazyUser mechanism.
     get_user_model().objects.create_user('dummy2', '')
     user, _ = LazyUser.objects.create_lazy_user()
     user.last_login = datetime.datetime(1972, 1, 1)
     user.save()
     c = remove_expired_users.Command()
     c.handle()
     users = get_user_model().objects.all()
     self.assertEqual(1, len(users))
     self.assertEqual('dummy2', users[0].username)
示例#2
0
 def test_remove_expired_users_session_cookie_age(self):
     # The remove_expired_users should look at SESSION_COOKIE_AGE to figure
     # out whether to delete users. It will delete users who have not
     # logged in since datetime.datetime.now - SESSION_COOKIE_AGE.
     user1, _ = LazyUser.objects.create_lazy_user()
     user2, _ = LazyUser.objects.create_lazy_user()
     user1.last_login = datetime.datetime(1972, 1, 1)
     user1.save()
     c = remove_expired_users.Command()
     c.handle()
     users = get_user_model().objects.all()
     self.assertEqual(1, len(users))
     self.assertEqual(user2.username, users[0].username)
示例#3
0
    def testRemoveExpiredUsers(self):
        # Users wihout usable passwords who don't have a current session record should be removed.
        u1 = User.objects.create_user(username_from_session('dummy'), '')
        u2 = User.objects.create_user('dummy2', '')
        s = Session(
            session_key='dummy',
            session_data='',
            expire_date=datetime.datetime.now() + datetime.timedelta(1)
        )
        s.save()

        c = remove_expired_users.Command()
        c.handle()

        users = User.objects.all()
        self.assertEqual(1, len(users))
        self.assertEqual(u1, users[0])