コード例 #1
0
ファイル: tests.py プロジェクト: zhifuliu/sanguo-server
    def test_plunder_list(self):
        req = protomsg.PlunderListRequest()
        req.session = self.session

        data = tests.pack_data(req)
        res = tests.make_request('/plunder/list/', data)
        msgs = tests.unpack_data(res)
コード例 #2
0
ファイル: middleware.py プロジェクト: hx002/sanguo-server
    def process_response(self, request, response):
        if response.status_code != 200:
            return response

        if request.path.startswith('/api/'):
            return response

        char_id = getattr(request, '_char_id', None)
        if char_id:
            other_msgs = message_get(char_id)
        else:
            other_msgs = []

        if not response.content:
            num_of_msgs = len(other_msgs)
            data = '%s%s' % (
                NUM_FIELD.pack(num_of_msgs),
                ''.join(other_msgs)
            )
        else:
            ret_msg_amount = getattr(response, '_msg_amount', 1)
            num_of_msgs = len(other_msgs) + ret_msg_amount
            data = '%s%s%s' % (
                NUM_FIELD.pack(num_of_msgs),
                response.content,
                ''.join(other_msgs)
            )

        # FOR DEBUG
        # print repr(data)
        _unpakced_data = app_test_helper.unpack_data(data)
        _msg_type = [RESPONSE_NOTIFY_TYPE_REV[a] for a, b, c in _unpakced_data]
        print _msg_type
        # DEBUG END
        return HttpResponse(data, content_type='text/plain')
コード例 #3
0
ファイル: middleware.py プロジェクト: wyrover/sanguo-server
    def process_response(self, request, response):
        if response.status_code != 200:
            return response

        if request.path.startswith('/api/'):
            return response

        char_id = getattr(request, '_char_id', None)
        if char_id:
            other_msgs = message_get(char_id)
        else:
            other_msgs = []

        if not response.content:
            num_of_msgs = len(other_msgs)
            data = '%s%s' % (NUM_FIELD.pack(num_of_msgs), ''.join(other_msgs))
        else:
            ret_msg_amount = getattr(response, '_msg_amount', 1)
            num_of_msgs = len(other_msgs) + ret_msg_amount
            data = '%s%s%s' % (NUM_FIELD.pack(num_of_msgs), response.content,
                               ''.join(other_msgs))

        # FOR DEBUG
        # print repr(data)
        _unpakced_data = app_test_helper.unpack_data(data)
        _msg_type = [RESPONSE_NOTIFY_TYPE_REV[a] for a, b, c in _unpakced_data]
        print _msg_type
        # DEBUG END
        return HttpResponse(data, content_type='text/plain')
コード例 #4
0
    def test_arena_battle(self):
        req = protomsg.ArenaRequest()
        req.session = self.session

        data = tests.pack_data(req)
        res = tests.make_request('/pvp/', data)
        msgs = tests.unpack_data(res)
コード例 #5
0
ファイル: tests.py プロジェクト: yaosj/sanguo-server
    def test_get(self):
        req = protomsg.GetHeroRequest()
        req.session = self.session
        req.id = 1

        data = app_test_helper.pack_data(req)
        res = app_test_helper.make_request("/hero/get/", data)
        msgs = app_test_helper.unpack_data(res)
コード例 #6
0
ファイル: tests.py プロジェクト: zhifuliu/sanguo-server
    def test_plunder_battle(self):
        req = protomsg.PlunderRequest()
        req.session = self.session
        req.id = self.other_char_id

        data = tests.pack_data(req)
        res = tests.make_request('/plunder/', data)
        msgs = tests.unpack_data(res)
コード例 #7
0
ファイル: tests.py プロジェクト: zhifuliu/sanguo-server
    def test_get(self):
        req = protomsg.GetHeroRequest()
        req.session = self.session
        req.id = 1

        data = app_test_helper.pack_data(req)
        res = app_test_helper.make_request('/hero/get/', data)
        msgs = app_test_helper.unpack_data(res)
コード例 #8
0
ファイル: tests.py プロジェクト: zhifuliu/sanguo-server
    def _cancel(self):
        req = protomsg.HangCancelRequest()
        req.session = self.session

        data = tests.pack_data(req)
        res = tests.make_request('/hang/cancel/', data)
        msgs = tests.unpack_data(res)

        return msgs
コード例 #9
0
ファイル: tests.py プロジェクト: hx002/sanguo-server
    def _cancel(self):
        req = protomsg.HangCancelRequest()
        req.session = self.session

        data = tests.pack_data(req)
        res = tests.make_request('/hang/cancel/', data)
        msgs = tests.unpack_data(res)

        return msgs
コード例 #10
0
ファイル: tests.py プロジェクト: zhifuliu/sanguo-server
    def _cmd(self, action, tp, param):
        req = protomsg.TestRequest()
        req.session = self.session
        req.action = action
        req.tp = tp
        req.param = param

        data = tests.pack_data(req)
        res = tests.make_request('/test/', data)
        msgs = tests.unpack_data(res)
コード例 #11
0
ファイル: tests.py プロジェクト: hx002/sanguo-server
    def _hang(self):
        req = protomsg.HangRequest()
        req.session = self.session
        req.stage_id = 1

        data = tests.pack_data(req)
        res = tests.make_request('/hang/', data)
        msgs = tests.unpack_data(res)

        return msgs
コード例 #12
0
ファイル: tests.py プロジェクト: zhifuliu/sanguo-server
    def _hang(self):
        req = protomsg.HangRequest()
        req.session = self.session
        req.stage_id = 1

        data = tests.pack_data(req)
        res = tests.make_request('/hang/', data)
        msgs = tests.unpack_data(res)

        return msgs
コード例 #13
0
ファイル: tests.py プロジェクト: hx002/sanguo-server
 def _step_up(self, _id, ret=0):
     req = protomsg.StepUpEquipRequest()
     req.session = self.session
     req.id = _id
     data = app_test_helper.pack_data(req)
     res = app_test_helper.make_request('/equip/stepup/', data)
     msgs = app_test_helper.unpack_data(res)
     for a, b, c in msgs:
         if a == protomsg.RESPONSE_NOTIFY_TYPE["StepUpEquipResponse"]:
             data = protomsg.StepUpEquipResponse()
             data.ParseFromString(c)
             self.assertEqual(data.ret, ret)
コード例 #14
0
ファイル: tests.py プロジェクト: zhifuliu/sanguo-server
 def _step_up(self, _id, ret=0):
     req = protomsg.StepUpEquipRequest()
     req.session = self.session
     req.id = _id
     data = app_test_helper.pack_data(req)
     res = app_test_helper.make_request('/equip/stepup/', data)
     msgs = app_test_helper.unpack_data(res)
     for a, b, c in msgs:
         if a == protomsg.RESPONSE_NOTIFY_TYPE["StepUpEquipResponse"]:
             data = protomsg.StepUpEquipResponse()
             data.ParseFromString(c)
             self.assertEqual(data.ret, ret)
コード例 #15
0
ファイル: tests.py プロジェクト: yaosj/sanguo-server
    def _step_up(self, _id, ret=0):
        req = protomsg.HeroStepUpRequest()
        req.session = self.session
        req.id = _id

        data = app_test_helper.pack_data(req)
        res = app_test_helper.make_request("/hero/stepup/", data)
        msgs = app_test_helper.unpack_data(res)

        for id_of_msg, len_of_msg, msg in msgs:
            if id_of_msg == protomsg.RESPONSE_NOTIFY_TYPE["HeroStepUpResponse"]:
                data = protomsg.HeroStepUpResponse()
                data.ParseFromString(msg)
コード例 #16
0
ファイル: tests.py プロジェクト: hx002/sanguo-server
    def _pve(self, stage_id):
        req = protomsg.PVERequest()
        req.session = self.session
        req.stage_id = stage_id

        data = tests.pack_data(req)
        res = tests.make_request('/pve/', data)
        msgs = tests.unpack_data(res)

        for id_of_msg, len_of_msg, msg in msgs:
            if id_of_msg == RESPONSE_NOTIFY_TYPE["PVEResponse"]:
                data = protomsg.PVEResponse()
                data.ParseFromString(msg)
                self.assertEqual(data.stage_id, stage_id)
コード例 #17
0
    def _step_up(self, _id, ret=0):
        req = protomsg.HeroStepUpRequest()
        req.session = self.session
        req.id = _id

        data = app_test_helper.pack_data(req)
        res = app_test_helper.make_request('/hero/stepup/', data)
        msgs = app_test_helper.unpack_data(res)

        for id_of_msg, len_of_msg, msg in msgs:
            if id_of_msg == protomsg.RESPONSE_NOTIFY_TYPE[
                    "HeroStepUpResponse"]:
                data = protomsg.HeroStepUpResponse()
                data.ParseFromString(msg)
コード例 #18
0
    def _open(self, mail_id, ret=0):
        req = protomsg.OpenMailRequest()
        req.session = self.session
        req.id = mail_id

        data = app_test_helper.pack_data(req)
        res = app_test_helper.make_request('/mail/open/', data)
        msgs = app_test_helper.unpack_data(res)

        for id_of_msg, len_of_msg, msg in msgs:
            if id_of_msg == protomsg.RESPONSE_NOTIFY_TYPE["OpenMailResponse"]:
                d = protomsg.OpenMailResponse()
                d.ParseFromString(msg)
                self.assertEqual(d.ret, ret)
コード例 #19
0
ファイル: tests.py プロジェクト: wyrover/sanguo-server
    def _get_attach(self, mail_id, ret=0):
        req = protomsg.GetAttachmentRequest()
        req.session = self.session
        req.id = mail_id

        data = app_test_helper.pack_data(req)
        res = app_test_helper.make_request('/mail/getattachment/', data)
        msgs = app_test_helper.unpack_data(res)

        for id_of_msg, len_of_msg, msg in msgs:
            if id_of_msg == protomsg.RESPONSE_NOTIFY_TYPE["GetAttachmentResponse"]:
                d = protomsg.GetAttachmentResponse()
                d.ParseFromString(msg)
                self.assertEqual(d.ret, ret)
コード例 #20
0
ファイル: tests.py プロジェクト: zhifuliu/sanguo-server
    def _pve(self, stage_id):
        req = protomsg.PVERequest()
        req.session = self.session
        req.stage_id = stage_id

        data = tests.pack_data(req)
        res = tests.make_request('/pve/', data)
        msgs = tests.unpack_data(res)

        for id_of_msg, len_of_msg, msg in msgs:
            if id_of_msg == RESPONSE_NOTIFY_TYPE["PVEResponse"]:
                data = protomsg.PVEResponse()
                data.ParseFromString(msg)
                self.assertEqual(data.stage_id, stage_id)
コード例 #21
0
    def _accept(self, _id, ret=0, session=None):
        if not session:
            session = self.session
        req = protomsg.FriendAcceptRequest()
        req.session = session
        req.id = _id

        data = app_test_helper.pack_data(req)
        res = app_test_helper.make_request('/friend/accept/', data)
        msgs = app_test_helper.unpack_data(res)

        for id_of_msg, _, msg in msgs:
            if id_of_msg == RESPONSE_NOTIFY_TYPE['FriendAcceptResponse']:
                data = protomsg.FriendAcceptResponse()
                data.ParseFromString(msg)
                self.assertEqual(data.ret, ret)
コード例 #22
0
ファイル: tests.py プロジェクト: hx002/sanguo-server
    def _accept(self, _id, ret=0, session=None):
        if not session:
            session = self.session
        req = protomsg.FriendAcceptRequest()
        req.session = session
        req.id = _id

        data = app_test_helper.pack_data(req)
        res = app_test_helper.make_request('/friend/accept/', data)
        msgs = app_test_helper.unpack_data(res)

        for id_of_msg, _, msg in msgs:
            if id_of_msg == RESPONSE_NOTIFY_TYPE['FriendAcceptResponse']:
                data = protomsg.FriendAcceptResponse()
                data.ParseFromString(msg)
                self.assertEqual(data.ret, ret)
コード例 #23
0
ファイル: tests.py プロジェクト: hx002/sanguo-server
    def _set_socket(self, hero_id, weapon_id, armor_id, jewelry_id, ret):
        req = protomsg.SetSocketRequest()
        req.session = self.session
        req.socket.id = 1
        req.socket.hero_id = hero_id
        req.socket.weapon_id = weapon_id
        req.socket.armor_id = armor_id
        req.socket.jewelry_id = jewelry_id

        data = app_test_helper.pack_data(req)
        res = app_test_helper.make_request('/socket/set/', data)
        msgs = app_test_helper.unpack_data(res)

        for id_of_msg, len_of_msg, msg in msgs:
            if id_of_msg == RESPONSE_NOTIFY_TYPE["SetSocketResponse"]:
                data = protomsg.SetSocketResponse()
                data.ParseFromString(msg)
                self.assertEqual(data.ret, ret)
コード例 #24
0
    def _set_socket(self, hero_id, weapon_id, armor_id, jewelry_id, ret):
        req = protomsg.SetSocketRequest()
        req.session = self.session
        req.socket.id = 1
        req.socket.hero_id = hero_id
        req.socket.weapon_id = weapon_id
        req.socket.armor_id = armor_id
        req.socket.jewelry_id = jewelry_id

        data = app_test_helper.pack_data(req)
        res = app_test_helper.make_request('/socket/set/', data)
        msgs = app_test_helper.unpack_data(res)

        for id_of_msg, len_of_msg, msg in msgs:
            if id_of_msg == RESPONSE_NOTIFY_TYPE["SetSocketResponse"]:
                data = protomsg.SetSocketResponse()
                data.ParseFromString(msg)
                self.assertEqual(data.ret, ret)
コード例 #25
0
ファイル: tests.py プロジェクト: hx002/sanguo-server
    def _embed(self, equip_id, hole_id, gem_id, ret=0):
        if gem_id == 0:
            req = protomsg.UnEmbedGemRequest()
            url = '/equip/unembed/'
            response_name = "UnEmbedGemResponse"
        else:
            req = protomsg.EmbedGemRequest()
            req.gem_id = gem_id
            url = '/equip/embed/'
            response_name = "EmbedGemResponse"

        req.session = self.session
        req.equip_id = equip_id
        req.hole_id = hole_id

        data = app_test_helper.pack_data(req)
        res = app_test_helper.make_request(url, data)
        msgs = app_test_helper.unpack_data(res)

        for id_of_msg, _, msg in msgs:
            if id_of_msg == RESPONSE_NOTIFY_TYPE[response_name]:
                data = getattr(protomsg, response_name)()
                data.ParseFromString(msg)
                self.assertEqual(data.ret, ret)
コード例 #26
0
ファイル: tests.py プロジェクト: zhifuliu/sanguo-server
    def _embed(self, equip_id, hole_id, gem_id, ret=0):
        if gem_id == 0:
            req = protomsg.UnEmbedGemRequest()
            url = '/equip/unembed/'
            response_name = "UnEmbedGemResponse"
        else:
            req = protomsg.EmbedGemRequest()
            req.gem_id = gem_id
            url = '/equip/embed/'
            response_name = "EmbedGemResponse"

        req.session = self.session
        req.equip_id = equip_id
        req.hole_id = hole_id

        data = app_test_helper.pack_data(req)
        res = app_test_helper.make_request(url, data)
        msgs = app_test_helper.unpack_data(res)

        for id_of_msg, _, msg in msgs:
            if id_of_msg == RESPONSE_NOTIFY_TYPE[response_name]:
                data = getattr(protomsg, response_name)()
                data.ParseFromString(msg)
                self.assertEqual(data.ret, ret)
コード例 #27
0
ファイル: tests.py プロジェクト: zhifuliu/sanguo-server
 def test_refresh(self):
     req = protomsg.GetHeroRefreshRequest()
     req.session = self.session
     data = app_test_helper.pack_data(req)
     res = app_test_helper.make_request('/heropanel/refresh/', data)
     msg = app_test_helper.unpack_data(res)
コード例 #28
0
 def test_player_list(self):
     req = protomsg.PlayerListRequest()
     req.session = self.session
     data = app_test_helper.pack_data(req)
     res = app_test_helper.make_request('/friend/player-list/', data)
     msgs = app_test_helper.unpack_data(res)
コード例 #29
0
ファイル: tests.py プロジェクト: yaosj/sanguo-server
 def test_refresh(self):
     req = protomsg.GetHeroRefreshRequest()
     req.session = self.session
     data = app_test_helper.pack_data(req)
     res = app_test_helper.make_request("/heropanel/refresh/", data)
     msg = app_test_helper.unpack_data(res)
コード例 #30
0
ファイル: tests.py プロジェクト: hx002/sanguo-server
 def test_player_list(self):
     req = protomsg.PlayerListRequest()
     req.session = self.session
     data = app_test_helper.pack_data(req)
     res = app_test_helper.make_request('/friend/player-list/', data)
     msgs = app_test_helper.unpack_data(res)