Skip to content

Commit 03e404e

Browse files
Merge pull request #86 from SiftScience/API-6560
API-6560: Added return_route_info param
2 parents 9cbbd11 + 308a340 commit 03e404e

File tree

4 files changed

+64
-5
lines changed

4 files changed

+64
-5
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
5.1.0 2022-06-22
2+
- Added return_route_info query parameter
3+
14
5.0.2 2022-01-24
25
- Fix usage of urllib for Python 2.7
36

sift/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def track(
7979
return_score=False,
8080
return_action=False,
8181
return_workflow_status=False,
82+
return_route_info=False,
8283
force_workflow_run=False,
8384
abuse_types=None,
8485
timeout=None,
@@ -106,6 +107,9 @@ def track(
106107
include the status of any workflow run as a result of
107108
the tracked event.
108109
110+
return_route_info: Whether to get the route information from the Workflow Decision.
111+
This parameter must be used with the return_workflow_status query parameter.
112+
109113
force_workflow_run: TODO:(rlong) Add after Rishabh adds documentation.
110114
111115
abuse_types(optional): List of abuse types, specifying for which abuse types a score
@@ -152,6 +156,9 @@ def track(
152156
if return_workflow_status:
153157
params['return_workflow_status'] = 'true'
154158

159+
if return_route_info:
160+
params['return_route_info'] = 'true'
161+
155162
if force_workflow_run:
156163
params['force_workflow_run'] = 'true'
157164

sift/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
VERSION = '5.0.2'
1+
VERSION = '5.1.0'
22
API_VERSION = '205'

tests/test_client.py

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import datetime
2-
import warnings
32
import json
4-
import mock
5-
import sift
6-
import unittest
73
import sys
4+
import unittest
5+
import warnings
6+
7+
import mock
88
import requests.exceptions
9+
10+
import sift
11+
912
if sys.version_info[0] < 3:
1013
import six.moves.urllib as urllib
1114
else:
@@ -73,6 +76,23 @@ def score_response_json():
7376
}"""
7477

7578

79+
def workflow_statuses_json():
80+
return """{
81+
"route" : {
82+
"name" : "my route"
83+
},
84+
"history": [
85+
{
86+
"app": "decision",
87+
"name": "Order Looks OK",
88+
"state": "running",
89+
"config": {
90+
"decision_id": "order_looks_ok_payment_abuse"
91+
}
92+
}
93+
]
94+
}"""
95+
7696
# A sample response from the /{version}/users/{userId}/score API.
7797
USER_SCORE_RESPONSE_JSON = """{
7898
"status": 0,
@@ -435,6 +455,35 @@ def test_sync_score_ok(self):
435455
assert(response.body['score_response']['scores']['content_abuse']['score'] == 0.14)
436456
assert(response.body['score_response']['scores']['payment_abuse']['score'] == 0.97)
437457

458+
def test_sync_workflow_ok(self):
459+
event = '$transaction'
460+
mock_response = mock.Mock()
461+
mock_response.content = ('{"status": 0, "error_message": "OK", "workflow_statuses": %s}'
462+
% workflow_statuses_json())
463+
mock_response.json.return_value = json.loads(mock_response.content)
464+
mock_response.status_code = 200
465+
mock_response.headers = response_with_data_header()
466+
with mock.patch.object(self.sift_client.session, 'post') as mock_post:
467+
mock_post.return_value = mock_response
468+
response = self.sift_client.track(
469+
event,
470+
valid_transaction_properties(),
471+
return_workflow_status=True,
472+
return_route_info=True,
473+
abuse_types=['payment_abuse', 'content_abuse', 'legacy'])
474+
mock_post.assert_called_with(
475+
'https://api.siftscience.com/v205/events',
476+
data=mock.ANY,
477+
headers=mock.ANY,
478+
timeout=mock.ANY,
479+
params={'return_workflow_status': 'true', 'return_route_info': 'true',
480+
'abuse_types': 'payment_abuse,content_abuse,legacy'})
481+
self.assertIsInstance(response, sift.client.Response)
482+
assert(response.is_ok())
483+
assert(response.api_status == 0)
484+
assert(response.api_error_message == "OK")
485+
assert(response.body['workflow_statuses']['route']['name'] == 'my route')
486+
438487
def test_get_decisions_fails(self):
439488
with self.assertRaises(ValueError):
440489
self.sift_client.get_decisions('usr')

0 commit comments

Comments
 (0)