コード例 #1
0
ファイル: test_client.py プロジェクト: datduyng/ccapi
def test_client():
    # Check proxy definitions.
    with pytest.raises(TypeError):
        ccapi.Client(proxies="foobar")

    with pytest.raises((ConnectionError, ResponseError)):
        ccapi.Client(base_url=_INVALID_URL)

    ccapi.Client(base_url=_INVALID_URL, test=False)

    assert not _BASE_CLIENT.authenticated
コード例 #2
0
def main():
    client = ccapi.Client()
    client.auth(email="*****@*****.**", password="******")

    me = client.me()

    models = client.get("model", filters={"user": me}, size=sys.maxsize)
    for model in models:
        model.delete()
コード例 #3
0
ファイル: test_client.py プロジェクト: datduyng/ccapi
def test_client_repr():
    repr_ = "<Client url='{}'>"

    def _test(client):
        assert repr(client) == repr_.format(client.base_url)

    _test(_BASE_CLIENT)

    client = ccapi.Client(_INVALID_URL, test=False)
    _test(client)
コード例 #4
0
ファイル: test_client.py プロジェクト: datduyng/ccapi
def test_auth():
    with pytest.raises(ValueError):
        _BASE_CLIENT.auth()
    with pytest.raises(ValueError):
        _BASE_CLIENT.auth(email="*****@*****.**")

    assert not _BASE_CLIENT.authenticated
    _BASE_CLIENT.auth(email=_TEST_EMAIL, password=_TEST_PASSWORD)
    assert _BASE_CLIENT.authenticated

    client = ccapi.Client()
    assert not client.authenticated
    client.auth(token=_BASE_CLIENT._auth_token)
    assert client.authenticated

    _BASE_CLIENT.logout()
    client.logout()

    with pytest.raises(AuthenticationError):
        _BASE_CLIENT.auth(email="thisisaninvalidemail.org", password="******")
コード例 #5
0
ファイル: conftest.py プロジェクト: datduyng/ccapi
def client():
    client = ccapi.Client()
    client.auth(email="*****@*****.**", password="******")
    return client
コード例 #6
0
ファイル: test_client.py プロジェクト: datduyng/ccapi
def test__request():
    proxies = get_random_proxies()
    client = ccapi.Client(proxies=proxies)
    response = client._request("GET", "api/ping")
コード例 #7
0
ファイル: test_client.py プロジェクト: datduyng/ccapi
# imports - module imports
import ccapi
from ccapi.exception import (TypeError, ConnectionError, AuthenticationError,
                             ResponseError)
from testutils import get_random_proxies

# imports - standard imports
import pytest

_INVALID_URL = "http://thisisaninvalidurl.com"
_TEST_EMAIL = "*****@*****.**"
_TEST_PASSWORD = "******"
_AUTH_TOKEN = None

_BASE_CLIENT = ccapi.Client()


def test_client():
    # Check proxy definitions.
    with pytest.raises(TypeError):
        ccapi.Client(proxies="foobar")

    with pytest.raises((ConnectionError, ResponseError)):
        ccapi.Client(base_url=_INVALID_URL)

    ccapi.Client(base_url=_INVALID_URL, test=False)

    assert not _BASE_CLIENT.authenticated


def test_client_repr():