Skip to content

Commit

Permalink
Skip HAS ONLY test if mongomock version < 3.19.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Mar 4, 2020
1 parent f95f146 commit eb0eb88
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 3 additions & 3 deletions optimade/server/entry_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
from .query_params import EntryListingQueryParams, SingleEntryQueryParams

try:
ci_force_mongo = bool(int(os.environ.get("OPTIMADE_CI_FORCE_MONGO", 0)))
CI_FORCE_MONGO = bool(int(os.environ.get("OPTIMADE_CI_FORCE_MONGO", 0)))
except (TypeError, ValueError): # pragma: no cover
ci_force_mongo = False
CI_FORCE_MONGO = False


if CONFIG.use_real_mongo or ci_force_mongo:
if CONFIG.use_real_mongo or CI_FORCE_MONGO:
from pymongo import MongoClient

client = MongoClient(CONFIG.mongo_uri)
Expand Down
16 changes: 14 additions & 2 deletions tests/server/test_query_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@

from optimade.server.config import CONFIG
from optimade.server import mappers
from optimade.server.entry_collections import CI_FORCE_MONGO

from .utils import SetClient

MONGOMOCK_OLD = False
MONGOMOCK_MSG = ""
if not CI_FORCE_MONGO and not CONFIG.use_real_mongo:
import mongomock

MONGOMOCK_OLD = tuple(
int(val) for val in mongomock.__version__.split(".")[0:3]
) <= (3, 19, 0)
MONGOMOCK_MSG = f"mongomock version {mongomock.__version__}<=3.19.0 is too old for this test, skipping..."


class IncludeTests(SetClient, unittest.TestCase):
"""Make sure `include` is handled correctly
Expand Down Expand Up @@ -394,12 +405,13 @@ def test_list_length(self):
# expected_ids = []
# self._check_response(request, expected_ids, len(expected_ids))

@unittest.skipIf(MONGOMOCK_OLD, MONGOMOCK_MSG)
def test_list_has_only(self):
""" Test HAS ONLY query on elements.
This test fails with mongomock<=3.1.9 when $size is 1, but works with a real mongo.
This test fails with mongomock<=3.19.0 when $size is 1, but works with a real mongo.
TODO: this text should be removed once mongomock>3.1.9 has been released, which should
TODO: this text and skip condition should be removed once mongomock>3.19.0 has been released, which should
contain the bugfix for this: https://github.com/mongomock/mongomock/pull/597.
"""
Expand Down

0 comments on commit eb0eb88

Please sign in to comment.