|
1 | 1 | import os
|
| 2 | +from datetime import datetime, timedelta |
2 | 3 |
|
3 | 4 | import fingerprint_pro_server_api_sdk
|
4 | 5 | from fingerprint_pro_server_api_sdk.rest import ApiException
|
|
12 | 13 |
|
13 | 14 | # create an instance of the API class
|
14 | 15 | api_instance = fingerprint_pro_server_api_sdk.FingerprintApi(configuration)
|
15 |
| -visitor_id = os.environ["VISITOR_ID"] |
16 |
| -request_id = os.environ["REQUEST_ID"] |
17 | 16 |
|
| 17 | +end = int(datetime.now().timestamp() * 1000) |
| 18 | +start = int((datetime.now() - timedelta(days=90)).timestamp() * 1000) |
| 19 | + |
| 20 | + |
| 21 | +# FingerprintApi->search_events usage example |
18 | 22 | try:
|
19 |
| - visits_response = api_instance.get_visits(visitor_id, limit=2) |
20 |
| - pagination_key = visits_response.pagination_key |
21 |
| - print("\n\n\nVisits response: \n", visits_response) |
| 23 | + search_events_response = api_instance.search_events(2, start=start, end=end) |
| 24 | + if len(search_events_response.events) == 0: |
| 25 | + print("FingerprintApi.search_events: is empty") |
| 26 | + exit(1) |
| 27 | + first_event = search_events_response.events[0] |
| 28 | + first_event_identification_data = first_event.products.identification.data |
| 29 | + visitor_id = first_event_identification_data.visitor_id |
| 30 | + request_id = first_event_identification_data.request_id |
| 31 | + print("\n\n\nSearch events response: \n", search_events_response) |
| 32 | + search_events_response_second_page = api_instance.search_events(2, start=start, end=end, pagination_key=search_events_response.pagination_key) |
22 | 33 |
|
23 |
| - visits_response = api_instance.get_visits( |
24 |
| - visitor_id, limit=2, pagination_key=pagination_key) |
| 34 | + if len(search_events_response_second_page.events) == 0: |
| 35 | + print("Second page of FingerprintApi.search_events: is empty") |
| 36 | + exit(1) |
25 | 37 |
|
26 | 38 | except ApiException as e:
|
27 |
| - print("Exception when calling DefaultApi->visitors_visitor_id_get: %s\n" % e) |
| 39 | + print("Exception when calling FingerprintApi.search_events: %s\n" % e) |
28 | 40 | exit(1)
|
29 | 41 |
|
| 42 | +# Use existing visitor_id from FingerprintApi->search_events response to check FingerprintApi->get_visits method |
30 | 43 | try:
|
31 |
| - events_response = api_instance.get_event(request_id) |
32 |
| - print("\n\n\nEvent response: \n", events_response.products) |
| 44 | + visits_response = api_instance.get_visits(visitor_id, limit=2) |
| 45 | + print("\n\n\nVisits response: \n", visits_response) |
33 | 46 |
|
34 | 47 | except ApiException as e:
|
35 |
| - print("Exception when calling DefaultApi->get_event: %s\n" % e) |
| 48 | + print("Exception when calling FingerprintApi.get_visits: %s\n" % e) |
36 | 49 | exit(1)
|
37 | 50 |
|
| 51 | +# Use existing request_id from FingerprintApi->search_events response to check FingerprintApi->get_event method |
38 | 52 | try:
|
39 |
| - search_events_response = api_instance.search_events(2, bot="bad") |
40 |
| - print("\n\n\nSearch events response: \n", search_events_response) |
| 53 | + events_response = api_instance.get_event(request_id) |
| 54 | + print("\n\n\nEvent response: \n", events_response.products) |
41 | 55 |
|
42 | 56 | except ApiException as e:
|
43 |
| - print("Exception when calling DefaultApi->search_events: %s\n" % e) |
| 57 | + print("Exception when calling FingerprintApi.get_event: %s\n" % e) |
44 | 58 | exit(1)
|
45 | 59 |
|
46 | 60 | # Async methods examples
|
|
55 | 69 | print("Exception when calling Async example: %s\n" % e)
|
56 | 70 | exit(1)
|
57 | 71 |
|
| 72 | +# Check that old events are still match expected format |
| 73 | +try: |
| 74 | + search_events_response_old = api_instance.search_events(1, start=start, end=end, reverse=True) |
| 75 | + if len(search_events_response_old.events) == 0: |
| 76 | + print("FingerprintApi.search_events: is empty for old events\n") |
| 77 | + exit(1) |
| 78 | + old_event_identification_data = search_events_response_old.events[0].products.identification.data |
| 79 | + visitor_id_old = old_event_identification_data.visitor_id |
| 80 | + request_id_old = old_event_identification_data.request_id |
| 81 | + |
| 82 | + if visitor_id_old == visitor_id or request_id_old == request_id: |
| 83 | + print("Old events are identical to new\n") |
| 84 | + exit(1) |
| 85 | + |
| 86 | + api_instance.get_visits(visitor_id_old, limit=2) |
| 87 | + api_instance.get_event(request_id_old) |
| 88 | + print("\n\n\nOld events are good\n") |
| 89 | +except ApiException as e: |
| 90 | + print("Exception when trying to read old data: %s\n" % e) |
| 91 | + |
58 | 92 | print("Checks passed!")
|
59 | 93 |
|
60 | 94 | exit(0)
|
0 commit comments