37
37
38
38
class PhabricatorTest (unittest .TestCase ):
39
39
def setUp (self ):
40
- self .api = phabricator .Phabricator (username = 'test' , certificate = 'test' , host = 'http://localhost' )
40
+ self .api = phabricator .Phabricator (
41
+ username = 'test' ,
42
+ certificate = 'test' ,
43
+ host = 'http://localhost'
44
+ )
41
45
self .api .certificate = CERTIFICATE
42
46
43
47
def test_generate_hash (self ):
@@ -49,8 +53,14 @@ def test_generate_hash(self):
49
53
def test_connect (self , mock_connection ):
50
54
mock_obj = mock_connection .return_value = mock .Mock ()
51
55
mock_obj .getresponse .return_value = StringIO (RESPONSES ['conduit.connect' ])
56
+ mock_obj .getresponse .return_value .status = 200
57
+
58
+ api = phabricator .Phabricator (
59
+ username = 'test' ,
60
+ certificate = 'test' ,
61
+ host = 'http://localhost'
62
+ )
52
63
53
- api = phabricator .Phabricator (username = 'test' , certificate = 'test' , host = 'http://localhost' )
54
64
api .connect ()
55
65
keys = api ._conduit .keys ()
56
66
self .assertIn ('sessionKey' , keys )
@@ -60,16 +70,39 @@ def test_connect(self, mock_connection):
60
70
def test_user_whoami (self , mock_connection ):
61
71
mock_obj = mock_connection .return_value = mock .Mock ()
62
72
mock_obj .getresponse .return_value = StringIO (RESPONSES ['user.whoami' ])
73
+ mock_obj .getresponse .return_value .status = 200
63
74
64
- api = phabricator .Phabricator (username = 'test' , certificate = 'test' , host = 'http://localhost' )
75
+ api = phabricator .Phabricator (
76
+ username = 'test' ,
77
+ certificate = 'test' ,
78
+ host = 'http://localhost'
79
+ )
65
80
api ._conduit = True
66
81
67
82
self .assertEqual (api .user .whoami ()['userName' ], 'testaccount' )
68
83
84
+ @mock .patch ('phabricator.httplib.HTTPConnection' )
85
+ def test_bad_status (self , mock_connection ):
86
+ mock_obj = mock_connection .return_value = mock .Mock ()
87
+ mock_obj .getresponse .return_value = mock .Mock ()
88
+ mock_obj .getresponse .return_value .status = 400
89
+
90
+ api = phabricator .Phabricator (
91
+ username = 'test' ,
92
+ certificate = 'test' ,
93
+ host = 'http://localhost'
94
+ )
95
+ api ._conduit = True
96
+
97
+ with self .assertRaises (phabricator .httplib .HTTPException ):
98
+ api .user .whoami ()
99
+
100
+
69
101
@mock .patch ('phabricator.httplib.HTTPConnection' )
70
102
def test_maniphest_find (self , mock_connection ):
71
103
mock_obj = mock_connection .return_value = mock .Mock ()
72
104
mock_obj .getresponse .return_value = StringIO (RESPONSES ['maniphest.find' ])
105
+ mock_obj .getresponse .return_value .status = 200
73
106
74
107
api = phabricator .Phabricator (username = 'test' , certificate = 'test' , host = 'http://localhost' )
75
108
api ._conduit = True
0 commit comments