@@ -19,11 +19,12 @@ def __init__(self, url):
19
19
20
20
21
21
class MockResponse (object ):
22
- def __init__ (self , json_text , status_code , request = None ):
22
+ def __init__ (self , json_text , status_code , request = None , url = None ):
23
23
self .text = json_text
24
24
self .status_code = status_code
25
25
self .cookies = cookies
26
26
self .request = request
27
+ self .url = url
27
28
28
29
def json (self , ** kwargs ):
29
30
return json .loads (self .text , ** kwargs )
@@ -47,8 +48,11 @@ def testFailure(self):
47
48
def testError (self ):
48
49
self .failUnlessRaises (ArgusException , lambda : check_success (MockResponse ("" , 500 ), decCls = JsonDecoder ))
49
50
51
+ def testUnauthorized (self ):
52
+ self .failUnlessRaises (ArgusAuthException , lambda : check_success (MockResponse ("" , 401 ), decCls = JsonDecoder ))
53
+
50
54
def testUnexpectedEndpoint (self ):
51
- self .failUnlessRaises (Exception , lambda : check_success (MockResponse ("HTTP 404 Not Found" , 404 ), decCls = JsonDecoder ))
55
+ self .failUnlessRaises (ArgusObjectNotFoundException , lambda : check_success (MockResponse ("HTTP 404 Not Found" , 404 ), decCls = JsonDecoder ))
52
56
53
57
54
58
class TestServiceBase (unittest .TestCase ):
@@ -92,7 +96,7 @@ def testAuthImplicit(self):
92
96
93
97
@mock .patch ('requests.Session.post' , return_value = MockResponse ("""{ "status": 401, "message": "Unauthorized" }""" , 401 , request = MockRequest ("v2/auth/login" )))
94
98
def testUnauthorized (self , mockPost ):
95
- """A stright -forward login failure with invalid username/password"""
99
+ """A straight -forward login failure with invalid username/password"""
96
100
self .failUnlessRaises (ArgusAuthException , lambda : self .argus .login ())
97
101
98
102
def testAuthWithDirectRefreshToken (self ):
@@ -423,18 +427,18 @@ def testGetUserAlert(self, mockGet):
423
427
res = self .argus .alerts .get_user_alert (testId , testId )
424
428
self .assertTrue (isinstance (res , Alert ))
425
429
self .assertEquals (res .to_dict (), alert_D )
426
- self .assertIn ((os .path .join (endpoint , "alerts" ),), tuple (mockGet .call_args ))
430
+ self .assertIn ((os .path .join (endpoint , "alerts/meta " ),), tuple (mockGet .call_args ))
427
431
428
432
@mock .patch ('requests.Session.get' , return_value = MockResponse (json .dumps ([]), 200 ))
429
433
def testGetUserAlertNoMatch (self , mockGet ):
430
434
res = self .argus .alerts .get_user_alert (testId , testId )
431
435
self .assertEquals (res , None )
432
- self .assertIn ((os .path .join (endpoint , "alerts" ),), tuple (mockGet .call_args ))
436
+ self .assertIn ((os .path .join (endpoint , "alerts/meta " ),), tuple (mockGet .call_args ))
433
437
434
438
@mock .patch ('requests.Session.get' , return_value = MockResponse (json .dumps ([alert_D , alert_D ]), 200 ))
435
439
def testGetUserAlertUnexpectedMultiple (self , mockGet ):
436
440
self .failUnlessRaises (AssertionError , lambda : self .argus .alerts .get_user_alert (testId , testId ))
437
- self .assertIn ((os .path .join (endpoint , "alerts" ),), tuple (mockGet .call_args ))
441
+ self .assertIn ((os .path .join (endpoint , "alerts/meta " ),), tuple (mockGet .call_args ))
438
442
439
443
440
444
class TestAlertTrigger (TestServiceBase ):
0 commit comments