# Code generated by lark_sdk_gen. DO NOT EDIT.

import unittest
import pylark
import pytest
from tests.test_conf import app_all_permission, app_no_permission
from tests.test_helper import mock_get_tenant_access_token_failed


def mock(*args, **kwargs):
    raise pylark.PyLarkError(scope="scope", func="func", code=1, msg="mock-failed")


def mock_raw_request(*args, **kwargs):
    raise pylark.PyLarkError(
        scope="scope", func="func", code=1, msg="mock-raw-request-failed"
    )


# mock get token
class TestJssdkSampleMockGetTokenFailed(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        super(TestJssdkSampleMockGetTokenFailed, self).__init__(*args, **kwargs)
        self.cli = app_all_permission.ins()
        self.cli.auth.get_tenant_access_token = mock_get_tenant_access_token_failed
        self.cli.auth.get_app_access_token = mock_get_tenant_access_token_failed
        self.module_cli = self.cli.jssdk

    def test_mock_get_token_get_jssdk_ticket(self):
        with pytest.raises(pylark.PyLarkError) as e:
            self.module_cli.get_jssdk_ticket(pylark.GetJssdkTicketReq())

        assert "msg=failed" in f"{e}"


# mock mock self func
class TestJssdkSampleMockSelfFuncFailed(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        super(TestJssdkSampleMockSelfFuncFailed, self).__init__(*args, **kwargs)
        self.cli = app_all_permission.ins()
        self.module_cli = self.cli.jssdk

    def test_mock_self_func_get_jssdk_ticket(self):
        origin_func = self.module_cli.get_jssdk_ticket
        self.module_cli.get_jssdk_ticket = mock

        with pytest.raises(pylark.PyLarkError) as e:
            self.module_cli.get_jssdk_ticket(pylark.GetJssdkTicketReq())

        assert "msg=mock-failed" in f"{e}"
        self.module_cli.get_jssdk_ticket = origin_func


# mock raw request
class TestJssdkSampleMockRawRequestFailed(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        super(TestJssdkSampleMockRawRequestFailed, self).__init__(*args, **kwargs)
        self.cli = app_all_permission.ins()
        self.module_cli = self.cli.jssdk
        self.cli.raw_request = mock_raw_request

    def test_mock_raw_request_get_jssdk_ticket(self):
        with pytest.raises(pylark.PyLarkError) as e:
            self.module_cli.get_jssdk_ticket(pylark.GetJssdkTicketReq())

        assert e.type is pylark.PyLarkError
        assert e.value.code > 0
        assert "mock-raw-request-failed" in e.value.msg


# real request
class TestJssdkSampleRealRequestFailed(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        super(TestJssdkSampleRealRequestFailed, self).__init__(*args, **kwargs)
        self.cli = app_no_permission.ins()
        self.module_cli = self.cli.jssdk

    def test_real_request_get_jssdk_ticket(self):
        with pytest.raises(pylark.PyLarkError) as e:
            self.module_cli.get_jssdk_ticket(pylark.GetJssdkTicketReq())

        assert e.type is pylark.PyLarkError
        assert e.value.code > 0

# Code generated by lark_sdk_gen. DO NOT EDIT.

import unittest
import pylark
import pytest
from tests.test_conf import app_all_permission, app_no_permission
from tests.test_helper import mock_get_tenant_access_token_failed


def mock(*args, **kwargs):
    raise pylark.PyLarkError(scope="scope", func="func", code=1, msg="mock-failed")


def mock_raw_request(*args, **kwargs):
    raise pylark.PyLarkError(
        scope="scope", func="func", code=1, msg="mock-raw-request-failed"
    )


# mock get token
class TestJssdkSampleMockGetTokenFailed(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        super(TestJssdkSampleMockGetTokenFailed, self).__init__(*args, **kwargs)
        self.cli = app_all_permission.ins()
        self.cli.auth.get_tenant_access_token = mock_get_tenant_access_token_failed
        self.cli.auth.get_app_access_token = mock_get_tenant_access_token_failed
        self.module_cli = self.cli.jssdk

    def test_mock_get_token_get_jssdk_ticket(self):
        with pytest.raises(pylark.PyLarkError) as e:
            self.module_cli.get_jssdk_ticket(pylark.GetJssdkTicketReq())

        assert "msg=failed" in f"{e}"


# mock mock self func
class TestJssdkSampleMockSelfFuncFailed(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        super(TestJssdkSampleMockSelfFuncFailed, self).__init__(*args, **kwargs)
        self.cli = app_all_permission.ins()
        self.module_cli = self.cli.jssdk

    def test_mock_self_func_get_jssdk_ticket(self):
        origin_func = self.module_cli.get_jssdk_ticket
        self.module_cli.get_jssdk_ticket = mock

        with pytest.raises(pylark.PyLarkError) as e:
            self.module_cli.get_jssdk_ticket(pylark.GetJssdkTicketReq())

        assert "msg=mock-failed" in f"{e}"
        self.module_cli.get_jssdk_ticket = origin_func


# mock raw request
class TestJssdkSampleMockRawRequestFailed(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        super(TestJssdkSampleMockRawRequestFailed, self).__init__(*args, **kwargs)
        self.cli = app_all_permission.ins()
        self.module_cli = self.cli.jssdk
        self.cli.raw_request = mock_raw_request

    def test_mock_raw_request_get_jssdk_ticket(self):
        with pytest.raises(pylark.PyLarkError) as e:
            self.module_cli.get_jssdk_ticket(pylark.GetJssdkTicketReq())

        assert e.type is pylark.PyLarkError
        assert e.value.code > 0
        assert "mock-raw-request-failed" in e.value.msg


# real request
class TestJssdkSampleRealRequestFailed(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        super(TestJssdkSampleRealRequestFailed, self).__init__(*args, **kwargs)
        self.cli = app_no_permission.ins()
        self.module_cli = self.cli.jssdk

    def test_real_request_get_jssdk_ticket(self):
        with pytest.raises(pylark.PyLarkError) as e:
            self.module_cli.get_jssdk_ticket(pylark.GetJssdkTicketReq())

        assert e.type is pylark.PyLarkError
        assert e.value.code > 0

# Code generated by lark_sdk_gen. DO NOT EDIT. # mock get token # mock mock self func # mock raw request # real request