|
5 | 5 | from sigma.backends.opensearch import OpensearchLuceneBackend |
6 | 6 | from sigma.collection import SigmaCollection |
7 | 7 |
|
| 8 | +def os_available_test(): |
| 9 | + try: |
| 10 | + requests.get('http://localhost:9200/') |
| 11 | + except requests.exceptions.ConnectionError: |
| 12 | + return False |
| 13 | + return True |
| 14 | + |
8 | 15 | @pytest.fixture(scope="class") |
9 | 16 | def prepare_es_data(): |
10 | | - requests.delete('http://localhost:9200/test-index') |
11 | | - requests.put("http://localhost:9200/test-index") |
12 | | - requests.put("http://localhost:9200/test-index/_mapping", json={ |
13 | | - "properties": { |
14 | | - "field": { |
15 | | - "type": "ip" |
| 17 | + if os_available_test(): |
| 18 | + requests.delete('http://localhost:9200/test-index') |
| 19 | + requests.put("http://localhost:9200/test-index") |
| 20 | + requests.put("http://localhost:9200/test-index/_mapping", json={ |
| 21 | + "properties": { |
| 22 | + "field": { |
| 23 | + "type": "ip" |
| 24 | + } |
16 | 25 | } |
17 | 26 | } |
18 | | - } |
19 | | - ) |
20 | | - requests.post("http://localhost:9200/test-index/_doc/", json={ "fieldA" : "valueA", "fieldB" : "valueB" }) |
21 | | - requests.post("http://localhost:9200/test-index/_doc/", json={ "fieldA" : "valueA1", "fieldB" : "valueB1" }) |
22 | | - requests.post("http://localhost:9200/test-index/_doc/", json={ "fieldA" : "valueA2", "fieldB" : "valueB2" }) |
23 | | - requests.post("http://localhost:9200/test-index/_doc/", json={ "fieldA" : "foosamplebar", "fieldB" : "foo" }) |
24 | | - requests.post("http://localhost:9200/test-index/_doc/", json={ "field" : "192.168.1.1" }) |
25 | | - requests.post("http://localhost:9200/test-index/_doc/", json={ "field name" : "value" }) |
26 | | - # Wait a bit for Documents to be indexed |
27 | | - time.sleep(1) |
| 27 | + ) |
| 28 | + requests.post("http://localhost:9200/test-index/_doc/", json={ "fieldA" : "valueA", "fieldB" : "valueB" }) |
| 29 | + requests.post("http://localhost:9200/test-index/_doc/", json={ "fieldA" : "valueA1", "fieldB" : "valueB1" }) |
| 30 | + requests.post("http://localhost:9200/test-index/_doc/", json={ "fieldA" : "valueA2", "fieldB" : "valueB2" }) |
| 31 | + requests.post("http://localhost:9200/test-index/_doc/", json={ "fieldA" : "foosamplebar", "fieldB" : "foo" }) |
| 32 | + requests.post("http://localhost:9200/test-index/_doc/", json={ "field" : "192.168.1.1" }) |
| 33 | + requests.post("http://localhost:9200/test-index/_doc/", json={ "field name" : "value" }) |
| 34 | + # Wait a bit for Documents to be indexed |
| 35 | + time.sleep(1) |
28 | 36 |
|
29 | 37 | @pytest.fixture |
30 | 38 | def lucene_backend(): |
31 | 39 | return OpensearchLuceneBackend() |
32 | 40 |
|
| 41 | +@pytest.mark.skipif(os_available_test() == False, reason="ES not available") |
33 | 42 | class TestConnectOpensearch: |
34 | 43 |
|
35 | 44 | def query_backend_hits(self, query, num_wanted=0): |
|
0 commit comments