Skip to content

Commit 2fb5463

Browse files
authored
Merge pull request #112 from fingerprintjs/refactor-functional-tests
Don't use outdated events in functional tests
2 parents 98d5c89 + 37989bf commit 2fb5463

File tree

5 files changed

+52
-22
lines changed

5 files changed

+52
-22
lines changed

.env.example

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
PRIVATE_KEY=<SECRET_API_KEY>
2-
REQUEST_ID=<REQUEST_ID>
3-
VISITOR_ID=<VISITOR_ID>
42
VISITOR_ID_TO_DELETE=<VISITOR_ID_TO_DELETE> # for delete visitor example
53
REQUEST_ID_TO_UPDATE=<REQUEST_ID_TO_UPDATE> # for update event example
64
# put 'eu' or 'ap' if necessary, 'us' is default

.github/workflows/coverage-report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/checkout@v4
1515
- uses: actions/setup-python@v5
1616
with:
17-
python-version: "3.12"
17+
python-version: "3.13"
1818
- name: "Install dependencies"
1919
run: |
2020
python -m pip install --upgrade pip

.github/workflows/functional_tests.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
fail-fast: false
1818
max-parallel: 1
1919
matrix:
20-
python-version: [ "3.9", "3.10", "3.11", "3.12", "pypy3.9", "pypy3.10" ]
20+
python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13", "pypy3.9", "pypy3.10" ]
2121

2222
steps:
2323
- uses: actions/checkout@v4
@@ -33,8 +33,6 @@ jobs:
3333
run: "python ./run_checks.py"
3434
env:
3535
PRIVATE_KEY: "${{ secrets.PRIVATE_KEY }}"
36-
VISITOR_ID: "${{ secrets.VISITOR_ID }}"
37-
REQUEST_ID: "${{ secrets.REQUEST_ID }}"
3836

3937
report-status:
4038
needs: functional_tests

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ on:
99
jobs:
1010
tests:
1111
name: "Python ${{ matrix.python-version }}"
12-
runs-on: "ubuntu-20.04"
12+
runs-on: "ubuntu-latest"
1313

1414
strategy:
1515
matrix:
16-
python-version: [ "3.9", "3.10", "3.11", "3.12", "pypy3.9", "pypy3.10" ]
16+
python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13", "pypy3.9", "pypy3.10" ]
1717

1818
steps:
1919
- uses: actions/checkout@v4

run_checks.py

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from datetime import datetime, timedelta
23

34
import fingerprint_pro_server_api_sdk
45
from fingerprint_pro_server_api_sdk.rest import ApiException
@@ -12,35 +13,48 @@
1213

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

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
1822
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)
2233

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)
2537

2638
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)
2840
exit(1)
2941

42+
# Use existing visitor_id from FingerprintApi->search_events response to check FingerprintApi->get_visits method
3043
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)
3346

3447
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)
3649
exit(1)
3750

51+
# Use existing request_id from FingerprintApi->search_events response to check FingerprintApi->get_event method
3852
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)
4155

4256
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)
4458
exit(1)
4559

4660
# Async methods examples
@@ -55,6 +69,26 @@
5569
print("Exception when calling Async example: %s\n" % e)
5670
exit(1)
5771

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+
5892
print("Checks passed!")
5993

6094
exit(0)

0 commit comments

Comments
 (0)