Skip to content
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

[MSUE-151] [MSUE-191] - Integration testing files #99

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
5.5.0 2023-10-03
- Score percentiles for Score API

5.4.0 2023-07-26
- Support for Verification API

Expand Down
19 changes: 15 additions & 4 deletions sift/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ def track(
params['force_workflow_run'] = 'true'

if include_score_percentiles:
field_types = ['SCORE_PERCENTILES']
params['fields'] = ','.join(field_types)
params['fields'] = 'SCORE_PERCENTILES'
try:
response = self.session.post(
path,
Expand All @@ -193,7 +192,7 @@ def track(
except requests.exceptions.RequestException as e:
raise ApiException(str(e), path)

def score(self, user_id, timeout=None, abuse_types=None, version=None):
def score(self, user_id, timeout=None, abuse_types=None, version=None, include_score_percentiles=False):
"""Retrieves a user's fraud score from the Sift Science API.
This call is blocking. Check out https://siftscience.com/resources/references/score_api.html
for more information on our Score response structure.
Expand All @@ -210,6 +209,9 @@ def score(self, user_id, timeout=None, abuse_types=None, version=None):

version(optional): Use a different version of the Sift Science API for this call.

include_score_percentiles(optional) : Whether to add new parameter in the query parameter.
if include_score_percentiles is true then add a new parameter called fields in the query parameter

Returns:
A sift.client.Response object if the score call succeeded, or raises
an ApiException.
Expand All @@ -227,6 +229,9 @@ def score(self, user_id, timeout=None, abuse_types=None, version=None):
if abuse_types:
params['abuse_types'] = ','.join(abuse_types)

if include_score_percentiles:
params['fields'] = 'SCORE_PERCENTILES'

url = self._score_url(user_id, version)

try:
Expand All @@ -239,7 +244,7 @@ def score(self, user_id, timeout=None, abuse_types=None, version=None):
except requests.exceptions.RequestException as e:
raise ApiException(str(e), url)

def get_user_score(self, user_id, timeout=None, abuse_types=None):
def get_user_score(self, user_id, timeout=None, abuse_types=None, include_score_percentiles=False):
"""Fetches the latest score(s) computed for the specified user and abuse types from the Sift Science API.
As opposed to client.score() and client.rescore_user(), this *does not* compute a new score for the user; it
simply fetches the latest score(s) which have computed. These scores may be arbitrarily old.
Expand All @@ -256,6 +261,9 @@ def get_user_score(self, user_id, timeout=None, abuse_types=None):
should be returned (if scores were requested). If not specified, a score will
be returned for every abuse_type to which you are subscribed.

include_score_percentiles(optional) : Whether to add new parameter in the query parameter.
if include_score_percentiles is true then add a new parameter called fields in the query parameter

Returns:
A sift.client.Response object if the score call succeeded, or raises
an ApiException.
Expand All @@ -271,6 +279,9 @@ def get_user_score(self, user_id, timeout=None, abuse_types=None):
if abuse_types:
params['abuse_types'] = ','.join(abuse_types)

if include_score_percentiles:
params['fields'] = 'SCORE_PERCENTILES'

try:
response = self.session.get(
url,
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.4.0'
VERSION = '5.5.0'
API_VERSION = '205'
1 change: 1 addition & 0 deletions test_integration_app/decisions_api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from decisions_api import test_decisions_api
66 changes: 66 additions & 0 deletions test_integration_app/decisions_api/test_decisions_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import sift
import globals

from os import environ as env

class DecisionAPI():
# Get the value of API_KEY from environment variable
api_key = env['API_KEY']
account_id = env['ACCOUNT_ID']
client = sift.Client(api_key = api_key, account_id = account_id)
globals.initialize()
user_id = globals.user_id

def apply_user_decision(self):
applyDecisionRequest = {
"decision_id" : "block_user_payment_abuse",
"source" : "MANUAL_REVIEW",
"analyst" : "[email protected]",
"description" : "User linked to three other payment abusers and ordering high value items"
}

return self.client.apply_user_decision(self.user_id, applyDecisionRequest)

def apply_order_decision(self):
applyOrderDecisionRequest = {
"decision_id" : "block_order_payment_abuse",
"source" : "AUTOMATED_RULE",
"description" : "Auto block pending order as score exceeded risk threshold of 90"
}

return self.client.apply_order_decision(self.user_id, "ORDER-1234567", applyOrderDecisionRequest)

def apply_session_decision(self):
applySessionDecisionRequest = {
"decision_id" : "session_looks_fraud_account_takover",
"source" : "MANUAL_REVIEW",
"analyst" : "[email protected]",
"description" : "compromised account reported to customer service"
}

return self.client.apply_session_decision(self.user_id, "session_id", applySessionDecisionRequest)

def apply_content_decision(self):
applyContentDecisionRequest = {
"decision_id" : "content_looks_fraud_content_abuse",
"source" : "MANUAL_REVIEW",
"analyst" : "[email protected]",
"description" : "fraudulent listing"
}

return self.client.apply_content_decision(self.user_id, "content_id", applyContentDecisionRequest)

def get_user_decisions(self):
return self.client.get_user_decisions(self.user_id)

def get_order_decisions(self):
return self.client.get_order_decisions("ORDER-1234567")

def get_content_decisions(self):
return self.client.get_content_decisions(self.user_id, "CONTENT_ID")

def get_session_decisions(self):
return self.client.get_session_decisions(self.user_id, "SESSION_ID")

def get_decisions(self):
return self.client.get_decisions(entity_type='user', limit=10, start_from=5, abuse_types='legacy,payment_abuse')
1 change: 1 addition & 0 deletions test_integration_app/events_api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from events_api import test_events_api
Loading