示例#1
0
    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)
示例#2
0
    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)
示例#3
0
    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': []
            }})
示例#4
0
    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})
示例#5
0
    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': []
            }}
        )
示例#6
0
    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})
示例#7
0
    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!")
示例#8
0
    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
        )
示例#9
0
    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
        )
示例#10
0
    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!")
示例#11
0
    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})
示例#12
0
    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})
示例#13
0
    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
示例#14
0
    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
示例#15
0
    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
示例#16
0
    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
示例#17
0
    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
示例#18
0
    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
示例#19
0
    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
示例#20
0
    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
示例#21
0
    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]
示例#22
0
    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
示例#23
0
 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': []
         }}
     )
示例#24
0
    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")
示例#25
0
    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")
示例#26
0
 def teardown_class(cls):
     MongoDB.get(1).character.delete_one({'_id': 2})
示例#27
0
 def setup(self):
     MongoDB.get(1).test_counter.insert_one({'_id': 1, 'value': 0})
示例#28
0
 def get_counter_value(self):
     return MongoDB.get(1).test_counter.find_one({'_id': 1})['value']
示例#29
0
def teardown():
    from core.db import MongoDB, RedisDB
    mongo = MongoDB.get(1)
    mongo.client.drop_database(mongo.name)

    RedisDB.get().flushdb()
示例#30
0
 def teardown(self):
     MongoDB.get(1).notification.delete_one({'_id': 1})
示例#31
0
 def incr_counter(self):
     value = self.get_counter_value()
     MongoDB.get(1).test_counter.update_one({'_id': 1}, {'$set': {'value': value+1}})
示例#32
0
 def teardown(self):
     MongoDB.get(1).notification.delete_one({'_id': 1})
示例#33
0
 def get_counter_value(self):
     return MongoDB.get(1).test_counter.find_one({'_id': 1})['value']
示例#34
0
 def teardown(self):
     MongoDB.get(1).test_counter.drop()
示例#35
0
 def setup(self):
     MongoDB.get(1).test_counter.insert_one({'_id':1, 'value': 0})
示例#36
0
 def incr_counter(self):
     value = self.get_counter_value()
     MongoDB.get(1).test_counter.update_one({'_id': 1},
                                            {'$set': {
                                                'value': value + 1
                                            }})
示例#37
0
 def teardown(self):
     MongoDB.get(1).test_counter.drop()