|
1 | 1 | import datetime
|
2 |
| -import warnings |
3 | 2 | import json
|
4 |
| -import mock |
5 |
| -import sift |
6 |
| -import unittest |
7 | 3 | import sys
|
| 4 | +import unittest |
| 5 | +import warnings |
| 6 | + |
| 7 | +import mock |
8 | 8 | import requests.exceptions
|
| 9 | + |
| 10 | +import sift |
| 11 | + |
9 | 12 | if sys.version_info[0] < 3:
|
10 | 13 | import six.moves.urllib as urllib
|
11 | 14 | else:
|
@@ -73,6 +76,23 @@ def score_response_json():
|
73 | 76 | }"""
|
74 | 77 |
|
75 | 78 |
|
| 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 | + |
76 | 96 | # A sample response from the /{version}/users/{userId}/score API.
|
77 | 97 | USER_SCORE_RESPONSE_JSON = """{
|
78 | 98 | "status": 0,
|
@@ -435,6 +455,35 @@ def test_sync_score_ok(self):
|
435 | 455 | assert(response.body['score_response']['scores']['content_abuse']['score'] == 0.14)
|
436 | 456 | assert(response.body['score_response']['scores']['payment_abuse']['score'] == 0.97)
|
437 | 457 |
|
| 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 | + |
438 | 487 | def test_get_decisions_fails(self):
|
439 | 488 | with self.assertRaises(ValueError):
|
440 | 489 | self.sift_client.get_decisions('usr')
|
|
0 commit comments