当前位置: 首页>>代码示例>>Python>>正文


Python Dao.get_user_by_username_or_none方法代码示例

本文整理汇总了Python中dao.Dao.get_user_by_username_or_none方法的典型用法代码示例。如果您正苦于以下问题:Python Dao.get_user_by_username_or_none方法的具体用法?Python Dao.get_user_by_username_or_none怎么用?Python Dao.get_user_by_username_or_none使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dao.Dao的用法示例。


在下文中一共展示了Dao.get_user_by_username_or_none方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestDAO

# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_user_by_username_or_none [as 别名]

#.........这里部分代码省略.........
        self.norcal_dao.create_user(username, password, regions)

        users = self.norcal_dao.get_all_users()
        self.assertEquals(len(users), 4)

        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)
开发者ID:BrandonCookeDev,项目名称:garpr,代码行数:69,代码来源:test_dao.py

示例2: TestDAO

# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_user_by_username_or_none [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")))
开发者ID:jschnei,项目名称:garpr,代码行数:104,代码来源:test_dao.py


注:本文中的dao.Dao.get_user_by_username_or_none方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。