示例#1
0
    def test_tg_get_file_from_attachment(self):
        mngr = TGManager("token")

        env = self.loop.run_until_complete(
            mngr.get_environment({"message": {
                "chat": {
                    "id": 1
                }
            }}))

        async def request(_, method, **kwargs):
            self.assertEqual(kwargs["file_id"], 13)

            return TGResponse(False, (), {"file_path": "path"})

        mngr.request = types.MethodType(request, mngr)

        async def request_file(_, path):
            self.assertEqual(path, "path")

            return "file"

        mngr.request_file = types.MethodType(request_file, mngr)

        attachment = Attachment("photo", 13, None, None, None, None)

        file = self.loop.run_until_complete(
            env.get_file_from_attachment(attachment))

        self.assertEqual(file, "file")
示例#2
0
    def test_tg_request_file_none(self):
        mngr = TGManager("token")

        mngr.file_url = "wrong_url"

        res = self.loop.run_until_complete(mngr.request_file("path"))

        self.assertEqual(res, None)

        self.loop.run_until_complete(mngr.dispose())