Skip to content

Commit 9b25099

Browse files
committed
Add missing test
1 parent 450caac commit 9b25099

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/zig-out
22
/.zig-cache
3+
__pycache__

tests/test_fingerprint_api.py

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import json
2+
3+
4+
def test_insert(client, index_name, create_index):
5+
# insert fingerprint
6+
req = client.post(f'/{index_name}/_update', json={
7+
'changes': [
8+
{'insert': {'id': 1, 'hashes': [100, 200, 300]}}
9+
],
10+
})
11+
assert req.status_code == 200, req.content
12+
assert json.loads(req.content) == {}
13+
14+
# verify we can find it
15+
req = client.post(f'/{index_name}/_search', json={
16+
'query': [100, 200, 300]
17+
})
18+
assert req.status_code == 200, req.content
19+
assert json.loads(req.content) == {
20+
'results': [{'id': 1, 'score': 3}]
21+
}
22+
23+
24+
def test_update_full(client, index_name, create_index):
25+
# insert fingerprint
26+
req = client.post(f'/{index_name}/_update', json={
27+
'changes': [
28+
{'insert': {'id': 1, 'hashes': [100, 200, 300]}}
29+
],
30+
})
31+
assert req.status_code == 200, req.content
32+
assert json.loads(req.content) == {}
33+
34+
# update fingerprint
35+
req = client.post(f'/{index_name}/_update', json={
36+
'changes': [
37+
{'insert': {'id': 1, 'hashes': [1000, 2000, 3000]}}
38+
],
39+
})
40+
assert req.status_code == 200, req.content
41+
assert json.loads(req.content) == {}
42+
43+
# verify we can't find the original version
44+
req = client.post(f'/{index_name}/_search', json={
45+
'query': [100, 200, 300]
46+
})
47+
assert req.status_code == 200, req.content
48+
assert json.loads(req.content) == {
49+
'results': []
50+
}
51+
52+
# verify we can't find the updated version
53+
req = client.post(f'/{index_name}/_search', json={
54+
'query': [1000, 2000, 3000]
55+
})
56+
assert req.status_code == 200, req.content
57+
assert json.loads(req.content) == {
58+
'results': [{'id': 1, 'score': 3}]
59+
}
60+
61+
62+
def test_update_partial(client, index_name, create_index):
63+
# insert fingerprint
64+
req = client.post(f'/{index_name}/_update', json={
65+
'changes': [
66+
{'insert': {'id': 1, 'hashes': [100, 200, 300]}}
67+
],
68+
})
69+
assert req.status_code == 200, req.content
70+
assert json.loads(req.content) == {}
71+
72+
# update fingerprint
73+
req = client.post(f'/{index_name}/_update', json={
74+
'changes': [
75+
{'insert': {'id': 1, 'hashes': [100, 200, 999]}}
76+
],
77+
})
78+
assert req.status_code == 200, req.content
79+
assert json.loads(req.content) == {}
80+
81+
# verify we can't find the original version
82+
req = client.post(f'/{index_name}/_search', json={
83+
'query': [100, 200, 300]
84+
})
85+
assert req.status_code == 200, req.content
86+
assert json.loads(req.content) == {
87+
'results': [{'id': 1, 'score': 2}]
88+
}
89+
90+
# verify we can't find the updated version
91+
req = client.post(f'/{index_name}/_search', json={
92+
'query': [100, 200, 999]
93+
})
94+
assert req.status_code == 200, req.content
95+
assert json.loads(req.content) == {
96+
'results': [{'id': 1, 'score': 3}]
97+
}
98+
99+
100+
def test_delete(client, index_name, create_index):
101+
# insert fingerprint
102+
req = client.post(f'/{index_name}/_update', json={
103+
'changes': [
104+
{'insert': {'id': 1, 'hashes': [100, 200, 300]}}
105+
],
106+
})
107+
assert req.status_code == 200, req.content
108+
assert json.loads(req.content) == {}
109+
110+
# delete fingerprint
111+
req = client.post(f'/{index_name}/_update', json={
112+
'changes': [
113+
{'delete': {'id': 1}}
114+
],
115+
})
116+
assert req.status_code == 200, req.content
117+
assert json.loads(req.content) == {}
118+
119+
# verify we can't find it
120+
req = client.post(f'/{index_name}/_search', json={
121+
'query': [100, 200, 300]
122+
})
123+
assert req.status_code == 200, req.content
124+
assert json.loads(req.content) == {
125+
'results': []
126+
}

0 commit comments

Comments
 (0)