本文整理汇总了Python中dao.Dao.insert_ranking方法的典型用法代码示例。如果您正苦于以下问题:Python Dao.insert_ranking方法的具体用法?Python Dao.insert_ranking怎么用?Python Dao.insert_ranking使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dao.Dao
的用法示例。
在下文中一共展示了Dao.insert_ranking方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import insert_ranking [as 别名]
class TestDAO(unittest.TestCase):
def setUp(self):
self.region = 'test'
self.mongo_client = mongomock.MongoClient()
self.dao = Dao(self.region, mongo_client=self.mongo_client, new=True)
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'], TrueskillRating(), False, id=self.player_1_id)
self.player_2 = Player('sfat', ['sfat', 'miom | sfat'], TrueskillRating(), False, id=self.player_2_id)
self.player_3 = Player('mango', ['mango'],
TrueskillRating(trueskill_rating=trueskill.Rating(mu=2, sigma=3)),
True, id=self.player_3_id)
self.player_4 = Player('shroomed', ['shroomed'], TrueskillRating(), False, id=self.player_4_id)
self.player_5 = Player('pewpewu', ['pewpewu'], TrueskillRating(), False, id=self.player_5_id)
# only includes players 1-3
self.players = [self.player_1, self.player_2, self.player_3]
self.tournament_id_1 = ObjectId()
self.tournament_type_1 = 'tio'
self.tournament_raw_1 = 'raw1'
self.tournament_date_1 = datetime(2013, 10, 16)
self.tournament_name_1 = 'tournament 1'
self.tournament_players_1 = [self.player_1_id, self.player_2_id, self.player_3_id, self.player_4_id]
self.tournament_matches_1 = [
MatchResult(winner=self.player_1_id, loser=self.player_2_id),
MatchResult(winner=self.player_3_id, loser=self.player_4_id)
]
# tournament 2 is earlier than tournament 1, but inserted after
self.tournament_id_2 = ObjectId()
self.tournament_type_2 = 'challonge'
self.tournament_raw_2 = 'raw2'
self.tournament_date_2 = datetime(2013, 10, 10)
self.tournament_name_2 = 'tournament 2'
self.tournament_players_2 = [self.player_5_id, self.player_2_id, self.player_3_id, self.player_4_id]
self.tournament_matches_2 = [
MatchResult(winner=self.player_5_id, loser=self.player_2_id),
MatchResult(winner=self.player_3_id, loser=self.player_4_id)
]
self.tournament_1 = Tournament(self.tournament_type_1,
self.tournament_raw_1,
self.tournament_date_1,
self.tournament_name_1,
self.tournament_players_1,
self.tournament_matches_1,
id=self.tournament_id_1)
self.tournament_2 = Tournament(self.tournament_type_2,
self.tournament_raw_2,
self.tournament_date_2,
self.tournament_name_2,
self.tournament_players_2,
self.tournament_matches_2,
id=self.tournament_id_2)
self.tournament_ids = [self.tournament_id_1, self.tournament_id_2]
self.tournaments = [self.tournament_1, self.tournament_2]
self.ranking_entry_1 = RankingEntry(1, self.player_1_id, 20)
self.ranking_entry_2 = RankingEntry(2, self.player_2_id, 19)
self.ranking_entry_3 = RankingEntry(3, self.player_3_id, 17.5)
self.ranking_entry_4 = RankingEntry(3, self.player_4_id, 16.5)
self.ranking_time_1 = datetime(2013, 4, 20)
self.ranking_time_2 = datetime(2013, 4, 21)
self.ranking_1 = Ranking(self.ranking_time_1, self.tournament_ids,
[self.ranking_entry_1, self.ranking_entry_2, self.ranking_entry_3])
self.ranking_2 = Ranking(self.ranking_time_2, self.tournament_ids,
[self.ranking_entry_1, self.ranking_entry_2, self.ranking_entry_4])
self.rankings = [self.ranking_1, self.ranking_2]
for player in self.players:
self.dao.add_player(player)
for tournament in self.tournaments:
self.dao.insert_tournament(tournament)
for ranking in self.rankings:
self.dao.insert_ranking(ranking)
def test_init_with_invalid_region(self):
print Dao.get_all_regions(mongo_client=self.mongo_client)
# create a dao with an existing region
Dao(self.region, mongo_client=self.mongo_client, new=False)
# create a dao with a new region
with self.assertRaises(RegionNotFoundException):
Dao('newregion', mongo_client=self.mongo_client, new=False)
def test_get_all_regions(self):
# add another region
region = 'newregion'
Dao(region, mongo_client=self.mongo_client, new=True)
#.........这里部分代码省略.........
示例2: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import insert_ranking [as 别名]
#.........这里部分代码省略.........
self.rankings = [self.ranking_1, self.ranking_2, self.ranking_3]
self.user_id_1 = 'abc123'
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()))
示例3: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import insert_ranking [as 别名]
#.........这里部分代码省略.........
self.superadmin = User(
id=self.superadmin_id,
user_admin_regions=self.superadmin_admin_regions,
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(