Skip to content

Commit 8c7ccd5

Browse files
authored
Added function test files for request errors and unicode (#2071)
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 Signed-off-by: Andreas Maier <maiera@de.ibm.com>
1 parent 3afaca8 commit 8c7ccd5

2 files changed

Lines changed: 256 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)