|
1 | 1 | import json
|
2 | 2 |
|
3 | 3 |
|
4 |
| -def test_insert(client, index_name, create_index): |
| 4 | +def test_insert_single(client, index_name, create_index): |
| 5 | + # insert fingerprint |
| 6 | + req = client.put(f'/{index_name}/1', json={'hashes': [101, 201, 301]}) |
| 7 | + assert req.status_code == 200, req.content |
| 8 | + assert json.loads(req.content) == {} |
| 9 | + |
| 10 | + # verify we can find it |
| 11 | + req = client.post(f'/{index_name}/_search', json={ |
| 12 | + 'query': [101, 201, 301] |
| 13 | + }) |
| 14 | + assert req.status_code == 200, req.content |
| 15 | + assert json.loads(req.content) == { |
| 16 | + 'results': [ |
| 17 | + {'id': 1, 'score': 3}, |
| 18 | + ], |
| 19 | + } |
| 20 | + |
| 21 | + req = client.get(f'/{index_name}/1') |
| 22 | + assert req.status_code == 200, req.content |
| 23 | + assert json.loads(req.content) == { |
| 24 | + 'version': 1, |
| 25 | + } |
| 26 | + |
| 27 | + |
| 28 | +def test_insert_multi(client, index_name, create_index): |
5 | 29 | # insert fingerprint
|
6 | 30 | req = client.post(f'/{index_name}/_update', json={
|
7 | 31 | 'changes': [
|
8 |
| - {'insert': {'id': 1, 'hashes': [100, 200, 300]}} |
| 32 | + {'insert': {'id': 1, 'hashes': [101, 201, 301]}}, |
| 33 | + {'insert': {'id': 2, 'hashes': [102, 202, 302]}}, |
9 | 34 | ],
|
10 | 35 | })
|
11 | 36 | assert req.status_code == 200, req.content
|
12 | 37 | assert json.loads(req.content) == {}
|
13 | 38 |
|
14 | 39 | # verify we can find it
|
15 | 40 | req = client.post(f'/{index_name}/_search', json={
|
16 |
| - 'query': [100, 200, 300] |
| 41 | + 'query': [101, 201, 301, 102, 202, 302] |
17 | 42 | })
|
18 | 43 | assert req.status_code == 200, req.content
|
19 | 44 | assert json.loads(req.content) == {
|
20 |
| - 'results': [{'id': 1, 'score': 3}] |
| 45 | + 'results': [ |
| 46 | + {'id': 1, 'score': 3}, |
| 47 | + {'id': 2, 'score': 3}, |
| 48 | + ], |
21 | 49 | }
|
22 | 50 |
|
23 |
| - # verify we can get id |
24 | 51 | req = client.get(f'/{index_name}/1')
|
25 | 52 | assert req.status_code == 200, req.content
|
26 | 53 | assert json.loads(req.content) == {
|
27 | 54 | 'version': 1,
|
28 | 55 | }
|
29 | 56 |
|
| 57 | + req = client.get(f'/{index_name}/2') |
| 58 | + assert req.status_code == 200, req.content |
| 59 | + assert json.loads(req.content) == { |
| 60 | + 'version': 1, |
| 61 | + } |
| 62 | + |
30 | 63 |
|
31 | 64 | def test_update_full(client, index_name, create_index):
|
32 | 65 | # insert fingerprint
|
@@ -118,25 +151,60 @@ def test_update_partial(client, index_name, create_index):
|
118 | 151 | }
|
119 | 152 |
|
120 | 153 |
|
121 |
| -def test_delete(client, index_name, create_index): |
122 |
| - # insert fingerprint |
| 154 | +def test_delete_multi(client, index_name, create_index): |
| 155 | + # insert fingerprints |
123 | 156 | req = client.post(f'/{index_name}/_update', json={
|
124 | 157 | 'changes': [
|
125 |
| - {'insert': {'id': 1, 'hashes': [100, 200, 300]}} |
| 158 | + {'insert': {'id': 1, 'hashes': [101, 201, 301]}}, |
| 159 | + {'insert': {'id': 2, 'hashes': [102, 202, 302]}}, |
126 | 160 | ],
|
127 | 161 | })
|
128 | 162 | assert req.status_code == 200, req.content
|
129 | 163 | assert json.loads(req.content) == {}
|
130 | 164 |
|
131 |
| - # delete fingerprint |
| 165 | + # delete fingerprints |
132 | 166 | req = client.post(f'/{index_name}/_update', json={
|
133 | 167 | 'changes': [
|
134 |
| - {'delete': {'id': 1}} |
| 168 | + {'delete': {'id': 1}}, |
| 169 | + {'delete': {'id': 2}}, |
135 | 170 | ],
|
136 | 171 | })
|
137 | 172 | assert req.status_code == 200, req.content
|
138 | 173 | assert json.loads(req.content) == {}
|
139 | 174 |
|
| 175 | + # verify we can't find it |
| 176 | + req = client.post(f'/{index_name}/_search', json={ |
| 177 | + 'query': [101, 201, 301, 102, 202, 302] |
| 178 | + }) |
| 179 | + assert req.status_code == 200, req.content |
| 180 | + assert json.loads(req.content) == { |
| 181 | + 'results': [] |
| 182 | + } |
| 183 | + |
| 184 | + req = client.get(f'/{index_name}/1') |
| 185 | + assert req.status_code == 404, req.content |
| 186 | + assert json.loads(req.content) == { |
| 187 | + 'error': 'FingerprintNotFound', |
| 188 | + } |
| 189 | + |
| 190 | + req = client.get(f'/{index_name}/2') |
| 191 | + assert req.status_code == 404, req.content |
| 192 | + assert json.loads(req.content) == { |
| 193 | + 'error': 'FingerprintNotFound', |
| 194 | + } |
| 195 | + |
| 196 | + |
| 197 | +def test_delete_single(client, index_name, create_index): |
| 198 | + # insert fingerprint |
| 199 | + req = client.put(f'/{index_name}/1', json={'hashes': [100, 200, 300]}) |
| 200 | + assert req.status_code == 200, req.content |
| 201 | + assert json.loads(req.content) == {} |
| 202 | + |
| 203 | + # delete fingerprint |
| 204 | + req = client.delete(f'/{index_name}/1') |
| 205 | + assert req.status_code == 200, req.content |
| 206 | + assert json.loads(req.content) == {} |
| 207 | + |
140 | 208 | # verify we can't find it
|
141 | 209 | req = client.post(f'/{index_name}/_search', json={
|
142 | 210 | 'query': [100, 200, 300]
|
|
0 commit comments