@@ -346,6 +346,52 @@ def test_get_decisions(self):
346
346
assert (response .is_ok ())
347
347
assert (response .body ['data' ][0 ]['id' ] == 'block_user' )
348
348
349
+ def test_get_decisions_entity_session (self ):
350
+ mock_response = mock .Mock ()
351
+ get_decisions_response_json = \
352
+ '{' \
353
+ '"data": [' \
354
+ '{' \
355
+ '"id": "block_session",' \
356
+ '"name" : "Block session",' \
357
+ '"description": "session has problems",' \
358
+ '"entity_type": "session",' \
359
+ '"abuse_type": "legacy",' \
360
+ '"category": "block",' \
361
+ '"webhook_url": "http://web.hook",' \
362
+ '"created_at": "1468005577348",' \
363
+ '"created_by": "admin@biz.com",' \
364
+ '"updated_at": "1469229177756",' \
365
+ '"updated_by": "analyst@biz.com"' \
366
+ '}' \
367
+ '],' \
368
+ '"has_more": "true",' \
369
+ '"next_ref": "v3/accounts/accountId/decisions"' \
370
+ '}'
371
+
372
+ mock_response .content = get_decisions_response_json
373
+ mock_response .json .return_value = json .loads (mock_response .content )
374
+ mock_response .status_code = 200
375
+ mock_response .headers = response_with_data_header ()
376
+ with mock .patch ('requests.get' ) as mock_get :
377
+ mock_get .return_value = mock_response
378
+
379
+ response = self .sift_client .get_decisions (entity_type = "session" ,
380
+ limit = 10 ,
381
+ start_from = None ,
382
+ abuse_types = "account_takeover" ,
383
+ timeout = 3 )
384
+ mock_get .assert_called_with (
385
+ 'https://api3.siftscience.com/v3/accounts/ACCT/decisions' ,
386
+ headers = mock .ANY ,
387
+ auth = mock .ANY ,
388
+ params = {'entity_type' :'session' ,'limit' :10 ,'abuse_types' :'account_takeover' },
389
+ timeout = 3 )
390
+
391
+ assert (isinstance (response , sift .client .Response ))
392
+ assert (response .is_ok ())
393
+ assert (response .body ['data' ][0 ]['id' ] == 'block_session' )
394
+
349
395
def test_apply_decision_to_user_ok (self ):
350
396
user_id = '54321'
351
397
mock_response = mock .Mock ()
@@ -394,12 +440,18 @@ def test_validate_no_user_id_string_fails(self):
394
440
except Exception as e :
395
441
assert (isinstance (e , sift .client .ApiException ))
396
442
397
- def test_apply_decision_to_order (self ):
443
+ def test_apply_decision_to_order_fails_with_no_order_id (self ):
398
444
try :
399
445
self .sift_client .apply_order_decision ("user_id" , None , {})
400
446
except Exception as e :
401
447
assert (isinstance (e , sift .client .ApiException ))
402
448
449
+ def test_apply_decision_to_session_fails_with_no_session_id (self ):
450
+ try :
451
+ self .sift_client .apply_session_decision ("user_id" , None , {})
452
+ except Exception as e :
453
+ assert (isinstance (e , sift .client .ApiException ))
454
+
403
455
def test_validate_apply_decision_request_no_analyst_fails (self ):
404
456
apply_decision_request = {
405
457
'decision_id' : 'user_looks_ok_legacy' ,
@@ -522,6 +574,42 @@ def test_apply_decision_to_order_ok(self):
522
574
assert (response .http_status_code == 200 )
523
575
assert (response .body ['entity' ]['type' ] == 'order' )
524
576
577
+ def test_apply_decision_to_session_ok (self ):
578
+ user_id = '54321'
579
+ session_id = 'gigtleqddo84l8cm15qe4il'
580
+ mock_response = mock .Mock ()
581
+ apply_decision_request = {
582
+ 'decision_id' : 'session_looks_bad_ato' ,
583
+ 'source' : 'AUTOMATED_RULE' ,
584
+ 'time' : 1481569575
585
+ }
586
+
587
+ apply_decision_response_json = '{' \
588
+ '"entity": {' \
589
+ '"id": "54321",' \
590
+ '"type": "login"' \
591
+ '},' \
592
+ '"decision": {' \
593
+ '"id":"session_looks_bad_ato"' \
594
+ '},' \
595
+ '"time":"1481569575"}'
596
+
597
+ mock_response .content = apply_decision_response_json
598
+ mock_response .json .return_value = json .loads (mock_response .content )
599
+ mock_response .status_code = 200
600
+ mock_response .headers = response_with_data_header ()
601
+ with mock .patch ('requests.post' ) as mock_post :
602
+ mock_post .return_value = mock_response
603
+ response = self .sift_client .apply_session_decision (user_id , session_id , apply_decision_request )
604
+ data = json .dumps (apply_decision_request )
605
+ mock_post .assert_called_with (
606
+ 'https://api3.siftscience.com/v3/accounts/ACCT/users/%s/sessions/%s/decisions' % (user_id ,session_id ),
607
+ auth = mock .ANY , data = data , headers = mock .ANY , timeout = mock .ANY )
608
+ assert (isinstance (response , sift .client .Response ))
609
+ assert (response .is_ok ())
610
+ assert (response .http_status_code == 200 )
611
+ assert (response .body ['entity' ]['type' ] == 'login' )
612
+
525
613
def test_label_user_ok (self ):
526
614
user_id = '54321'
527
615
mock_response = mock .Mock ()
0 commit comments