Skip to content

Commit

Permalink
Added tests for length aliasing
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Mar 17, 2020
1 parent 39e3c33 commit b0de4ad
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/filtertransformers/test_mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,21 @@ def test_not_implemented(self):
with self.assertRaises(VisitError):
self.transform("list LENGTH > 3")

def test_list_length_aliases(self):
from optimade.server.mappers import StructureMapper

class AliasedStructureMapper(StructureMapper):
LENGTH_ALIASES = (("elements", "nelements"),)

t = MongoTransformer(mapper=AliasedStructureMapper())
p = LarkParser(version=self.version, variant=self.variant)
self.assertEqual(t.transform(p.parse("elements LENGTH 3")), {"nelements": 3})

self.assertEqual(
t.transform(p.parse('elements HAS "Li" AND elements LENGTH = 3')),
{"$and": [{"elements": {"$in": ["Li"]}}, {"nelements": 3}]},
)

def test_list_properties(self):
""" Test the HAS ALL, ANY and optional ONLY queries.
Expand Down

0 comments on commit b0de4ad

Please sign in to comment.