Skip to content

Commit

Permalink
Fix mock opensearch tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ElliottKasoar committed Jun 12, 2024
1 parent 1a386b6 commit 0e30256
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions tests/test_opensearch_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,20 @@ def abcd(self):
else:
port = 9200
host = "localhost"
security_enabled = os.getenv("security_enabled") == "true"
if os.environ["opensearch-version"] == "latest":
credential = "admin:myStrongPassword123!"
else:
credential = "admin:admin"

logging.basicConfig(level=logging.INFO)

url = f"opensearch://admin:admin@{host}:{port}"
opensearch_abcd = ABCD.from_url(url, index_name="test_index", use_ssl=False)
url = f"opensearch://{credential}@{host}:{port}"
opensearch_abcd = ABCD.from_url(
url,
index_name="test_index",
use_ssl=security_enabled,
)
assert isinstance(opensearch_abcd, OpenSearchDatabase)
return opensearch_abcd

Expand Down Expand Up @@ -78,10 +87,9 @@ def test_push(self, abcd):
assert isinstance(atoms_2, Atoms)
atoms_2.set_cell([1, 1, 1])

abcd.refresh()
result = AtomsModel(
None,
None,
abcd.client.search(index="test_index")["hits"]["hits"][0]["_source"],
dict=abcd.client.search(index="test_index")["hits"]["hits"][0]["_source"],
).to_ase()
assert atoms_1 == result
assert atoms_2 != result
Expand Down Expand Up @@ -117,17 +125,14 @@ def test_bulk(self, abcd):
atoms_list.append(atoms_1)
atoms_list.append(atoms_2)
abcd.push(atoms_list)
abcd.refresh()
assert abcd.count() == 2

result_1 = AtomsModel(
None,
None,
abcd.client.search(index="test_index")["hits"]["hits"][0]["_source"],
dict=abcd.client.search(index="test_index")["hits"]["hits"][0]["_source"],
).to_ase()
result_2 = AtomsModel(
None,
None,
abcd.client.search(index="test_index")["hits"]["hits"][1]["_source"],
dict=abcd.client.search(index="test_index")["hits"]["hits"][1]["_source"],
).to_ase()
assert atoms_1 == result_1
assert atoms_2 == result_2
Expand All @@ -151,4 +156,5 @@ def test_count(self, abcd):
atoms.set_cell([1, 1, 1])
abcd.push(atoms)
abcd.push(atoms)
abcd.refresh()
assert abcd.count() == 2

0 comments on commit 0e30256

Please sign in to comment.