def test_password_change_clears_sessions(self): SessionFactory(user=self.user) SessionFactory(user=self.user) SessionFactory(user=self.user) assert Session.find().count() == 3 self.user.set_password('killerqueen') assert Session.find().count() == 0
def test_remove_session_for_user(self): SessionFactory(user=self.user) # sanity check assert Session.find().count() == 1 utils.remove_sessions_for_user(self.user) assert Session.find().count() == 0 SessionFactory() SessionFactory(user=self.user) # sanity check assert Session.find().count() == 2 utils.remove_sessions_for_user(self.user) assert Session.find().count() == 1
def test_confirm_email(self, mock_mail): user = UnregUserFactory() auth.register_unconfirmed( username=user.username, password='******', fullname='Rosie', ) user.reload() token = user.get_confirmation_token(user.username) res = self.app.get('/confirm/{}/{}'.format(user._id, token), allow_redirects=False) res = res.follow() assert_equal(res.status_code, 302) assert_in('login?service=', res.location) user.reload() mock_mail.assert_called() assert_equal(len(mock_mail.call_args_list), 1) empty, kwargs = mock_mail.call_args kwargs['user'].reload() assert_equal(empty, ()) assert_equal( kwargs, { 'user': user, 'mimetype': 'html', 'mail': mails.WELCOME, 'to_addr': user.username, }) self.app.set_cookie(settings.COOKIE_NAME, user.get_or_create_cookie()) res = self.app.get('/confirm/{}/{}'.format(user._id, token)) res = res.follow() assert_equal(res.status_code, 302) assert_equal('/', urlparse.urlparse(res.location).path) assert_equal(len(mock_mail.call_args_list), 1) session = Session.find(Q('data.auth_user_id', 'eq', user._id)).order_by('-date_modified').first() assert_equal(len(session.data['status']), 1)
def test_remove_session(self): session = SessionFactory(user=self.user) assert Session.find().count() == 1 utils.remove_session(session) assert Session.find().count() == 0