Skip to content

Commit c33e403

Browse files
authored
Merge branch 'master' into json-serialization-msue-67
2 parents 89f535a + 03e404e commit c33e403

File tree

6 files changed

+70
-7
lines changed

6 files changed

+70
-7
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
5.1.0 2022-06-22
2+
- Added return_route_info query parameter
3+
4+
5.0.2 2022-01-24
5+
- Fix usage of urllib for Python 2.7
6+
17
5.0.1 2019-03-07
28
- Update metadata in setup.py
39

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Sift Python Bindings [![Build Status](https://travis-ci.org/SiftScience/sift-python.svg?branch=master)](https://travis-ci.org/SiftScience/sift-python)
1+
# Sift Python Bindings
22

33
Bindings for Sift's APIs -- including the
44
[Events](https://sift.com/resources/references/events-api.html),

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
packages=['sift'],
3434
install_requires=[
3535
"requests >= 0.14.1",
36+
"six >= 1.16.0",
3637
],
3738
extras_require={
3839
'test': [

sift/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def track(
8585
return_score=False,
8686
return_action=False,
8787
return_workflow_status=False,
88+
return_route_info=False,
8889
force_workflow_run=False,
8990
abuse_types=None,
9091
timeout=None,
@@ -112,6 +113,9 @@ def track(
112113
include the status of any workflow run as a result of
113114
the tracked event.
114115
116+
return_route_info: Whether to get the route information from the Workflow Decision.
117+
This parameter must be used with the return_workflow_status query parameter.
118+
115119
force_workflow_run: TODO:(rlong) Add after Rishabh adds documentation.
116120
117121
abuse_types(optional): List of abuse types, specifying for which abuse types a score
@@ -158,6 +162,9 @@ def track(
158162
if return_workflow_status:
159163
params['return_workflow_status'] = 'true'
160164

165+
if return_route_info:
166+
params['return_route_info'] = 'true'
167+
161168
if force_workflow_run:
162169
params['force_workflow_run'] = 'true'
163170

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.1'
1+
VERSION = '5.1.0'
22
API_VERSION = '205'

tests/test_client.py

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import datetime
2-
from decimal import Decimal
3-
import warnings
42
import json
5-
import mock
6-
import sift
7-
import unittest
83
import sys
4+
import unittest
5+
import warnings
6+
from decimal import Decimal
7+
8+
import mock
99
import requests.exceptions
10+
11+
import sift
12+
1013
if sys.version_info[0] < 3:
1114
import six.moves.urllib as urllib
1215
else:
@@ -74,6 +77,23 @@ def score_response_json():
7477
}"""
7578

7679

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

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

0 commit comments

Comments
 (0)