本文整理汇总了Python中dao.Dao.change_passwd方法的典型用法代码示例。如果您正苦于以下问题:Python Dao.change_passwd方法的具体用法?Python Dao.change_passwd怎么用?Python Dao.change_passwd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dao.Dao
的用法示例。
在下文中一共展示了Dao.change_passwd方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import change_passwd [as 别名]
#.........这里部分代码省略.........
user = users[-1]
self.assertEquals(user.username, username)
self.assertEquals(user.admin_regions, regions)
def test_create_duplicate_user(self):
username = 'abra'
password = 'cadabra'
regions = ['nyc', 'newjersey']
self.norcal_dao.create_user(username, password, regions)
with self.assertRaises(DuplicateUsernameException):
self.norcal_dao.create_user(username, password, regions)
def test_create_user_invalid_regions(self):
username = 'abra'
password = 'cadabra'
regions = ['canadia', 'bahstahn']
with self.assertRaises(InvalidRegionsException):
self.norcal_dao.create_user(username, password, regions)
def test_change_password(self):
username = 'abra'
password = 'cadabra'
new_password = 'whoops'
regions = ['newjersey']
self.norcal_dao.create_user(username, password, regions)
user = self.norcal_dao.get_user_by_username_or_none(username)
old_salt = user.salt
old_hash = user.hashed_password
self.assertTrue(verify_password(password, old_salt, old_hash))
self.norcal_dao.change_passwd(username, new_password)
new_user = self.norcal_dao.get_user_by_username_or_none(username)
new_salt = new_user.salt
new_hash = new_user.hashed_password
self.assertNotEquals(old_salt, new_salt)
self.assertTrue(verify_password(new_password, new_salt, new_hash))
def test_get_and_insert_merge(self):
dao = self.norcal_dao
dao.insert_player(self.merge_player_1)
all_players = dao.get_all_players()
self.assertEqual([p.name for p in all_players],
[u'CLGsFaT', u'gaR', u'sfat'])
player_one = all_players[0]
player_two = all_players[2]
users = dao.get_all_users()
user = users[0]
now = datetime.today()
orig_id = ObjectId()
the_merge = Merge(requester_user_id=user.id,
source_player_obj_id=player_one.id,
target_player_obj_id=player_two.id,
time=now,
id=orig_id)
merge_id = dao.insert_merge(the_merge)
self.assertTrue(merge_id)
self.assertIsInstance(merge_id, ObjectId)
self.assertEqual(merge_id, orig_id)
示例2: len
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import change_passwd [as 别名]
import os
import sys
from pymongo import MongoClient
# add root directory to python path
sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/../'))
from config.config import Config
from dao import Dao
# script to change users password
if __name__ == "__main__":
if len(sys.argv) != 3:
print "incorrect number of arguments!"
print "usage: python change_passwd.py username password"
sys.exit()
username = sys.argv[1]
password = sys.argv[2]
config = Config()
mongo_client = MongoClient(host=config.get_mongo_url())
dao = Dao(None, mongo_client)
if not dao.change_passwd(username, password):
print "user not found! you done goofed"
else:
print "password updated sucessfully"
示例3: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import change_passwd [as 别名]
#.........这里部分代码省略.........
user = users[0]
self.assertEquals(user.id, self.user_id_1)
self.assertEquals(user.username, 'user1')
self.assertEquals(user.admin_regions, self.user_admin_regions_1)
user = users[1]
self.assertEquals(user.id, self.user_id_2)
self.assertEquals(user.username, self.user_full_name_2)
self.assertEquals(user.admin_regions, self.user_admin_regions_2)
def test_create_user(self):
username = 'abra'
password = 'cadabra'
regions = ['nyc', 'newjersey']
self.norcal_dao.create_user(username, password, regions)
users = self.norcal_dao.get_all_users()
self.assertEquals(len(users), 3)
user = users[-1]
self.assertEquals(user.username, username)
self.assertEquals(user.admin_regions, regions)
def test_create_duplicate_user(self):
username = 'abra'
password = 'cadabra'
regions = ['nyc', 'newjersey']
self.norcal_dao.create_user(username, password, regions)
with self.assertRaises(DuplicateUsernameException):
self.norcal_dao.create_user(username, password, regions)
def test_create_user_invalid_regions(self):
username = 'abra'
password = 'cadabra'
regions = ['canadia', 'bahstahn']
with self.assertRaises(InvalidRegionsException):
self.norcal_dao.create_user(username, password, regions)
def test_change_password(self):
username = 'abra'
password = 'cadabra'
new_password = 'whoops'
regions = ['newjersey']
self.norcal_dao.create_user(username, password, regions)
user = self.norcal_dao.get_user_by_username_or_none(username)
old_salt = user.salt
old_hash = user.hashed_password
self.assertTrue(verify_password(password, old_salt, old_hash))
self.norcal_dao.change_passwd(username, new_password)
new_user = self.norcal_dao.get_user_by_username_or_none(username)
new_salt = new_user.salt
new_hash = new_user.hashed_password
self.assertNotEquals(old_salt, new_salt)
self.assertTrue(verify_password(new_password, new_salt, new_hash))
def test_get_and_insert_pending_merge(self):
dao = self.norcal_dao
all_players = dao.get_all_players()
player_one = all_players[0]
player_two = all_players[1]
users = dao.get_all_users()
user = users[0]
now = datetime.today()
orig_id = ObjectId()
the_merge = Merge(user.id, player_one.id, player_two.id, now, id=orig_id)
merge_id = dao.insert_pending_merge(the_merge)
self.assertTrue(merge_id)
self.assertIsInstance(merge_id, ObjectId)
self.assertEqual(merge_id, orig_id)
the_merge_redux = dao.get_pending_merge(merge_id)
self.assertEqual(the_merge.base_player_obj_id, the_merge_redux.base_player_obj_id, msg=the_merge_redux)
self.assertEqual(the_merge.player_to_be_merged_obj_id, the_merge_redux.player_to_be_merged_obj_id)
self.assertEqual(the_merge.id, the_merge_redux.id)
self.assertEqual(the_merge.requester_user_id, the_merge_redux.requester_user_id)
# changed to account for mongo driver losing sub-second accuracy on datetimes
self.assertTrue(abs(the_merge.time - the_merge_redux.time).total_seconds() < 1)
def test_get_non_existant_merge(self):
dao = self.norcal_dao
self.assertIsNone(dao.get_pending_merge(ObjectId("420f53650181b84aaaa01051"))) #mlg1337noscope
def test_get_players_with_similar_alias(self):
dao = self.norcal_dao
self.assertTrue(any(player.name == "gaR" for player in dao.get_players_with_similar_alias("1 1 gar")))
self.assertTrue(any(player.name == "gaR" for player in dao.get_players_with_similar_alias("p1s1 gar")))
self.assertTrue(any(player.name == "gaR" for player in dao.get_players_with_similar_alias("GOOG| gar")))
self.assertTrue(any(player.name == "gaR" for player in dao.get_players_with_similar_alias("GOOG | gar")))
self.assertTrue(any(player.name == "gaR" for player in dao.get_players_with_similar_alias("p1s2 GOOG| gar")))
self.assertTrue(any(player.name == "gaR" for player in dao.get_players_with_similar_alias("garpr goog youtube gar")))