forked from ucloud/ucloud-sdk-python2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_client.py
More file actions
76 lines (63 loc) · 2.33 KB
/
test_client.py
File metadata and controls
76 lines (63 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
import os
import pytest
import logging
from ucloud.client import Client
from ucloud.core import exc
from ucloud.testing.mock import MockedTransport
logger = logging.getLogger(__name__)
@pytest.fixture(scope="session", autouse=True)
def client():
return Client(
{
"region": "cn-bj2",
"public_key": "foo",
"private_key": "foo",
"timeout": 10,
"max_retries": 3,
}
)
@pytest.fixture(scope="function", autouse=True)
def transport():
return MockedTransport()
class TestClient(object):
def test_client_invoke(self, client, transport):
transport.mock_data(lambda _: {"RetCode": 0, "Action": "Foo"})
client.transport = transport
assert client.invoke("Foo") == {"RetCode": 0, "Action": "Foo"}
def test_client_invoke_code_error(self, client, transport):
transport.mock_data(lambda _: {"RetCode": 171, "Action": "Foo"})
client.transport = transport
with pytest.raises(exc.RetCodeException):
try:
client.invoke("Foo")
except exc.RetCodeException as e:
assert str(e)
expected = {"RetCode": 171, "Action": "Foo", "Message": ""}
assert e.json() == expected
raise e
def test_client_invoke_with_retryable_error(self, client, transport):
transport.mock_data(lambda _: {"RetCode": 10000, "Action": "Foo"})
client.transport = transport
with pytest.raises(exc.RetCodeException):
client.invoke("Foo")
def test_client_invoke_with_unexpected_error(self, client, transport):
def raise_error(_):
raise ValueError("temporary error")
transport.mock_data(raise_error)
client.transport = transport
with pytest.raises(ValueError):
client.invoke("Foo")
def test_client_try_import(self, client):
assert client.pathx()
assert client.stepflow()
assert client.uaccount()
assert client.udb()
assert client.udpn()
assert client.udisk()
assert client.uhost()
assert client.ulb()
assert client.umem()
assert client.unet()
assert client.uphost()
assert client.vpc()