forked from solidfire/solidfire-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api_server_error.py
More file actions
64 lines (49 loc) · 1.96 KB
/
test_api_server_error.py
File metadata and controls
64 lines (49 loc) · 1.96 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
#!/usr/bin/env python
import json
from unittest.case import TestCase
from hamcrest import assert_that, equal_to
from solidfire.common import ApiServerError
class TestApiServerError(TestCase):
def test_should_provide_defaults_with_empty_string(self):
api_error = ApiServerError('aMethod', '')
assert_that(api_error.error_name, equal_to('Unknown'))
assert_that(api_error.error_code, equal_to(500))
assert_that(api_error.message, equal_to(None))
def test_should_provide_defaults(self):
api_error = ApiServerError('aMethod', '{}')
assert_that(api_error.error_name, equal_to('Unknown'))
assert_that(api_error.error_code, equal_to(500))
assert_that(api_error.message, equal_to(None))
def test_should_convert_code_to_int(self):
api_error = ApiServerError('aMethod', '{"code": "404"}')
assert_that(api_error.error_code,
equal_to(404) and not (equal_to("404")))
def test_should_map_provided_json(self):
api_error = ApiServerError(
'aMethod',
'{ \
"error" : { \
"name": "error_name", \
"code": 505, \
"message": "aMessage" \
} \
}',
)
assert_that(api_error.error_name, equal_to('error_name'))
assert_that(api_error.error_code, equal_to(505))
assert_that(api_error.message, equal_to('aMessage'))
def test_repr_evals_no_json(self):
api_error = ApiServerError('aMethod', json.loads('{}', ))
assert_that(eval(repr(api_error)), api_error)
def test_repr_evals(self):
api_error = ApiServerError(
'aMethod',
'{ \
"error" : { \
"name": "error_name", \
"code": 505, \
"message": "aMessage" \
} \
}',
)
assert_that(eval(repr(api_error)), api_error)