本文整理汇总了Python中radlibs.Client类的典型用法代码示例。如果您正苦于以下问题:Python Client类的具体用法?Python Client怎么用?Python Client使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_rad_by_name
def new_rad_by_name():
if not g.user:
return error_response('login required')
try:
parse(request.form['rad'])
except ParseError as e:
return error_response('parse error: {0}'.format(e.message))
session = Client().session()
lib_name = request.form['lib']
association_id = request.form['association_id']
try:
find_association(association_id)
except NoResultFound:
return error_response('no such association')
try:
lib = session.query(Lib).\
filter(Lib.name == lib_name).\
filter(Lib.association_id == association_id).\
one()
except NoResultFound:
return error_response("no such lib '{0}'".format(lib_name))
rad = Rad(created_by=g.user.user_id,
lib_id=lib.lib_id,
rad=request.form['rad'])
session.add(rad)
radlibs.lib.decache_lib(lib.name, lib.association_id)
return {
'status': 'ok',
'rad_id': rad.rad_id,
}
示例2: test_invite_new_user_to_association
def test_invite_new_user_to_association(self, user, send_invitation_mail):
user.email = "[email protected]"
session = Client().session()
association = Association(name='prancing ponies')
session.add(association)
session.flush()
session.add(UserAssociation(user_id=user.user_id,
association_id=association.association_id))
session.flush()
response = self.app.post(
'/association/{0}/invite_user'.format(association.association_id),
data={'email': '[email protected]'})
eq_(response.status_code, 200, response.data)
body = json.loads(response.data)
eq_(body, {'status': 'ok', 'action': 'invited'})
invite = session.query(AssociationInvite).one()
eq_(invite.email, '[email protected]')
eq_(invite.association_id, association.association_id)
send_invitation_mail.assert_called_once_with(
'[email protected]',
'[email protected]',
'prancing ponies',
'http://localhost/accept_invitation/{0}/'.format(invite.token))
示例3: edit_rad
def edit_rad(rad_id):
if rad_id == 0:
abort(404)
if not g.user:
return error_response('login required')
try:
parse(request.form['rad'])
except ParseError as e:
return error_response('parse error: {0}'.format(e.message))
session = Client().session()
try:
(rad, lib) = session.query(Rad, Lib).\
join(Lib).\
join(Association).\
join(UserAssociation).\
filter(UserAssociation.user_id == g.user.user_id).\
filter(Rad.rad_id == rad_id).\
one()
except NoResultFound:
return error_response('no such rad')
rad.rad = request.form['rad']
session.add(rad)
radlibs.lib.decache_lib(lib.name, lib.association_id)
return {'status': 'ok'}
示例4: test_no_such_lib_raises_keyerror
def test_no_such_lib_raises_keyerror(self, g):
session = Client().session()
association = Association(name="prancing ponies")
session.add(association)
session.flush()
g.association_id = association.association_id
radlibs.lib.load_lib('Loot')
示例5: find_association
def find_association(association_id):
session = Client().session()
return session.query(Association).\
join(UserAssociation,
UserAssociation.association_id == Association.association_id).\
filter(Association.association_id == association_id).\
filter(UserAssociation.user_id == g.user.user_id).\
one()
示例6: test_generate
def test_generate(self):
session = Client().session()
association = Association(name='crazy train')
session.add(association)
session.flush()
invite = AssociationInvite.generate(association.association_id,
'[email protected]')
示例7: test_generate_token
def test_generate_token(self):
session = Client().session()
user = User()
session.add(user)
session.flush()
token = EmailVerificationToken.generate(user)
eq_(len(token.token), 32)
示例8: test_breadcrumb_for_an_association
def test_breadcrumb_for_an_association(self):
session = Client().session()
association = Association(name="Harpy")
session.add(association)
session.flush()
with app.app_context():
crumb = breadcrumb_for(association)
eq_(crumb, ('Harpy', 'http://localhost/association/{0}'.format(
association.association_id)))
示例9: register
def register():
db_session = Client().session()
user = User(
email=request.form['email'],
identifier=session['partial_user']['identifier'])
db_session.add(user)
db_session.flush()
token = EmailVerificationToken.generate(user)
send_verification_mail(
user, url_for('verify_email', token=token.token, _external=True))
session['user'] = {'email': user.email, 'identifier': user.identifier}
return redirect(request.form['redirect_uri'])
示例10: test_create_new_association
def test_create_new_association(self, user):
session = Client().session()
response = self.app.post('/association/new',
data={'name': 'codescouts'})
association = session.query(Association).one()
user_association = session.query(UserAssociation).one()
eq_(user_association.association_id, association.association_id)
eq_(user_association.user_id, user.user_id)
eq_(association.name, 'codescouts')
eq_(response.status_code, 302, response.data)
eq_(response.headers['Location'],
'http://localhost/association/{0}'.format(
association.association_id))
示例11: test_test_radlib_requires_login
def test_test_radlib_requires_login(self):
session = Client().session()
association = Association(name="somebody's private stuff")
session.add(association)
session.flush()
response = self.app.post(
'/association/{0}/test_radlib'.format(association.association_id),
data={'rad': 'I ate some <Food>'})
eq_(response.status_code, 200)
body = json.loads(response.data)
eq_(body, {
'status': 'error',
'error': 'login required'})
示例12: test_bypass_login__new_user
def test_bypass_login__new_user(self):
session = Client().session()
response = self.app.post('/login_bypass', data={
'email': '[email protected]',
'identifier': 'http://www.facebook.com/itsme',
})
eq_(response.status_code, 302)
eq_(response.headers['Location'], 'http://localhost/')
user = session.query(User).one()
eq_(user.email, '[email protected]')
eq_(user.identifier, 'http://www.facebook.com/itsme')
示例13: test_bypass_login__existing_user
def test_bypass_login__existing_user(self):
session = Client().session()
user = User(identifier='http://www.facebook.com/itsme',
email='[email protected]')
session.add(user)
session.flush()
response = self.app.post('/login_bypass', data={
'email': '[email protected]',
'identifier': 'http://www.facebook.com/itsme',
})
eq_(response.status_code, 302)
eq_(response.headers['Location'], 'http://localhost/')
示例14: test_hmac_auth__invalid_datetime_format
def test_hmac_auth__invalid_datetime_format(self):
session = Client().session()
user = User(api_key='hurfdurf')
session.add(user)
session.flush()
response = self.app.post(
'/test_authorization', data={'user_id': user.user_id,
'signature': 'johnhancock',
'time': 'beer:30',
'other_param': 'frabjous'})
eq_(response.status_code, 200, response.data)
body = json.loads(response.data)
eq_(body, {'status': 'error', 'error': 'not logged in'})
示例15: test_add_new_rad__requires_correct_user
def test_add_new_rad__requires_correct_user(self, user):
session = Client().session()
other_user = User()
association_id = self.create_association(other_user)
lib = Lib(name="Song", association_id=association_id)
session.add(lib)
session.flush()
response = self.app.post('/lib/{0}/rad/new'.format(lib.lib_id),
data={'rad': '<Song_which_never_ends>'})
eq_(response.status_code, 200)
body = json.loads(response.data)
eq_(body, {
'status': 'error',
'error': 'no such lib'})