예제 #1
0
def test_discovery_doc(mocker):
    mocker.patch("lumapps.api.utils._get_conn", return_value=_get_conn(":memory:"))

    class DummyResp:
        def __init__(self, text):
            self.text = text

        def json(self):
            return loads(self.text)

    with open("tests/test_data/lumapps_discovery.json") as fh:
        resp = DummyResp(fh.read())

    class DummySession:
        def get(*args, **kwargs):
            return resp

    c = BaseClient(token="foobar")
    mocker.patch(
        "lumapps.api.client.BaseClient.client",
        new_callable=PropertyMock,
        return_value=DummySession(),
    )
    doc1 = c.discovery_doc
    doc2 = c.discovery_doc
    assert doc1
    assert doc1 == doc2
예제 #2
0
def test_with_proxy_1():
    c = BaseClient(
        token="foobar",
        proxy_info={"scheme": "http", "host": "foo.bar.com", "port": 12345},
    )
    s = c.client
    assert len(s._proxies) == 2
예제 #3
0
def test_api_client_token_setter():
    token = "bvazbduioanpdo2"
    with BaseClient(token=token) as cli:
        assert cli.token == token
        assert cli._headers is not None
        assert token in cli.client.headers["authorization"]
        cli2 = cli
    assert cli2._client is None
예제 #4
0
def test_with_proxy_2():
    c = BaseClient(
        token="foobar",
        proxy_info={
            "scheme": "https",
            "host": "foo.bar",
            "port": 12345,
            "user": "******",
            "password": "******",
        },
    )
    s = c.client
    assert len(s._proxies) == 2
예제 #5
0
def cli_drive() -> BaseClient:
    with open("tests/test_data/drive_v3_discovery.json") as fh:
        doc = load(fh)
    get_discovery_cache().set(doc["baseUrl"], doc)
    c = BaseClient(
        token="foobar",
        api_info={
            "base_url": "https://www.googleapis.com",
            "name": "drive",
            "version": "v3",
            "scopes": ["https://www.googleapis.com/auth/drive"],
        },
    )
    return c
예제 #6
0
def test_api_client_no_auth():
    with BaseClient() as cli:
        with raises(BaseClientError):
            cli.client
예제 #7
0
def cli() -> BaseClient:
    c = BaseClient(token="foobar")
    with open("tests/test_data/lumapps_discovery.json") as fh:
        doc = load(fh)
    get_discovery_cache().set(doc["baseUrl"], doc)
    return c