Skip to content

Commit 03df159

Browse files
committed
Added function test files for request errors and unicode
Details: * Added two new function test files for common tests: - test_common_request_errors.yaml - Test that requests raises exceptions - test_common_unicode.yaml - Unicode testcases * Removed the requests exceptions testcase from test_user.yaml because it is now covered in the new test file. Signed-off-by: Andreas Maier <maiera@de.ibm.com>
1 parent d9af6b6 commit 03df159

File tree

3 files changed

+225
-24
lines changed

3 files changed

+225
-24
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Function tests for request errors
2+
3+
- name: connection_error
4+
description: Test raising ConnectionError
5+
zhmcclient_call:
6+
target:
7+
manager_attribute: consoles
8+
uri: /api/console
9+
name: Console
10+
method: get_property
11+
parameters:
12+
name: version
13+
zhmcclient_result:
14+
exception:
15+
class: ConnectionError
16+
message_pattern: ConnectionError
17+
hmc_interactions:
18+
- http_request:
19+
method: GET
20+
uri: /api/console
21+
http_response:
22+
callback: raise_requests_connection_error
23+
24+
- name: read_timeout
25+
description: Test raising ReadTimeout
26+
zhmcclient_call:
27+
target:
28+
manager_attribute: consoles
29+
uri: /api/console
30+
name: Console
31+
method: get_property
32+
parameters:
33+
name: version
34+
zhmcclient_result:
35+
exception:
36+
class: ReadTimeout
37+
message_pattern: ReadTimeout
38+
hmc_interactions:
39+
- http_request:
40+
method: GET
41+
uri: /api/console
42+
http_response:
43+
callback: raise_requests_read_timeout
44+
45+
- name: retry_error
46+
description: Test raising RetryError
47+
zhmcclient_call:
48+
target:
49+
manager_attribute: consoles
50+
uri: /api/console
51+
name: Console
52+
method: get_property
53+
parameters:
54+
name: version
55+
zhmcclient_result:
56+
exception:
57+
class: RetriesExceeded
58+
message_pattern: RetryError
59+
hmc_interactions:
60+
- http_request:
61+
method: GET
62+
uri: /api/console
63+
http_response:
64+
callback: raise_requests_retry_error
65+
66+
- name: http_error
67+
description: Test raising HTTPError
68+
zhmcclient_call:
69+
target:
70+
manager_attribute: consoles
71+
uri: /api/console
72+
name: Console
73+
method: get_property
74+
parameters:
75+
name: version
76+
zhmcclient_result:
77+
exception:
78+
class: ConnectionError
79+
message_pattern: HTTPError
80+
hmc_interactions:
81+
- http_request:
82+
method: GET
83+
uri: /api/console
84+
http_response:
85+
callback: raise_requests_http_error
86+
87+
- name: ssl_error
88+
description: Test raising SSLError
89+
zhmcclient_call:
90+
target:
91+
manager_attribute: consoles
92+
uri: /api/console
93+
name: Console
94+
method: get_property
95+
parameters:
96+
name: version
97+
zhmcclient_result:
98+
exception:
99+
class: ConnectionError
100+
message_pattern: SSLError
101+
hmc_interactions:
102+
- http_request:
103+
method: GET
104+
uri: /api/console
105+
http_response:
106+
callback: raise_requests_ssl_error
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Function tests for unicode support
2+
3+
# Note: This file contains UTF-8 character sequences and must be stored UTF-8
4+
# encoded. Make sure your editor supports and preserves the UTF-8 characters.
5+
6+
# Note: It is not easily possible to specify invalid Unicode characters in
7+
# an editable YAML file:
8+
# - Having invalid UTF-8 byte sequences directly in the file is not a good idea
9+
# because the files need to be editable and so the editor must support and
10+
# preserve the UTF-8 byte sequences in the file. Adding such a test would
11+
# be feasible when the test file gets generated, but that has not been done.
12+
# - Using escape sequences in YAML does not easily allow to construct invalid
13+
# Unicode characters:
14+
# - "\xC2" looks like an incomplete 2-byte UTF-8 byte sequence, but is really
15+
# interpreted as Unicode character U+00C2 and is fully supported.
16+
# - "\uC2" is rejected by PyYAML when loading the test file as an invalid way
17+
# to specify an escaped Unicode character. That causes a pytest collection
18+
# error because the test file cannot be loaded.
19+
# - "\uD800" is an incomplete (lone) surrogate sequence and is tolerated by
20+
# PyYAML and json, even though it is invalid according to the Unicode
21+
# standard. It would be rejected by ruamel.yaml. There is a testcase for
22+
# that in this test file.
23+
# - Specifying binary Bytes that are invalid UTF-8 sequences (using
24+
# !!binary) is valid in YAML and loading the test file succeeds, but it gets
25+
# rejected with an invalid type (binary vs. string) when validating the
26+
# test file against its JSON schema.
27+
28+
- name: valid_escaped_local_property_value
29+
description: Test valid escaped Unicode character in locally present property value
30+
zhmcclient_call:
31+
target:
32+
manager_attribute: consoles
33+
uri: /api/console
34+
name: "Ren\u00e9"
35+
method: get_property
36+
parameters:
37+
name: name
38+
zhmcclient_result:
39+
return: "Ren\u00E9" # U+00E9 = e accent degu
40+
41+
- name: valid_escaped_hmc_property_value
42+
description: Test valid escaped Unicode character in property value obtained from HMC
43+
zhmcclient_call:
44+
target:
45+
manager_attribute: consoles
46+
uri: /api/console
47+
name: "Console"
48+
method: get_property
49+
parameters:
50+
name: hmc_version
51+
zhmcclient_result:
52+
return: "\u00E9" # U+00E9 = e accent degu
53+
hmc_interactions:
54+
- http_request:
55+
method: GET
56+
uri: /api/console
57+
http_response:
58+
status: 200
59+
body:
60+
parent: null
61+
class: "console"
62+
object-uri: "/api/console"
63+
object-id: "console"
64+
name: "Console"
65+
hmc_version: "\u00E9" # U+00E9 = e accent degu
66+
67+
- name: valid_utf8_hmc_property_value
68+
description: Test valid UTF-8 Unicode character in property value obtained from HMC
69+
zhmcclient_call:
70+
target:
71+
manager_attribute: consoles
72+
uri: /api/console
73+
name: "Console"
74+
method: get_property
75+
parameters:
76+
name: hmc_version
77+
zhmcclient_result:
78+
return: "é" # UTF-8 character directly: U+00E9 = e accent degu
79+
hmc_interactions:
80+
- http_request:
81+
method: GET
82+
uri: /api/console
83+
http_response:
84+
status: 200
85+
body:
86+
parent: null
87+
class: "console"
88+
object-uri: "/api/console"
89+
object-id: "console"
90+
name: "Console"
91+
hmc_version: "é" # UTF-8 character directly: U+00E9 = e accent degu
92+
93+
- name: incomplete_surrogate_hmc_property_value
94+
description: Test incomplete Unicode surrogate sequence in property value obtained from HMC
95+
# Note: This testcase depends on using PyYAML, which tolerates incomplete
96+
# surrogate sequences (ruamel.yaml does not).
97+
zhmcclient_call:
98+
target:
99+
manager_attribute: consoles
100+
uri: /api/console
101+
name: "Console"
102+
method: get_property
103+
parameters:
104+
name: hmc_version
105+
zhmcclient_result:
106+
return: "\uD800" # incomplete (lone) Unicode surrogate sequence
107+
hmc_interactions:
108+
- http_request:
109+
method: GET
110+
uri: /api/console
111+
http_response:
112+
status: 200
113+
body:
114+
parent: null
115+
class: "console"
116+
object-uri: "/api/console"
117+
object-id: "console"
118+
name: "Console"
119+
hmc_version: "\uD800" # incomplete (lone) Unicode surrogate sequence

tests/function/test_user.yaml

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -92,27 +92,3 @@
9292
object-id: "oid-user1"
9393
name: "user1"
9494
hmc_version: "2.17"
95-
96-
- name: test_user_get_property_connection_error
97-
description: Test User.get_property(name) with connection error
98-
zhmcclient_call:
99-
target:
100-
manager_attribute: users
101-
uri: /api/users/oid-user1
102-
name: user1
103-
parent:
104-
manager_attribute: consoles
105-
uri: /api/console
106-
name: Console
107-
method: get_property
108-
parameters:
109-
name: user1
110-
zhmcclient_result:
111-
exception:
112-
class: ConnectionError
113-
hmc_interactions:
114-
- http_request:
115-
method: GET
116-
uri: /api/users/oid-user1
117-
http_response:
118-
callback: raise_requests_connection_error

0 commit comments

Comments
 (0)