Skip to content

API-6560: Added return_route_info param #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
5.1.0 2022-06-22
- Added return_route_info query parameter

5.0.2 2022-01-24
- Fix usage of urllib for Python 2.7

Expand Down
7 changes: 7 additions & 0 deletions sift/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def track(
return_score=False,
return_action=False,
return_workflow_status=False,
return_route_info=False,
force_workflow_run=False,
abuse_types=None,
timeout=None,
Expand Down Expand Up @@ -106,6 +107,9 @@ def track(
include the status of any workflow run as a result of
the tracked event.

return_route_info: Whether to get the route information from the Workflow Decision.
This parameter must be used with the return_workflow_status query parameter.

force_workflow_run: TODO:(rlong) Add after Rishabh adds documentation.

abuse_types(optional): List of abuse types, specifying for which abuse types a score
Expand Down Expand Up @@ -152,6 +156,9 @@ def track(
if return_workflow_status:
params['return_workflow_status'] = 'true'

if return_route_info:
params['return_route_info'] = 'true'

if force_workflow_run:
params['force_workflow_run'] = 'true'

Expand Down
2 changes: 1 addition & 1 deletion sift/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VERSION = '5.0.2'
VERSION = '5.1.0'
API_VERSION = '205'
57 changes: 53 additions & 4 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import datetime
import warnings
import json
import mock
import sift
import unittest
import sys
import unittest
import warnings

import mock
import requests.exceptions

import sift

if sys.version_info[0] < 3:
import six.moves.urllib as urllib
else:
Expand Down Expand Up @@ -73,6 +76,23 @@ def score_response_json():
}"""


def workflow_statuses_json():
return """{
"route" : {
"name" : "my route"
},
"history": [
{
"app": "decision",
"name": "Order Looks OK",
"state": "running",
"config": {
"decision_id": "order_looks_ok_payment_abuse"
}
}
]
}"""

# A sample response from the /{version}/users/{userId}/score API.
USER_SCORE_RESPONSE_JSON = """{
"status": 0,
Expand Down Expand Up @@ -435,6 +455,35 @@ def test_sync_score_ok(self):
assert(response.body['score_response']['scores']['content_abuse']['score'] == 0.14)
assert(response.body['score_response']['scores']['payment_abuse']['score'] == 0.97)

def test_sync_workflow_ok(self):
event = '$transaction'
mock_response = mock.Mock()
mock_response.content = ('{"status": 0, "error_message": "OK", "workflow_statuses": %s}'
% workflow_statuses_json())
mock_response.json.return_value = json.loads(mock_response.content)
mock_response.status_code = 200
mock_response.headers = response_with_data_header()
with mock.patch.object(self.sift_client.session, 'post') as mock_post:
mock_post.return_value = mock_response
response = self.sift_client.track(
event,
valid_transaction_properties(),
return_workflow_status=True,
return_route_info=True,
abuse_types=['payment_abuse', 'content_abuse', 'legacy'])
mock_post.assert_called_with(
'https://api.siftscience.com/v205/events',
data=mock.ANY,
headers=mock.ANY,
timeout=mock.ANY,
params={'return_workflow_status': 'true', 'return_route_info': 'true',
'abuse_types': 'payment_abuse,content_abuse,legacy'})
self.assertIsInstance(response, sift.client.Response)
assert(response.is_ok())
assert(response.api_status == 0)
assert(response.api_error_message == "OK")
assert(response.body['workflow_statuses']['route']['name'] == 'my route')

def test_get_decisions_fails(self):
with self.assertRaises(ValueError):
self.sift_client.get_decisions('usr')
Expand Down