1
1
import unittest
2
2
3
+ import requests
4
+
3
5
from docker .errors import (APIError , DockerException ,
4
6
create_unexpected_kwargs_error )
5
7
@@ -11,6 +13,69 @@ def test_api_error_is_caught_by_dockerexception(self):
11
13
except DockerException :
12
14
pass
13
15
16
+ def test_status_code_200 (self ):
17
+ """The status_code property is present with 200 response."""
18
+ resp = requests .Response ()
19
+ resp .status_code = 200
20
+ err = APIError ('' , response = resp )
21
+ assert err .status_code == 200
22
+
23
+ def test_status_code_400 (self ):
24
+ """The status_code property is present with 400 response."""
25
+ resp = requests .Response ()
26
+ resp .status_code = 400
27
+ err = APIError ('' , response = resp )
28
+ assert err .status_code == 400
29
+
30
+ def test_status_code_500 (self ):
31
+ """The status_code property is present with 500 response."""
32
+ resp = requests .Response ()
33
+ resp .status_code = 500
34
+ err = APIError ('' , response = resp )
35
+ assert err .status_code == 500
36
+
37
+ def test_is_server_error_200 (self ):
38
+ """Report not server error on 200 response."""
39
+ resp = requests .Response ()
40
+ resp .status_code = 200
41
+ err = APIError ('' , response = resp )
42
+ assert err .is_server_error () is False
43
+
44
+ def test_is_server_error_300 (self ):
45
+ """Report not server error on 300 response."""
46
+ resp = requests .Response ()
47
+ resp .status_code = 300
48
+ err = APIError ('' , response = resp )
49
+ assert err .is_server_error () is False
50
+
51
+ def test_is_server_error_400 (self ):
52
+ """Report not server error on 400 response."""
53
+ resp = requests .Response ()
54
+ resp .status_code = 400
55
+ err = APIError ('' , response = resp )
56
+ assert err .is_server_error () is False
57
+
58
+ def test_is_server_error_500 (self ):
59
+ """Report server error on 500 response."""
60
+ resp = requests .Response ()
61
+ resp .status_code = 500
62
+ err = APIError ('' , response = resp )
63
+ assert err .is_server_error () is True
64
+
65
+ def test_is_client_error_500 (self ):
66
+ """Report not client error on 500 response."""
67
+ resp = requests .Response ()
68
+ resp .status_code = 500
69
+ err = APIError ('' , response = resp )
70
+ assert err .is_client_error () is False
71
+
72
+ def test_is_client_error_400 (self ):
73
+ """Report client error on 400 response."""
74
+ resp = requests .Response ()
75
+ resp .status_code = 400
76
+ err = APIError ('' , response = resp )
77
+ assert err .is_client_error () is True
78
+
14
79
15
80
class CreateUnexpectedKwargsErrorTest (unittest .TestCase ):
16
81
def test_create_unexpected_kwargs_error_single (self ):
0 commit comments