Example #1
0
    def _reset(self):
        RedisDB.connect()
        MongoDB.connect()

        GiftCodeUsingLog.objects.all().delete()
        # GiftCodeRecord.objects.all().delete()
        # GiftCodeGen.objects.all().delete()
        # GiftCode.objects.all().delete()

        MailHistoryRecord.objects.all().delete()
        Statistics.objects.all().delete()
        Character.objects.all().delete()
        ForbidChat.objects.all().delete()
        AccountBan.objects.all().delete()
        AccountLoginLog.objects.all().delete()
        AccountThird.objects.all().delete()
        AccountRegular.objects.all().delete()
        Account.objects.all().delete()
        GeTuiClientID.objects.all().delete()

        RedisDB.get().flushall()

        for mc in MongoDB.DBS.values():
            mc.client.drop_database(mc.name)

        for s in Server.objects.all():
            ensure_index(s.id)
Example #2
0
    def _reset(self):
        RedisDB.connect()
        MongoDB.connect()

        GiftCodeUsingLog.objects.all().delete()
        # GiftCodeRecord.objects.all().delete()
        # GiftCodeGen.objects.all().delete()
        # GiftCode.objects.all().delete()

        MailHistoryRecord.objects.all().delete()
        Statistics.objects.all().delete()
        Character.objects.all().delete()
        ForbidChat.objects.all().delete()
        AccountBan.objects.all().delete()
        AccountLoginLog.objects.all().delete()
        AccountThird.objects.all().delete()
        AccountRegular.objects.all().delete()
        Account.objects.all().delete()
        GeTuiClientID.objects.all().delete()

        RedisDB.get().flushall()

        for mc in MongoDB.DBS.values():
            mc.client.drop_database(mc.name)

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

    RedisDB.get().flushdb()
Example #34
0
 def teardown(self):
     MongoDB.get(1).notification.delete_one({'_id': 1})
Example #35
0
    def __call__(self, request):
        RedisDB.connect()
        MongoDB.connect()

        return self.get_response(request)
Example #36
0
 def teardown(self):
     MongoDB.get(1).test_counter.drop()
Example #37
0
 def teardown(self):
     MongoDB.get(1).test_counter.drop()
Example #38
0
 def get_counter_value(self):
     return MongoDB.get(1).test_counter.find_one({'_id': 1})['value']
Example #39
0
 def incr_counter(self):
     value = self.get_counter_value()
     MongoDB.get(1).test_counter.update_one({'_id': 1},
                                            {'$set': {
                                                'value': value + 1
                                            }})
Example #40
0
 def incr_counter(self):
     value = self.get_counter_value()
     MongoDB.get(1).test_counter.update_one({'_id': 1}, {'$set': {'value': value+1}})