Skip to content

Don't use outdated events in functional tests #112

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 5 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 0 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
PRIVATE_KEY=<SECRET_API_KEY>
REQUEST_ID=<REQUEST_ID>
VISITOR_ID=<VISITOR_ID>
VISITOR_ID_TO_DELETE=<VISITOR_ID_TO_DELETE> # for delete visitor example
REQUEST_ID_TO_UPDATE=<REQUEST_ID_TO_UPDATE> # for update event example
# put 'eu' or 'ap' if necessary, 'us' is default
Expand Down
52 changes: 38 additions & 14 deletions run_checks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from datetime import datetime, timedelta

import fingerprint_pro_server_api_sdk
from fingerprint_pro_server_api_sdk.rest import ApiException
Expand All @@ -12,35 +13,45 @@

# create an instance of the API class
api_instance = fingerprint_pro_server_api_sdk.FingerprintApi(configuration)
visitor_id = os.environ["VISITOR_ID"]
request_id = os.environ["REQUEST_ID"]

end = int(datetime.now().timestamp() * 1000)
start = int((datetime.now() - timedelta(days=90)).timestamp() * 1000)


# FingerprintApi->search_events usage example
try:
visits_response = api_instance.get_visits(visitor_id, limit=2)
pagination_key = visits_response.pagination_key
print("\n\n\nVisits response: \n", visits_response)
search_events_response = api_instance.search_events(2, start=start, end=end)
first_event = search_events_response.events[0]
first_event_identification_data = first_event.products.identification.data
visitor_id = first_event_identification_data.visitor_id
request_id = first_event_identification_data.request_id
print("\n\n\nSearch events response: \n", search_events_response)
search_events_response_second_page = api_instance.search_events(2, start=start, end=end, pagination_key=search_events_response.pagination_key)

visits_response = api_instance.get_visits(
visitor_id, limit=2, pagination_key=pagination_key)
if len(search_events_response_second_page.events) == 0:
print("Second page of FingerprintApi->search_events: is empty")
exit(1)

except ApiException as e:
print("Exception when calling DefaultApi->visitors_visitor_id_get: %s\n" % e)
print("Exception when calling FingerprintApi->search_events: %s\n" % e)
exit(1)

# Use existing visitor_id from FingerprintApi->search_events response to check FingerprintApi->get_visits method
try:
events_response = api_instance.get_event(request_id)
print("\n\n\nEvent response: \n", events_response.products)
visits_response = api_instance.get_visits(visitor_id, limit=2)
print("\n\n\nVisits response: \n", visits_response)

except ApiException as e:
print("Exception when calling DefaultApi->get_event: %s\n" % e)
print("Exception when calling FingerprintApi->get_visits: %s\n" % e)
exit(1)

# Use existing request_id from FingerprintApi->search_events response to check FingerprintApi->get_event method
try:
search_events_response = api_instance.search_events(2, bot="bad")
print("\n\n\nSearch events response: \n", search_events_response)
events_response = api_instance.get_event(request_id)
print("\n\n\nEvent response: \n", events_response.products)

except ApiException as e:
print("Exception when calling DefaultApi->search_events: %s\n" % e)
print("Exception when calling FingerprintApi->get_event: %s\n" % e)
exit(1)

# Async methods examples
Expand All @@ -55,6 +66,19 @@
print("Exception when calling Async example: %s\n" % e)
exit(1)

# Check that old events are still match expected format
try:
search_events_response_old = api_instance.search_events(1, start=start, end=end, reverse=True)
old_event_identification_data = search_events_response_old.events[0].products.identification.data
visitor_id_old = old_event_identification_data.visitor_id
request_id_old = old_event_identification_data.request_id

api_instance.get_visits(visitor_id_old, limit=2)
api_instance.get_event(request_id_old)
print("\n\n\nOld events are good\n")
except ApiException as e:
print("Exception when trying to read old data: %s\n" % e)

print("Checks passed!")

exit(0)
Loading