Skip to content

Commit b1809a0

Browse files
authored
[API-7364] - Add integration tests to CI (#105)
[API-7364] - Tests fixes + CI step for the integration app
1 parent 22a950d commit b1809a0

6 files changed

Lines changed: 70 additions & 35 deletions

File tree

.circleci/config.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,23 @@ jobs:
3939
mock-version: 3.0.5
4040
requests-version: 2.27.1
4141

42+
run-integration-tests-python3:
43+
docker:
44+
- image: cimg/python:3.10.2
45+
steps:
46+
- checkout
47+
- run:
48+
name: Install the lib and run tests
49+
command: |
50+
pip3 install ../project
51+
python3 test_integration_app/main.py
52+
4253
workflows:
4354
build-and-test-wf:
4455
jobs:
4556
- build-and-test-python3
4657
- build-and-test-python2
58+
- run-integration-tests-python3:
59+
filters:
60+
branches:
61+
only: master

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,25 @@ errors from the root dir of the repository:
243243

244244
python -m unittest discover
245245
python3 -m unittest discover
246+
247+
## Integration testing app
248+
249+
For testing the app with real calls it is possible to run the integration testing app,
250+
it makes calls to almost all our public endpoints to make sure the library integrates
251+
well. At the moment, the app is run on every merge to master
252+
253+
#### How to run it locally
254+
255+
1. Add env variable `ACCOUNT_ID` with the valid account id
256+
2. Add env variable `API_KEY` with the valid Api Key associated from the account
257+
3. Run the following under the project root folder
258+
```
259+
# uninstall the lib from the local env (if it was installed)
260+
pip uninstall sift
261+
262+
# install the lib from the local source code
263+
pip install ../sift-python
264+
265+
# run the app
266+
python test_integration_app/main.py
267+
```

test_integration_app/decisions_api/test_decisions_api.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ class DecisionAPI():
1010
client = sift.Client(api_key = api_key, account_id = account_id)
1111
globals.initialize()
1212
user_id = globals.user_id
13+
session_id = globals.session_id
1314

1415
def apply_user_decision(self):
1516
applyDecisionRequest = {
16-
"decision_id" : "block_user_payment_abuse",
17+
"decision_id" : "integration_app_watch_account_abuse",
1718
"source" : "MANUAL_REVIEW",
1819
"analyst" : "analyst@example.com",
1920
"description" : "User linked to three other payment abusers and ordering high value items"
@@ -32,17 +33,17 @@ def apply_order_decision(self):
3233

3334
def apply_session_decision(self):
3435
applySessionDecisionRequest = {
35-
"decision_id" : "session_looks_fraud_account_takover",
36+
"decision_id" : "integration_app_watch_account_takeover",
3637
"source" : "MANUAL_REVIEW",
3738
"analyst" : "analyst@example.com",
3839
"description" : "compromised account reported to customer service"
3940
}
4041

41-
return self.client.apply_session_decision(self.user_id, "session_id", applySessionDecisionRequest)
42+
return self.client.apply_session_decision(self.user_id, self.session_id, applySessionDecisionRequest)
4243

4344
def apply_content_decision(self):
4445
applyContentDecisionRequest = {
45-
"decision_id" : "content_looks_fraud_content_abuse",
46+
"decision_id" : "integration_app_watch_content_abuse",
4647
"source" : "MANUAL_REVIEW",
4748
"analyst" : "analyst@example.com",
4849
"description" : "fraudulent listing"

test_integration_app/globals.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
def initialize():
2-
global user_id, user_email
2+
global user_id, user_email, session_id
33
user_id = 'billy_jones_301'
44
user_email = 'billjones1@example.com'
5+
session_id = 'gigtleqddo84l8cm15qe4il'

test_integration_app/main.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import string
2+
import random
3+
14
from events_api import test_events_api
25
from decisions_api import test_decisions_api
36
from workflows_api import test_workflows_api
@@ -22,7 +25,6 @@ def runAllMethods():
2225
objPSPMerchant = test_psp_merchant_api.PSPMerchantAPI()
2326

2427
#Events APIs
25-
2628
assert (objUtils.isOK(objEvents.add_item_to_cart()) == True)
2729
assert (objUtils.isOK(objEvents.add_promotion()) == True)
2830
assert (objUtils.isOK(objEvents.chargeback()) == True)
@@ -54,48 +56,43 @@ def runAllMethods():
5456
assert (objUtils.isOK(objEvents.update_password()) == True)
5557
assert (objUtils.isOK(objEvents.verification()) == True)
5658
print("Events API Tested")
57-
58-
# Decision APIs
5959

60-
assert (objUtils.isOK(objDecision.apply_user_decision()) == False)
61-
assert (objUtils.isOK(objDecision.apply_order_decision()) == False)
62-
assert (objUtils.isOK(objDecision.apply_session_decision()) == False)
63-
assert (objUtils.isOK(objDecision.apply_content_decision()) == False)
60+
# Decision APIs
61+
assert (objUtils.isOK(objDecision.apply_user_decision()) == True)
62+
assert (objUtils.isOK(objDecision.apply_order_decision()) == True)
63+
assert (objUtils.isOK(objDecision.apply_session_decision()) == True)
64+
assert (objUtils.isOK(objDecision.apply_content_decision()) == True)
6465
assert (objUtils.isOK(objDecision.get_user_decisions()) == True)
6566
assert (objUtils.isOK(objDecision.get_order_decisions()) == True)
6667
assert (objUtils.isOK(objDecision.get_content_decisions()) == True)
6768
assert (objUtils.isOK(objDecision.get_session_decisions()) == True)
6869
assert (objUtils.isOK(objDecision.get_decisions()) == True)
6970
print("Decision API Tested")
70-
71-
# Workflows APIs
7271

72+
# Workflows APIs
7373
assert (objUtils.isOK(objWorkflow.synchronous_workflows()) == True)
7474
print("Workflow API Tested")
75-
76-
# Score APIs
7775

78-
assert (objUtils.isOK(objScore.get_user_score()) == False)
76+
# Score APIs
77+
assert (objUtils.isOK(objScore.get_user_score()) == True)
7978
print("Score API Tested")
80-
81-
# Verification APIs
8279

80+
# Verification APIs
8381
assert (objUtils.isOK(objVerification.send()) == True)
8482
assert (objUtils.isOK(objVerification.resend()) == True)
8583
checkResponse = objVerification.check()
8684
assert (objUtils.isOK(checkResponse) == True)
8785
assert (checkResponse.body["status"] == 50)
8886
print("Verification API Tested")
89-
90-
# PSP Merchant APIs
9187

92-
assert (objUtils.isOK(objPSPMerchant.create_merchant()) == True)
93-
assert (objUtils.isOK(objPSPMerchant.edit_merchant()) == True)
94-
assert (objUtils.isOK(objPSPMerchant.get_a_merchant_profile()) == True)
88+
# PSP Merchant APIs
89+
merchant_id = 'merchant_id_test_app' + ''.join(random.choices(string.digits, k = 7))
90+
assert (objUtils.isOK(objPSPMerchant.create_merchant(merchant_id)) == True)
91+
assert (objUtils.isOK(objPSPMerchant.edit_merchant(merchant_id)) == True)
9592
assert (objUtils.isOK(objPSPMerchant.get_merchant_profiles()) == True)
9693
assert (objUtils.isOK(objPSPMerchant.get_merchant_profiles(batch_size=10, batch_token=None)) == True)
9794
print("PSP Merchant API Tested")
98-
99-
print("Execution completed")
95+
96+
print("API Integration tests execution finished")
10097

10198
runAllMethods()

test_integration_app/psp_merchant_api/test_psp_merchant_api.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ class PSPMerchantAPI():
1111

1212
client = sift.Client(api_key = api_key, account_id = account_id)
1313

14-
def create_merchant(self):
15-
merchant_id = ''.join(random.choices(string.digits, k = 7))
14+
def create_merchant(self, merchant_id):
1615
merchantProperties={
17-
"id": 'merchant_id_' + merchant_id,
16+
"id": merchant_id,
1817
"name": "Wonderful Payments Inc.13",
1918
"description": "Wonderful Payments payment provider.",
2019
"address": {
@@ -37,9 +36,9 @@ def create_merchant(self):
3736
}
3837
return self.client.create_psp_merchant_profile(merchantProperties)
3938

40-
def edit_merchant(self):
41-
merchantProperties={
42-
"id": "merchant_id_01013",
39+
def edit_merchant(self, merchant_id):
40+
merchantProperties = {
41+
"id": merchant_id,
4342
"name": "Wonderful Payments Inc.13 edit",
4443
"description": "Wonderful Payments payment provider. edit",
4544
"address": {
@@ -60,10 +59,10 @@ def edit_merchant(self):
6059
"score": 10
6160
}
6261
}
63-
return self.client.update_psp_merchant_profile("merchant_id_01013", merchantProperties)
62+
return self.client.update_psp_merchant_profile(merchant_id, merchantProperties)
6463

65-
def get_a_merchant_profile(self):
66-
return self.client.get_a_psp_merchant_profile("merchant_id_01013")
64+
def get_a_merchant_profile(self, merchant_id):
65+
return self.client.get_a_psp_merchant_profile(merchant_id)
6766

6867
def get_merchant_profiles(self, batch_token = None, batch_size = None):
6968
return self.client.get_psp_merchant_profiles(batch_token, batch_size)

0 commit comments

Comments
 (0)