def test_get_statistics(self): doc = MongoDB.get(1).character.find_one({'_id': 1}, {'league_group': 1}) group_id = doc['league_group'] group_doc = MongoDB.get(1).league_group.find_one({'_id': group_id}) for i in group_doc['clubs'].keys(): League(1, 1).get_statistics(i)
def teardown_class(cls): LeagueGame.clean(1) MongoDB.get(1).staff.delete_one({'_id': 1}) MongoDB.get(1).character.update_one( {'_id': 1}, {'$set': { 'club.match_staffs': [], 'club.tibu_staffs': [] }})
def reset(self): MongoDB.get(1).character.update_one({'_id': 1}, { '$set': { 'challenge_id': ConfigChallengeMatch.FIRST_ID, 'club.match_staffs': [], 'club.tibu_staffs': [] } }) MongoDB.get(1).staff.delete_one({'_id': 1})
def teardown_class(cls): LeagueGame.clean(1) MongoDB.get(1).staff.delete_one({'_id': 1}) MongoDB.get(1).character.update_one( {'_id': 1}, {'$set': { 'club.match_staffs': [], 'club.tibu_staffs': [] }} )
def reset(self): MongoDB.get(1).character.update_one( {'_id': 1}, {'$set': { 'challenge_id': ConfigChallengeMatch.FIRST_ID, 'club.match_staffs': [], 'club.tibu_staffs': [] }} ) MongoDB.get(1).staff.delete_one({'_id': 1})
def test_match_all_finished(self): MongoDB.get(1).character.update_one( {'_id': 1}, {'$set': {'challenge_id': 0}} ) try: Challenge(1, 1).start() except GameException as e: assert e.error_id == ConfigErrorMessage.get_error_id("CHALLENGE_ALL_FINISHED") else: raise Exception("can not be here!")
def make_friend_request(self): MongoDB.get(1).friend.update_one( {'_id': 1}, {'$set': {'friends.2': FRIEND_STATUS_PEER_CONFIRM}}, upsert=True ) MongoDB.get(1).friend.update_one( {'_id': 2}, {'$set': {'friends.1': FRIEND_STATUS_SELF_CONFIRM}}, upsert=True )
def set_friend_data(self): MongoDB.get(1).friend.update_one( {'_id': 1}, {'$set': {'friends.2': FRIEND_STATUS_OK}}, upsert=True ) MongoDB.get(1).friend.update( {'_id': 2}, {'$set': {'friends.1': FRIEND_STATUS_OK}}, upsert=True )
def test_match_all_finished(self): MongoDB.get(1).character.update_one({'_id': 1}, {'$set': { 'challenge_id': 0 }}) try: Challenge(1, 1).start() except GameException as e: assert e.error_id == ConfigErrorMessage.get_error_id( "CHALLENGE_ALL_FINISHED") else: raise Exception("can not be here!")
def reset(self): MongoDB.get(1).character.update_one({'_id': 1}, { '$set': { 'club.gold': 0, 'club.diamond': 0, 'club.level': 1, 'club.renown': 0, 'club.match_staffs': [], 'club.tibu_staffs': [] } }) MongoDB.get(1).staff.delete_one({'_id': 1})
def reset(self): MongoDB.get(1).character.update_one( {'_id': 1}, {'$set': { 'club.gold': 0, 'club.diamond': 0, 'club.level': 1, 'club.renown': 0, 'club.match_staffs': [], 'club.tibu_staffs': [] }} ) MongoDB.get(1).staff.delete_one({'_id': 1})
def test_add(self): FriendManager(1, 1).add('two') data = MongoDB.get(1).friend.find_one( {'_id': 1}, {'friends.2': 1} ) assert data['friends']['2'] == FRIEND_STATUS_PEER_CONFIRM
def test_level_up_to_two(self): renown = club_level_up_need_renown(1) + 1 club = Club(1, 1) club.update(renown=renown) doc = MongoDB.get(1).character.find_one({'_id': 1}, {'club': 1}) assert doc['club']['level'] == 2 assert club.level == 2
def test_add_gold(self): gold = 99 club = Club(1, 1) club.update(gold=gold) doc = MongoDB.get(1).character.find_one({'_id': 1}, {'club': 1}) assert doc['club']['gold'] == gold assert club.gold == gold
def test_set_policy(self): policy = random.choice(ConfigPolicy.INSTANCES.keys()) club = Club(1, 1) club.set_policy(policy) assert club.policy == policy doc = MongoDB.get(1).character.find_one({'_id': 1}, {'club.policy': 1}) assert doc['club']['policy'] == policy
def test_level_up_to_five(self): renown = 0 for i in range(1, 5): renown += club_level_up_need_renown(i) renown += 1 club = Club(1, 1) club.update(renown=renown) doc = MongoDB.get(1).character.find_one({'_id': 1}, {'club': 1}) assert doc['club']['level'] == 5 assert club.level == 5
def db(cls, server_id): """ :rtype : pymongo.collection.Collection """ key = "{0}{1}".format(cls.__name__, server_id) if key not in collection_cache: write_concern = cls.get_write_concern() coll = Collection(MongoDB.get(server_id), cls.COLLECTION, write_concern=write_concern) collection_cache[key] = coll return collection_cache[key]
def reset(self): MongoDB.get(1).friend.drop() MongoDB.get(1).staff.delete_many({'_id': {'$in': [1, 2]}}) MongoDB.get(1).character.update_many( {'_id': {'$in': [1,2]}}, {'$set': { 'club.match_staffs': [], 'club.tibu_staffs': [] }} )
def test_set_policy_not_exists(self): def _get_policy(): while True: policy = random.randint(1, 1000) if policy not in ConfigPolicy.INSTANCES.keys(): return policy policy = _get_policy() club = Club(1, 1) try: club.set_policy(policy) except GameException as e: assert e.error_id == ConfigErrorMessage.get_error_id("POLICY_NOT_EXIST") doc = MongoDB.get(1).character.find_one({'_id': 1}, {'club.policy': 1}) assert doc['club']['policy'] != policy else: raise Exception("can not be here")
def test_set_policy_not_exists(self): def _get_policy(): while True: policy = random.randint(1, 1000) if policy not in ConfigPolicy.INSTANCES.keys(): return policy policy = _get_policy() club = Club(1, 1) try: club.set_policy(policy) except GameException as e: assert e.error_id == ConfigErrorMessage.get_error_id( "POLICY_NOT_EXIST") doc = MongoDB.get(1).character.find_one({'_id': 1}, {'club.policy': 1}) assert doc['club']['policy'] != policy else: raise Exception("can not be here")
def teardown_class(cls): MongoDB.get(1).character.delete_one({'_id': 2})
def setup(self): MongoDB.get(1).test_counter.insert_one({'_id': 1, 'value': 0})
def get_counter_value(self): return MongoDB.get(1).test_counter.find_one({'_id': 1})['value']
def teardown(): from core.db import MongoDB, RedisDB mongo = MongoDB.get(1) mongo.client.drop_database(mongo.name) RedisDB.get().flushdb()
def teardown(self): MongoDB.get(1).notification.delete_one({'_id': 1})
def incr_counter(self): value = self.get_counter_value() MongoDB.get(1).test_counter.update_one({'_id': 1}, {'$set': {'value': value+1}})
def teardown(self): MongoDB.get(1).test_counter.drop()
def setup(self): MongoDB.get(1).test_counter.insert_one({'_id':1, 'value': 0})
def incr_counter(self): value = self.get_counter_value() MongoDB.get(1).test_counter.update_one({'_id': 1}, {'$set': { 'value': value + 1 }})