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


Python Dao.create_user方法代码示例

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


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

示例1: put

# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import create_user [as 别名]
    def put(self):
        dao = Dao(None, mongo_client=mongo_client)

        if not dao:
            return 'Dao not found', 404
        user = get_user_from_request(request, dao)
        if not user:
            return 'Permission denied', 403
        #if not is_user_admin_for_region(user, region='*'):
        #    return 'Permission denied', 403

        args = admin_functions_parser.parse_args()

        function_type = args['function_type']
        if function_type == 'region':
            region_name = args['new_region']

            #Execute region addition
            config = Config()
            if dao.create_region(region_name):
                print("region created:" + region_name)

        elif function_type == 'user':
            uname = args['new_user_name']
            upass = args['new_user_pass']
            uperm = args['new_user_permissions']
            uregions = args['new_user_regions']

            #Execute user addition
            dao = Dao(None, mongo_client)
            if dao.create_user(uname, upass, uregions):
                print("user created:" + uname)
开发者ID:garsh0p,项目名称:garpr,代码行数:34,代码来源:server.py

示例2: put

# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import create_user [as 别名]
    def put(self):
        dao = get_dao(None)
        auth_user(request, dao, check_regions=False, needs_super=True)


        parser = reqparse.RequestParser() \
            .add_argument('function_type', location='json', type=str) \
            .add_argument('new_region', location='json', type=str) \
            .add_argument('new_user_name', location='json', type=str) \
            .add_argument('new_user_pass', location='json', type=str) \
            .add_argument('new_user_permissions', location='json', type=str) \
            .add_argument('new_user_regions', location='json', type=list)
        args = parser.parse_args()

        function_type = args['function_type']
        if function_type == 'region':
            region_name = args['new_region']

            # Execute region addition
            if dao.create_region(region_name):
                print("region created:" + region_name)

        elif function_type == 'user':
            uname = args['new_user_name']
            upass = args['new_user_pass']
            uperm = args['new_user_permissions']
            uregions = args['new_user_regions']

            if uperm not in M.ADMIN_LEVEL_CHOICES:
                err('Invalid permission selection!')

            # Execute user addition
            dao = Dao(None, mongo_client)
            try:
                dao.create_user(uname, upass, uregions, uperm)
                print("user created:" + uname)
            except Exception as e:
                print e
                err('Error creating user!')
开发者ID:jiangtyd,项目名称:smash-ranks,代码行数:41,代码来源:server.py

示例3: len

# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import create_user [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 create new user in db
if __name__ == "__main__":
    if len(sys.argv) < 4:
        print "incorrect number of arguments!"
        print "usage: python create_user.py username password region1 [region2] [region3]...."
        sys.exit()

    username = sys.argv[1]
    password = sys.argv[2]
    regions =  sys.argv[3:]

    config = Config()
    mongo_client = MongoClient(host=config.get_mongo_url())
    dao = Dao(None, mongo_client)
    if dao.create_user(username, password, regions):
        print "user created:", username
开发者ID:BrandonCookeDev,项目名称:garpr,代码行数:29,代码来源:create_user.py

示例4: TestDAO

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

#.........这里部分代码省略.........
    def test_get_latest_ranking(self):
        latest_ranking = self.norcal_dao.get_latest_ranking()

        self.assertEquals(latest_ranking.time, self.ranking_time_2)
        self.assertEquals(latest_ranking.tournaments, self.tournament_ids)

        rankings = latest_ranking.ranking
        print rankings

        self.assertEquals(len(rankings), 3)
        self.assertEquals(rankings[0], self.ranking_entry_1)
        self.assertEquals(rankings[1], self.ranking_entry_2)
        self.assertEquals(rankings[2], self.ranking_entry_4)

    def test_get_all_users(self):
        users = self.norcal_dao.get_all_users()
        self.assertEquals(len(users), 3)

        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)

        user = users[2]
        self.assertEqual(user.id, self.superadmin_id)
        self.assertEqual(user.username, self.superadmin_full_name)
        self.assertEqual(user.admin_regions, self.superadmin_admin_regions)

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

示例5: TestDAO

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

#.........这里部分代码省略.........

    # TODO
    def test_merge_players_same_player_in_single_match(self):
        pass

    def test_get_latest_ranking(self):
        latest_ranking = self.norcal_dao.get_latest_ranking()

        self.assertEquals(latest_ranking.time, self.ranking_time_2)
        self.assertEquals(latest_ranking.tournaments, self.tournament_ids)

        rankings = latest_ranking.ranking

        self.assertEquals(len(rankings), 3)
        self.assertEquals(rankings[0], self.ranking_entry_1)
        self.assertEquals(rankings[1], self.ranking_entry_2)
        self.assertEquals(rankings[2], self.ranking_entry_4)


    def test_get_all_users(self):
        users = self.norcal_dao.get_all_users()
        self.assertEquals(len(users), 2)

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


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