Skip to content

Commit ea0279d

Browse files
committed
Tests: Connect test skipping if OS not avail
1 parent dd2488e commit ea0279d

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

tests/test_backend_opensearch_connect.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,40 @@
55
from sigma.backends.opensearch import OpensearchLuceneBackend
66
from sigma.collection import SigmaCollection
77

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+
815
@pytest.fixture(scope="class")
916
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+
}
1625
}
1726
}
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)
2836

2937
@pytest.fixture
3038
def lucene_backend():
3139
return OpensearchLuceneBackend()
3240

41+
@pytest.mark.skipif(os_available_test() == False, reason="ES not available")
3342
class TestConnectOpensearch:
3443

3544
def query_backend_hits(self, query, num_wanted=0):

0 commit comments

Comments
 (0)