Skip to content

Commit cc34495

Browse files
committed
fix tests for elasticsearch
1 parent 41e3c29 commit cc34495

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

optimade/server/create_app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ def insert_index_data(
138138

139139
links_coll = entry_collections["links"]
140140

141-
if links_coll.collection.estimated_document_count() > 0:
142-
LOGGER.info("Skipping index links insert: links collection already populated.")
141+
if len(links_coll) > 0:
142+
LOGGER.info("Skipping index links inserct: links collection already populated.")
143143
return
144144

145145
LOGGER.debug("Loading index links...")

tests/server/entry_collections/test_indexes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import pytest
22
from bson import ObjectId
33

4+
from optimade.server.config import ServerConfig
45

6+
CONFIG = ServerConfig()
7+
8+
9+
@pytest.mark.skipif(
10+
CONFIG.database_backend.value not in ("mongomock", "mongodb"),
11+
reason="Skipping index test when testing the elasticsearch backend.",
12+
)
513
def test_indexes_are_created_where_appropriate(client):
614
"""Test that with the test config, default indices are made by
715
supported backends. This is tested by checking that we cannot insert

tests/server/test_mappers.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
from optimade.server.config import ServerConfig
55
from optimade.server.mappers import BaseResourceMapper
66

7+
CONFIG = ServerConfig()
78

9+
10+
@pytest.mark.skipif(
11+
CONFIG.database_backend.value not in ("mongomock", "mongodb"),
12+
reason="Skipping mongo-related test when testing the elasticsearch backend.",
13+
)
814
def test_disallowed_aliases():
915
from optimade.server.entry_collections.mongo import MongoCollection
1016

@@ -14,7 +20,7 @@ class MyMapper(BaseResourceMapper):
1420

1521
mapper = MyMapper()
1622
with pytest.raises(RuntimeError):
17-
MongoCollection("fake", StructureResource, mapper, config=ServerConfig())
23+
MongoCollection("fake", StructureResource, mapper, config=CONFIG)
1824

1925

2026
def test_property_aliases():

0 commit comments

Comments
 (0)