本文整理汇总了Python中auth.models.User.save方法的典型用法代码示例。如果您正苦于以下问题:Python User.save方法的具体用法?Python User.save怎么用?Python User.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类auth.models.User
的用法示例。
在下文中一共展示了User.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_view_spot_for_reading_basic
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import save [as 别名]
def test_view_spot_for_reading_basic(self):
author = User(email='test')
author.save()
spot = models.Spot(
title='Legal ID',
type='Station ID')
spot.put()
constraint = models.SpotConstraint(dow=1, hour=0, slot=0, spots=[spot.key()])
constraint.put()
spot_copy = models.SpotCopy(
body='You are listening to chirpradio.org',
spot=spot,
author=author)
spot_copy.put()
resp = self.client.get(reverse('traffic_log.spotTextForReading', args=(spot.key(),)), {
'hour': constraint.hour,
'dow': constraint.dow,
'slot': constraint.slot
})
context = resp.context
self.assertEqual(context['spot_copy'].body, 'You are listening to chirpradio.org')
self.assertEqual(context['url_to_finish_spot'],
"/traffic_log/spot-copy/%s/finish?hour=0&dow=1&slot=0" % spot_copy.key())
示例2: test_user_edit_form
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import save [as 别名]
def test_user_edit_form(self):
steve = User(
email='[email protected]',
first_name='Steve',
last_name='Dolfin',
dj_name='DJ Steve',
roles=['dj'],
is_active=True,
password='123456' # pretend this is encrypted
)
steve.save()
resp = self.client.post('/auth/edit_user/', {
'original_email': '[email protected]', # this is the key
'email': '[email protected]',
'first_name': 'Steven',
'last_name': 'Dolfin III',
'dj_name': 'Steve Holt!',
'is_active': 'checked',
# change roles:
'is_volunteer_coordinator': 'checked'
})
self.assertNoFormErrors(resp)
user = User.all().filter('email =', '[email protected]').fetch(1)[0]
self.assertEqual(user.first_name, 'Steven')
self.assertEqual(user.last_name, 'Dolfin III')
self.assertEqual(user.dj_name, 'Steve Holt!')
self.assertEqual(user.roles, ['volunteer_coordinator'])
self.assertEqual(user.password, '123456') # should be untouched
示例3: test_user_management
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import save [as 别名]
def test_user_management(self):
"""
test user creation and deletion
"""
# creation
user = User.create('[email protected]', 'world')
self.assertTrue(user)
# retrieve
self.assertTrue(User.get_by_id(user.id))
self.assertTrue(User.get_by_email(user.email))
# duplicated users
self.assertFalse(User.create('[email protected]', 'world'))
try:
user2 = User(email='[email protected]', password='world')
user2.save()
except UserSaveError:
pass
else:
self.assertFalse('The user wrongly saved')
# deletion
self.assertTrue(user.delete())
user4 = User.get_by_email('[email protected]')
self.assertFalse(user4)
示例4: test_user_edit_form_change_password
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import save [as 别名]
def test_user_edit_form_change_password(self):
steve = User(
email='[email protected]',
first_name='Steve',
last_name='Dolfin',
dj_name='DJ Steve',
roles=['dj'],
is_active=True,
password='123456'
)
steve.save()
resp = self.client.post('/auth/edit_user/', {
'original_email': '[email protected]', # this is the key
'email': '[email protected]',
'first_name': 'Steve',
'last_name': 'Dolfin',
'dj_name': 'DJ Seteve',
'is_active': 'checked',
'is_dj': 'checked',
# new password
'password': '1234567'
})
self.assertNoFormErrors(resp)
user = User.all().filter('email =', '[email protected]').fetch(1)[0]
# password was changed:
self.assertEqual(user.check_password('1234567'), True)
示例5: test_login_form
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import save [as 别名]
def test_login_form(self):
# Set up a test user.
email = '[email protected]'
user = User(email=email)
user.set_password('password')
user.save()
# Missing required data
form = auth_forms.LoginForm({'redirect': '/'})
self.assertFalse(form.is_valid())
form = auth_forms.LoginForm({'redirect': '/', 'email': email})
self.assertFalse(form.is_valid())
# Form should fail to validate if password is incorrect.
form = auth_forms.LoginForm({'redirect': '/',
'email': email,
'password': 'incorrect password'})
self.assertFalse(form.is_valid())
# This should succeed.
form = auth_forms.LoginForm({'redirect': '/',
'email': email,
'password': 'password'})
self.assertTrue(form.is_valid())
# The form should reject inactive users.
user.is_active = False
user.save()
form = auth_forms.LoginForm({'redirect': '/',
'email': email,
'password': 'password'})
self.assertFalse(form.is_valid())
# The form should reject unknown users.
form = auth_forms.LoginForm({'redirect': '/',
'email': '[email protected]',
'password': 'password'})
self.assertFalse(form.is_valid())
示例6: test_finish_spot
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import save [as 别名]
def test_finish_spot(self):
self.assertEqual(list(models.TrafficLogEntry.all().fetch(5)), [])
author = User(email='test')
author.save()
spot = models.Spot(
title='Legal ID',
type='Station ID',
author=author)
spot.put()
# make a constraint closest to now:
now = time_util.chicago_now()
today = now.date()
current_hour = now.hour
constraint = models.SpotConstraint(
dow=today.isoweekday(), hour=current_hour, slot=0, spots=[spot.key()])
constraint.put()
spot_copy = models.SpotCopy(
body='You are listening to chirpradio.org',
spot=spot,
author=author)
spot_copy.put()
spot.random_spot_copies = [spot_copy.key()]
spot.save()
resp = self.client.get(reverse('traffic_log.index'))
# unfinished spot should have been marked in static HTML:
assert '<tr class="new">' in resp.content
resp = self.client.get(reverse('traffic_log.finishReadingSpotCopy', args=(spot_copy.key(),)), {
'hour': constraint.hour,
'dow': constraint.dow,
'slot': constraint.slot
})
logged = models.TrafficLogEntry.all().fetch(1)[0]
self.assertEqual(logged.reader.email, "[email protected]")
self.assertEqual(logged.readtime.timetuple()[0:5], datetime.datetime.now().timetuple()[0:5])
self.assertEqual(logged.log_date, time_util.chicago_now().date())
self.assertEqual(logged.spot.key(), spot.key())
self.assertEqual(logged.spot_copy.key(), spot_copy.key())
self.assertEqual(logged.scheduled.key(), constraint.key())
self.assertEqual(logged.hour, constraint.hour)
self.assertEqual(logged.dow, constraint.dow)
resp = self.client.get(reverse('traffic_log.index'))
# finished spot should have been marked in static HTML:
assert '<tr class="finished">' in resp.content
resp = self.client.get(reverse('traffic_log.spotTextForReading', args=(spot.key(),)), {
'hour': constraint.hour,
'dow': constraint.dow,
'slot': constraint.slot
})
context = resp.context
# already finished, no need for finish URL:
self.assertEqual(context['url_to_finish_spot'], None)
assert '(already finished)' in resp.content
示例7: test_spot_constraint_assign
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import save [as 别名]
def test_spot_constraint_assign(self):
user = User(email='test')
user.save()
spot_key = models.Spot(title='test',body='body',type='Live Read Promo', author=user).put()
constraint_key = models.SpotConstraint(dow=1,hour=1,slot=0).put()
views.connectConstraintsAndSpot([constraint_key], spot_key)
self.assertEqual(models.Spot.get(spot_key).constraints.count(), 1)
示例8: AutocompleteViewsTestCase
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import save [as 别名]
class AutocompleteViewsTestCase(DjangoTestCase):
def setUp(self):
# assert self.client.login(email="[email protected]")
self.activeUser = User(
email='[email protected]',
first_name='Active',
last_name='User',
is_active=True,
password='123456'
)
_reindex(self.activeUser)
self.activeUser.save()
self.inactiveUser = User(
email='[email protected]',
first_name='Inactive',
last_name='User',
is_active=False,
password='123456'
)
_reindex(self.inactiveUser)
self.inactiveUser.save()
def test_active_user(self):
response = self.client.get("/auth/search.txt", {'q': 'Active'})
self.assertEqual(response.content,
"%s|%s\n" % (self.activeUser, self.activeUser.key()))
def test_inactive_user(self):
response = self.client.get("/auth/search.txt", {'q': 'Inactive'})
self.assertEqual(response.content, "")
示例9: test_landing_page_shows_spots
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import save [as 别名]
def test_landing_page_shows_spots(self):
user = User(email='test')
user.save()
spot = models.Spot(
title='Legal ID',
type='Station ID')
spot_key = spot.put()
# assign it to every day of the week at the top of the hour:
constraint_keys = views.saveConstraint(dict(hour_list=range(0,24), dow_list=range(1,8), slot=0))
views.connectConstraintsAndSpot(constraint_keys, spot_key)
spot_copy = models.SpotCopy(body='body',
spot=spot,
author=user)
spot_copy.put()
resp = self.client.get(reverse('traffic_log.index'))
context = resp.context[0]
spot_map = {}
constraint_map = {}
for c in context['slotted_spots']:
spot_map[c.hour] = list(c.iter_spots())[0]
constraint_map[c.hour] = c
now = time_util.chicago_now()
# first hour:
self.assertEqual(spot_map[now.hour].title, 'Legal ID')
# second hour:
self.assertEqual(spot_map[(now + datetime.timedelta(hours=1)).hour].title,
'Legal ID')
示例10: test_spot_copy
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import save [as 别名]
def test_spot_copy(self):
author = User(email='test')
author.save()
spot = models.Spot(
title='Legal ID',
type='Station ID')
spot.put()
self.assertEqual(spot.get_add_copy_url(),
reverse('traffic_log.views.addCopyForSpot', args=(spot.key(),)))
constraint = models.SpotConstraint(dow=1, hour=0, slot=0, spots=[spot.key()])
constraint.put()
spot_copy = models.SpotCopy(
body=(
'You are now and forever listening to a killer '
'radio station called chirpradio.org'),
spot=spot,
author=author)
spot_copy.put()
self.assertEqual(str(spot_copy), "You are now and forever listening to a killer radio...")
self.assertEqual(spot_copy.get_edit_url(),
reverse('traffic_log.editSpotCopy', args=(spot_copy.key(),)))
self.assertEqual(spot_copy.get_delete_url(),
reverse('traffic_log.deleteSpotCopy', args=(spot_copy.key(),)))
示例11: PlaylistTest
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import save [as 别名]
class PlaylistTest(APITest):
def setUp(self):
super(PlaylistTest, self).setUp()
dbconfig['lastfm.api_key'] = 'SEKRET_LASTFM_KEY'
self.dj = User(dj_name='DJ Night Moves', first_name='Steve',
last_name='Dolfin', email='[email protected]',
roles=[auth.roles.DJ])
self.dj.save()
self.playlist = ChirpBroadcast()
(self.stevie,
self.talking_book,
self.tracks) = create_stevie_wonder_album_data()
def play_stevie_song(self, song_name):
self.playlist_track = PlaylistTrack(
playlist=self.playlist,
selector=self.dj,
artist=self.stevie,
album=self.talking_book,
track=self.tracks[song_name],
notes='from 1972!',
freeform_label='Motown')
self.playlist_track.save()
return self.playlist_track
示例12: setUp
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import save [as 别名]
def setUp(self):
assert self.client.login(email="[email protected]", roles=[roles.TRAFFIC_LOG_ADMIN])
author = User(email="test")
author.save()
self.author = author
spot = models.Spot(title="Legal ID", type="Station ID", author=author)
self.spot = spot
spot.put()
self.now = time_util.chicago_now()
self.today = self.now.date()
self.dow = self.today.isoweekday()
constraint = self.add_spot_to_constraint(spot)
self.constraint = constraint
spot_copy = models.SpotCopy(body="You are listening to chirpradio.org", spot=spot, author=author)
self.spot_copy = spot_copy
spot_copy.put()
spot.random_spot_copies = [spot_copy.key()]
spot.save()
logged_spot = models.TrafficLogEntry(
log_date=self.today,
spot=spot_copy.spot,
spot_copy=spot_copy,
dow=self.dow,
hour=self.now.hour,
slot=0,
scheduled=constraint,
readtime=time_util.chicago_now(),
reader=author,
)
logged_spot.put()
示例13: signup
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import save [as 别名]
def signup():
if request.method == "POST":
username = request.form["username"]
password = request.form["password"]
verify = request.form["verify"]
email = request.form["email"]
if valid_username(username) and valid_password(password)\
and valid_email(email) and password == verify:
user = User(username=username, email=email)
user.password = password
for exist in User.objects(username=username):
if user.username == exist.username:
flash(u"Username or Email already exist!!")
return redirect("/login")
for exist in User.objects(email=email):
if user.email == exist.email:
flash(u"Username or Email already exist!!")
return redirect("/login")
user.save()
login_user(user)
return redirect("/wiki/home")
else:
flash(u"Invalid Username or Password or Email!!")
return redirect("/signup")
return render_template("/auth/signup.html")
示例14: user
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import save [as 别名]
def user():
from auth.models import User
user = User()
user.username = 'Darth_Vader'
user.email = '[email protected]'
user.password = user.generate_password(password='12345678')
user.save(commit=True)
return user
示例15: test_forgot_password_form_case_insensitive_email
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import save [as 别名]
def test_forgot_password_form_case_insensitive_email(self):
# Set up a test user
user = User(email='[email protected]')
user.set_password('password')
user.save()
form = auth_forms.ForgotPasswordForm({'email': '[email protected]'})
self.assertTrue(form.is_valid())