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

Conversation

haneeshv
Copy link
Contributor

@haneeshv haneeshv commented Aug 3, 2023

Purpose

Currently, we don’t perform any thorough testing before releasing sift-python lib. The idea of this task is to actually setup an integration app that is going to contain a set of tests we run against the lib before releasing it. Those tests should be performed against real Sift env (Sift prod account)

This integration app can be a representative template for other libs - eventually we want to have the same integration app for every single public lib we support

Summary

Methods created for Events, Decisions, Workflows, Score, Verification and PSP Merchant API

Testing

Methods are implemented and tested manually

Checklist

  • The change was thoroughly tested manually
  • The change was covered with unit tests
  • The change was tested with real API calls (if applicable)
  • Necessary changes were made in the integration tests (if applicable)
  • New functionality is reflected in README

# Get the value of API_KEY from environment variable
api_key = env['API_KEY']

client = sift.Client(api_key = api_key, account_id = 'ACCT')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

account_id is probablky optional

}
}

response = client.verification_send(sendProperties)
Copy link
Contributor

@viaskal-sift viaskal-sift Aug 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to add assertion mechanism so that the cases fail when a particular condition is not met. For now we can just test the status in the response code which should be 0 for all successful calls

@@ -0,0 +1 @@
from decisions_api import test_decisions_api
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra line

@@ -0,0 +1 @@
from workflows_api import test_workflows_api
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: empty extra line should be provided

@@ -0,0 +1 @@
from score_api import test_score_api
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra line is missing

Comment on lines 421 to 423
assert(response.is_ok())
assert response.api_status == 0, "api_status should be 0"
assert response.api_error_message == "OK", "api_error_message should be OK"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the same code used in different tests. We may use something like utils.py file with the functions that can be reused

from labels_api import test_labels_api
from psp_merchant_api import test_psp_merchant_api

#Events APIs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why all those are commented out?

#Events APIs

# test_events_api.add_item_to_cart()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we can remove the spaces between the calls

@@ -0,0 +1 @@
from psp_merchant_api import test_psp_merchant_api
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra line is missing

@@ -0,0 +1 @@
from verifications_api import test_verification_api
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra line is missing

def test_verification_send():
client = sift.Client(api_key='valid-api-key', account_id='ACCT')
response = client.verification_send(sendProperties)
print(response)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we print the result instead of checking the response?

def test_verification_resend():
client = sift.Client(api_key='valid-api-key', account_id='ACCT')
response = client.verification_resend(resendProperties)
print(response)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same as above

def test_verification_check():
client = sift.Client(api_key='valid-api-key', account_id='ACCT')
response = client.verification_check(checkProperties)
print(response)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same as above

Comment on lines 62 to 66
test_verification_send()

# test_verification_resend()

# test_verification_check()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be moved to the main.py under the test_integration_app

else:
import urllib.parse

def response_with_data_header():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we need this one?

import sift
import sys

if sys.version_info[0] < 3:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is okay for us to concentrate only on Python 3 in these tests so feel free to remove all that is not related to Pythion 3

}

def test_verification_send():
client = sift.Client(api_key='valid-api-key', account_id='ACCT')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how this one is expected to work with this api_key?


def get_user_score():
response = client.get_user_score("[email protected]")
print(response)
Copy link
Contributor

@viaskal-sift viaskal-sift Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to print the results, it is okay just to run. Feel free to remove in other places as well

@viaskal-sift
Copy link
Contributor

@haneeshv several things

  • why test_sift_verification_apis.py is not withing the test_integration_app folder? Also, this tests file should be reviewed and made the same as the rest. Also, I think it simply doesn't work right now
  • some reused code can be moved into a separate file
  • don't print things

haneeshv and others added 2 commits September 25, 2023 15:39
Not required, created for testing purpose
@viaskal-sift viaskal-sift changed the title Integration testing files [MSUE-151] [MSUE-191] - Integration testing files Sep 26, 2023
def runAllMethods():
objUtils = Utils()
objEvents = test_events_api.EventsAPI()
ObjDecision = test_decisions_api.DecisionAPI()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: capital letter for ObjDecision


assert (objUtils.isOK(objVerification.send()) == True)
assert (objUtils.isOK(objVerification.resend()) == True)
assert (objUtils.isOK(objVerification.check()) == True)
Copy link
Contributor

@viaskal-sift viaskal-sift Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haneeshv how this one gonna work? The expectation is that this call will fail since the code will be wrong

Copy link
Contributor

@viaskal-sift viaskal-sift Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested:

res = objVerification.check()
assert (objUtils.isOK(res) == True)
assert. res.status == 50

"$verified_value" : "14155551212"
}
return self.client.track("$verification", verification_properties)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: too many extra lines


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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bit: too many extra lines

return self.client.track('$create_order', properties, return_workflow_status=True,
return_route_info=True, abuse_types=['promo_abuse', 'content_abuse', 'payment_abuse'])


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra line

Comment on lines +60 to +63
assert (objUtils.isOK(objDecision.apply_user_decision()) == False)
assert (objUtils.isOK(objDecision.apply_order_decision()) == False)
assert (objUtils.isOK(objDecision.apply_session_decision()) == False)
assert (objUtils.isOK(objDecision.apply_content_decision()) == False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why it is False?


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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants