本文整理汇总了Python中dao.Dao.insert_user方法的典型用法代码示例。如果您正苦于以下问题:Python Dao.insert_user方法的具体用法?Python Dao.insert_user怎么用?Python Dao.insert_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dao.Dao
的用法示例。
在下文中一共展示了Dao.insert_user方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import insert_user [as 别名]
#.........这里部分代码省略.........
self.user_admin_regions_1 = ['norcal', 'texas']
self.user_1 = User(self.user_id_1, self.user_admin_regions_1)
self.user_id_2 = 'asdfasdf'
self.user_full_name_2 = 'Full Name'
self.user_admin_regions_2 = []
self.user_2 = User(self.user_id_2, self.user_admin_regions_2, full_name=self.user_full_name_2)
self.users = [self.user_1, self.user_2]
self.region_1 = Region('norcal', 'Norcal')
self.region_2 = Region('texas', 'Texas')
self.regions = [self.region_1, self.region_2]
for region in self.regions:
Dao.insert_region(region, self.mongo_client, database_name=DATABASE_NAME)
self.norcal_dao = Dao('norcal', self.mongo_client, database_name=DATABASE_NAME)
for player in self.players:
self.norcal_dao.insert_player(player)
for tournament in self.tournaments:
self.norcal_dao.insert_tournament(tournament)
for pending_tournament in self.pending_tournaments:
self.norcal_dao.insert_pending_tournament(pending_tournament)
for ranking in self.rankings:
self.norcal_dao.insert_ranking(ranking)
for user in self.users:
self.norcal_dao.insert_user(user)
def tearDown(self):
self.mongo_client.drop_database(DATABASE_NAME)
def test_init_with_invalid_region(self):
# create a dao with an existing region
Dao('norcal', self.mongo_client, database_name=DATABASE_NAME)
# create a dao with a new region
with self.assertRaises(RegionNotFoundException):
Dao('newregion', self.mongo_client, database_name=DATABASE_NAME)
def test_get_all_regions(self):
# add another region
region = Region('newregion', 'New Region')
Dao.insert_region(region, self.mongo_client, database_name=DATABASE_NAME)
regions = Dao.get_all_regions(self.mongo_client, database_name=DATABASE_NAME)
self.assertEquals(len(regions), 3)
self.assertEquals(regions[0], region)
self.assertEquals(regions[1], self.region_1)
self.assertEquals(regions[2], self.region_2)
def test_get_player_by_id(self):
self.assertEquals(self.norcal_dao.get_player_by_id(self.player_1_id), self.player_1)
self.assertEquals(self.norcal_dao.get_player_by_id(self.player_2_id), self.player_2)
self.assertEquals(self.norcal_dao.get_player_by_id(self.player_3_id), self.player_3)
self.assertIsNone(self.norcal_dao.get_player_by_id(ObjectId()))
def test_get_player_by_alias(self):
self.assertEquals(self.norcal_dao.get_player_by_alias('gar'), self.player_1)
self.assertEquals(self.norcal_dao.get_player_by_alias('GAR'), self.player_1)
示例2: TestAliasService
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import insert_user [as 别名]
class TestAliasService(unittest.TestCase):
@classmethod
def setUpClass(cls):
MongoClient().drop_database(DATABASE_NAME)
def setUp(self):
self.maxDiff = None
self.mongo_client = MongoClient()
self.player_1_id = ObjectId()
self.player_2_id = ObjectId()
self.player_3_id = ObjectId()
self.player_4_id = ObjectId()
self.player_5_id = ObjectId()
self.player_1 = Player(
'gaR',
['gar', 'garr'],
{'norcal': TrueskillRating(), 'texas': TrueskillRating()},
['norcal', 'texas'],
id=self.player_1_id)
self.player_2 = Player(
'sfat',
['sfat', 'miom | sfat'],
{'norcal': TrueskillRating()},
['norcal'],
id=self.player_2_id)
self.player_3 = Player(
'mango',
['mango', 'gar'],
{'norcal': TrueskillRating(trueskill_rating=trueskill.Rating(mu=2, sigma=3))},
['socal'],
id=self.player_3_id)
self.player_4 = Player(
'garpr|gar',
['garpr|gar'],
{'norcal': TrueskillRating(trueskill_rating=trueskill.Rating(mu=2, sigma=3))},
['norcal'],
id=self.player_4_id)
self.players = [self.player_1, self.player_2, self.player_3, self.player_4]
self.user_id_1 = 'abc123'
self.user_full_name_1 = 'Full Name'
self.user_admin_regions_1 = ['norcal']
self.user_1 = User(self.user_id_1, self.user_admin_regions_1, full_name=self.user_full_name_1)
self.users = [self.user_1]
self.region_1 = Region('norcal', 'Norcal')
Dao.insert_region(self.region_1, self.mongo_client, database_name=DATABASE_NAME)
self.norcal_dao = Dao('norcal', self.mongo_client, database_name=DATABASE_NAME)
for player in self.players:
self.norcal_dao.insert_player(player)
for user in self.users:
self.norcal_dao.insert_user(user)
def tearDown(self):
self.mongo_client.drop_database(DATABASE_NAME)
def test_get_player_suggestions_from_player_aliases(self):
self.assertEquals(alias_service.get_player_suggestions_from_player_aliases(self.norcal_dao, ['gar', 'garpr | gar', 'g a r r']),
{
"gar": [self.player_1, self.player_3],
"garpr | gar": [self.player_1, self.player_3, self.player_4],
"g a r r": [self.player_1]
})
def test_get_player_or_suggestions_from_player_aliases(self):
self.assertEquals(alias_service.get_player_or_suggestions_from_player_aliases(self.norcal_dao, ['gar', 'garpr | gar', 'g a r r']),
{
"gar": {
"player": self.player_1,
"suggestions": [self.player_1, self.player_3]
},
"garpr | gar": {
"player": None,
"suggestions": [self.player_1, self.player_3, self.player_4],
},
"g a r r": {
"player": None,
"suggestions": [self.player_1]
}
})
def test_get_top_suggestion_for_aliases(self):
suggestions = alias_service.get_top_suggestion_for_aliases(self.norcal_dao, ['gar', 'garpr | gar'])
expected_suggestions = {
"gar": self.player_1,
"garpr | gar": self.player_1,
}
self.assertEquals(suggestions, expected_suggestions)
def test_get_top_suggestion_for_aliases_none(self):
suggestions = alias_service.get_top_suggestion_for_aliases(self.norcal_dao, ['gar', 'garpr | gar', 'ASDFASDF'])
expected_suggestions = {
"gar": self.player_1,
"garpr | gar": self.player_1,
#.........这里部分代码省略.........
示例3: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import insert_user [as 别名]
#.........这里部分代码省略.........
username=self.superadmin_full_name,
salt='nacl',
hashed_password='browns',
admin_level='SUPER'
)
self.users = [self.user_1, self.user_2, self.superadmin]
self.region_1 = Region(id='norcal', display_name='Norcal')
self.region_2 = Region(id='texas', display_name='Texas')
self.regions = [self.region_1, self.region_2]
for region in self.regions:
Dao.insert_region(region, self.mongo_client,
database_name=DATABASE_NAME)
self.norcal_dao = Dao('norcal', self.mongo_client,
database_name=DATABASE_NAME)
for player in self.players:
self.norcal_dao.insert_player(player)
for tournament in self.tournaments:
self.norcal_dao.insert_tournament(tournament)
for pending_tournament in self.pending_tournaments:
self.norcal_dao.insert_pending_tournament(pending_tournament)
for ranking in self.rankings:
self.norcal_dao.insert_ranking(ranking)
for user in self.users:
self.norcal_dao.insert_user(user)
def tearDown(self):
self.mongo_client.drop_database(DATABASE_NAME)
def test_init_with_invalid_region(self):
# create a dao with an existing region
Dao('norcal', self.mongo_client, database_name=DATABASE_NAME)
# create a dao with a non existant region, should return none
self.assertIsNone(Dao('newregion', self.mongo_client,
database_name=DATABASE_NAME))
def test_get_all_regions(self):
# add another region
region = Region(id='newregion', display_name='New Region')
Dao.insert_region(region, self.mongo_client,
database_name=DATABASE_NAME)
regions = Dao.get_all_regions(
self.mongo_client, database_name=DATABASE_NAME)
self.assertEquals(len(regions), 3)
self.assertEquals(regions[0], region)
self.assertEquals(regions[1], self.region_1)
self.assertEquals(regions[2], self.region_2)
def test_get_player_by_id(self):
self.assertEquals(self.norcal_dao.get_player_by_id(
self.player_1_id), self.player_1)
self.assertEquals(self.norcal_dao.get_player_by_id(
self.player_2_id), self.player_2)
示例4: TestServer
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import insert_user [as 别名]
class TestServer(unittest.TestCase):
def setUp(self):
self.mongo_client_patcher = patch('server.mongo_client', new=mongomock.MongoClient())
self.mongo_client = self.mongo_client_patcher.start()
server.app.config['TESTING'] = True
self.app = server.app.test_client()
self.norcal_region = Region('norcal', 'Norcal')
self.texas_region = Region('texas', 'Texas')
Dao.insert_region(self.norcal_region, self.mongo_client)
Dao.insert_region(self.texas_region, self.mongo_client)
self.norcal_dao = Dao(NORCAL_REGION_NAME, mongo_client=self.mongo_client)
self.texas_dao = Dao(TEXAS_REGION_NAME, mongo_client=self.mongo_client)
self._import_files()
now = datetime(2014, 11, 1)
rankings.generate_ranking(self.norcal_dao, now=now)
rankings.generate_ranking(self.texas_dao, now=now)
self.user_id = 'asdf'
self.user_full_name = 'full name'
self.user_admin_regions = ['norcal', 'nyc']
self.user = User(self.user_id, self.user_admin_regions, full_name=self.user_full_name)
self.norcal_dao.insert_user(self.user)
def _import_files(self):
for f in NORCAL_FILES:
scraper = TioScraper(f[0], f[1])
self._import_players(scraper, self.norcal_dao)
player_map = self.norcal_dao.get_player_id_map_from_player_aliases(scraper.get_players())
self.norcal_dao.insert_tournament(Tournament.from_scraper('tio', scraper, player_map, self.norcal_dao.region_id))
for f in TEXAS_FILES:
scraper = TioScraper(f[0], f[1])
self._import_players(scraper, self.texas_dao)
player_map = self.texas_dao.get_player_id_map_from_player_aliases(scraper.get_players())
self.texas_dao.insert_tournament(Tournament.from_scraper('tio', scraper, player_map, self.texas_dao.region_id))
def _import_players(self, scraper, dao):
for player in scraper.get_players():
db_player = dao.get_player_by_alias(player)
if db_player is None:
db_player = Player(
player,
[player.lower()],
{dao.region_id: TrueskillRating()},
[dao.region_id])
dao.insert_player(db_player)
def test_get_region_list(self):
data = self.app.get('/regions').data
expected_region_dict = {
'regions': [
{'id': 'norcal', 'display_name': 'Norcal'},
{'id': 'texas', 'display_name': 'Texas'}
]
}
self.assertEquals(json.loads(data), expected_region_dict)
def test_get_player_list(self):
def for_region(json_data, dao):
self.assertEquals(json_data.keys(), ['players'])
players_list = json_data['players']
players_from_db = dao.get_all_players()
self.assertEquals(len(players_list), len(players_from_db))
for player in players_list:
expected_keys = set(['id', 'name'])
self.assertEquals(set(player.keys()), expected_keys)
self.assertEquals(ObjectId(player['id']), dao.get_player_by_alias(player['name']).id)
data = self.app.get('/norcal/players').data
json_data = json.loads(data)
self.assertEquals(len(json_data['players']), 65)
for_region(json_data, self.norcal_dao)
data = self.app.get('/texas/players').data
json_data = json.loads(data)
self.assertEquals(len(json_data['players']), 41)
for_region(json_data, self.texas_dao)
def test_get_player_list_with_alias(self):
player = self.norcal_dao.get_player_by_alias('gar')
data = self.app.get('/norcal/players?alias=gar').data
json_data = json.loads(data)
self.assertEquals(len(json_data['players']), 1)
json_player = json_data['players'][0]
expected_keys = set(['id', 'name'])
self.assertEquals(set(json_player.keys()), expected_keys)
self.assertEquals(ObjectId(json_player['id']), player.id)
def test_get_player_list_case_insensitive(self):
player = self.norcal_dao.get_player_by_alias('gar')
#.........这里部分代码省略.........