本文整理汇总了Python中pyramid_basemodel.Session类的典型用法代码示例。如果您正苦于以下问题:Python Session类的具体用法?Python Session怎么用?Python Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_playlist_get_all_empty
def test_playlist_get_all_empty(self):
from balistos.models.playlist import Playlist
playlist = Playlist.get('test_playlist')
Session.delete(playlist)
Session.flush()
self.assertEqual(0, Playlist.get_all().count())
self.assertIsNone(Playlist.get('test_playlist'))
示例2: test_success
def test_success(self):
"User can delete itself"
self.add_user_root()
user = self.makeUser('thruflo', 'Password')
Session.add(user)
self.authenticate()
# Attempt to delete user
res = self.app.get('/users/thruflo/delete_user')
# Verify confirmation message
self.assertTrue('Are you really sure' in res.body)
# Verify that the user has not yet been deleted
self.assertTrue(get_existing_user(username='thruflo') is not None)
# Delete the user
res = self.app.post('/users/thruflo/delete_user')
# Verify that the user has now been deleted
self.assertTrue(get_existing_user(username='thruflo') is None)
# User should be logged out
self.assertTrue(len(res.headers['Set-Cookie']) < 200)
示例3: handle_data
def handle_data(data_str):
"""Handle data from the Twitter Streaming API, via the redis queue."""
# XXX debug only really.
sys.stderr.write('.')
# Decode into a unicode string.
text = unicode(data_str, 'utf-8')
# Try to parse the JSON text into a data dict.
try:
data = json.loads(text)
except Exception as err:
return logger.warn(err)
# In a transaction.
with transaction.manager:
# If we're dealing with a status.
if data.has_key('in_reply_to_status_id'):
return handle_status(data, text)
# If we're dealing with a deletion record.
if data.has_key('delete'):
return handle_deletion(data)
# XXX more events, e.g.: handle verification.
# Close the db connection.
Session.remove()
示例4: includeme
def includeme(config):
registry = config.registry
config.include('pyramid_basemodel')
config.include('pyramid_tm')
config.set_request_property(lib.user_property, 'user')
if not registry.queryUtility(interfaces.IDBSession):
registry.registerUtility(Session, interfaces.IDBSession)
if not registry.queryUtility(interfaces.IUserClass):
registry.registerUtility(User, interfaces.IUserClass)
if not registry.queryUtility(interfaces.IConsumerClass):
registry.registerUtility(Consumer, interfaces.IConsumerClass)
if not registry.queryUtility(interfaces.IActivationClass):
registry.registerUtility(Activation, interfaces.IActivationClass)
settings = config.get_settings()
key = settings['api.key']
secret = settings.get('api.secret')
ttl = settings.get('api.ttl', DEFAULT_TTL)
session = Session()
with transaction.manager:
consumer = Consumer.get_by_key(key)
if not consumer:
consumer = Consumer(key=key)
consumer.secret = secret
consumer.ttl = ttl
session.add(consumer)
session.flush()
registry.consumer = consumer
示例5: test_add_pclip
def test_add_pclip(self):
from balistos.models.clip import PlaylistClip
from balistos.models.clip import Clip
from balistos.models.playlist import Playlist
from datetime import datetime
playlist = Playlist(uri='test', title=u'Test')
clip = Clip(
youtube_video_id='test',
title=u'Test',
likes=5,
image_url='test_url',
duration=1
)
Session.add(clip)
Session.add(playlist)
Session.flush()
pclip = PlaylistClip(
playlist=playlist,
clip=clip,
likes=0,
state=0,
added=datetime.now()
)
Session.add(pclip)
Session.flush()
pclip = PlaylistClip.get_by_playlist_and_clip(playlist, clip)
self.assertEqual(playlist, pclip.playlist)
self.assertEqual(clip, pclip.clip)
self.assertEqual(0, pclip.state)
self.assertEqual(0, pclip.likes)
示例6: email_change_POST
def email_change_POST(self):
'''
Processes POST requests to generate change email hash
'''
if self.check_csrf:
token = self.request.session.get_csrf_token()
else:
token = ''
if self.check_csrf and token != self.request.POST.get('token'):
return {'status': False,
'msg': self.request._('csrf-mismatch',
default='CSRF token did not match.',
domain='pyramid_fullauth'),
'token': token}
try:
Session.query(User).filter(User.email == self.request.POST.get('email', '')).one()
return {'status': False,
'msg': self.request._('User with this email exists',
domain='pyramid_fullauth'),
'token': token}
except NoResultFound:
pass
user = self.request.user
try:
result = self.request.registry.notify(BeforeEmailChange(self.request, user))
except AttributeError as e:
return {'status': False, 'msg': e.message, 'token': token}
try:
user.set_new_email(self.request.POST.get('email', ''))
except EmptyError:
return {'status': False,
'msg': self.request._(
'E-mail is empty',
domain='pyramid_fullauth'),
'token': token}
except EmailValidationError:
return {'status': False,
'msg': self.request._(
'Incorrect e-mail format',
domain='pyramid_fullauth'),
'token': token}
response_values = {'status': True,
'msg': self.request._('We sent you email to activate your new email address',
domain='pyramid_fullauth')}
try:
self.request.registry.notify(AfterEmailChange(self.request, user))
except HTTPFound as redirect:
if self.request.is_xhr:
response_values['url'] = redirect.location
return response_values
else:
return redirect
else:
if self.request.is_xhr:
return response_values
else:
return HTTPFound(location='/')
示例7: test_user_get_all_empty
def test_user_get_all_empty(self):
from balistos.models.user import User
user = User.get_by_username('test_user')
Session.delete(user)
Session.flush()
self.assertEqual(0, User.get_all().count())
self.assertIsNone(User.get_by_username('test_user'))
示例8: remove_playlist_clip
def remove_playlist_clip(playlist, youtube_video_id):
"""
Remove clip from playlist
:param playlist: playlist we want to delete clip from
:type playlist: balistos.models.Playlist
:param clip: youtube video id we want to delete from playlist
:type clip: [clip type]
:returns True if removed, False otherwise
:rtype boolean
"""
pclip = PlaylistClip.get_by_playlist_and_clip(
playlist,
Clip.get(youtube_video_id)
)
if not pclip:
return False
state = pclip.state
Session.delete(pclip)
if state == 2:
next_pclip = PlaylistClip.get_queue_playlist_clip(playlist)
play_next_clip(playlist, pclip, next_pclip)
elif state == 1:
active_pclip = PlaylistClip.get_active_playlist_clip(playlist)
set_next_in_queue(playlist, active_pclip.clip.youtube_video_id)
return True
示例9: test_sucess_logs_user_out
def test_sucess_logs_user_out(self):
"Changing a user password logs the user out."
from pyramid_simpleauth.events import UserLoggedOut
from pyramid_simpleauth.model import User
mock_subscriber = Mock()
self.config = config_factory()
self.config.add_subscriber(mock_subscriber, UserLoggedOut)
self.app = TestApp(self.config.make_wsgi_app())
# Create a user.
user = self.makeUser('thruflo', 'Password')
Session.add(user)
old_hash = user.password
self.authenticate()
# Attempt to change password.
post_data = {
'old_password': 'Password',
'new_password': 'sworDpas',
'new_confirm': 'sworDpas',
'next': '/foo/bar',
}
res = self.app.post('/auth/change_password', post_data)
# Verify logged out.
self.assertTrue(len(res.headers['Set-Cookie']) < 200)
# Handler was called with the authentiated user as the second arg.
self.assertTrue(mock_subscriber.called)
event = mock_subscriber.call_args_list[0][0][0]
self.assertTrue(isinstance(event.user, User))
示例10: makeUserWithEmail
def makeUserWithEmail(self):
"Helper method that creates a user with an email"
user = self.makeUser(u'thruflo', u'Password')
Session.add(user)
user.emails.append(model.Email(address=u'[email protected]'))
transaction.commit()
Session.add(user)
return user
示例11: delete
def delete(self):
# If the comment has replies it will only marked as deleted
if len(self.replies):
self.comment = "<DELETED>"
self.deleted = True
# If note it will fully deleted
else:
DBSession.delete(self)
示例12: test_clip_get_all_empty
def test_clip_get_all_empty(self):
from balistos.models.clip import Clip
clips = Clip.get_all()
for clip in clips:
Session.delete(clip)
Session.flush()
self.assertEqual(0, Clip.get_all().count())
self.assertIsNone(Clip.get('cpV0ygkmhP4'))
示例13: test_pclip_get_all_empty
def test_pclip_get_all_empty(self):
from balistos.models.clip import PlaylistClip
pclips = PlaylistClip.get_all()
for pclip in pclips:
Session.delete(pclip)
Session.flush()
self.assertEqual(0, PlaylistClip.get_all().count())
self.assertEqual(0, PlaylistClip.get_all().count())
示例14: add_playlist_clip
def add_playlist_clip(
playlist,
title,
image_url,
youtube_video_id,
duration,
username=None,
state=0,
):
"""
Add clip to playlist
:param playlist: playlist of which we want to get videos
:type playlist: balistos.models.playlist.Playlist
:param title: title of video
:type title: str
:param image_url: url of image used for thumbnail
:type image_url: str
:param youtube_video_id: id of video on youtube
:type youtube_video_id: str
:param duration: duration of video
:type duration: int
:param username: username of user that added this clip
:type username: str
:param state: state of video to be added
:type state: int
"""
clip = Clip.get(youtube_video_id)
if not clip:
clip = Clip(
title=title,
image_url=image_url,
youtube_video_id=youtube_video_id,
likes=0,
duration=duration,
)
Session.add(clip)
pclip = PlaylistClip.get_by_playlist_and_clip(playlist, clip)
if not pclip:
if state == 2:
started = datetime.now()
else:
started = datetime.min
pclip = PlaylistClip(
added=datetime.now(),
likes=0,
state=state,
clip=clip,
playlist=playlist,
username=username,
started=started,
)
Session.add(pclip)
return pclip
else:
pclip.likes += 1
示例15: setUp
def setUp(self):
from balistos import configure
Session.remove()
createTestDB()
self.config = testing.setUp()
configure(self.config)
app = self.config.make_wsgi_app()
from webtest import TestApp
self.testapp = TestApp(app)