def test_elem_match(self): mspec = mim.match({'foo': { '$elemMatch': { 'bar': 1, 'baz': 2 } } }, {'foo': [ { 'bar': 1, 'baz': 2 } ] }) self.assertIsNotNone(mspec) mspec = mim.match({'foo': { '$elemMatch': { 'bar': 1, 'baz': 2 } } }, {'foo': [ { 'bar': 1, 'baz': 1 }, { 'bar': 2, 'baz': 2 } ] }) self.assertIsNone(mspec)
def test_or(self): doc = { 'd': 2 } self.assertIsNotNone(mim.match( {'$or': [ { 'd': 1 }, { 'd': 2 } ] }, doc)) self.assertIsNone(mim.match( {'$or': [ { 'd': 1 }, { 'd': 3 } ] }, doc))
def test_traverse_list(self): doc = { 'a': [ { 'b': 1 }, { 'b': 2 } ] } self.assertIsNotNone(mim.match( {'a.b': 1 }, doc))
def test_all(self): doc = { 'c': [ 1, 2 ] } self.assertIsNotNone(mim.match({'c': {'$all': [] } }, doc)) self.assertIsNotNone(mim.match({'c': {'$all': [1] } }, doc)) self.assertIsNotNone(mim.match({'c': {'$all': [1, 2] } }, doc)) self.assertIsNone(mim.match({'c': {'$all': [1, 2, 3] } }, doc))
def test_exists(self): doc = { 'd': 2 } self.assertIsNotNone(mim.match({'d': { '$exists': 1 } }, doc)) self.assertIsNone(mim.match({'d': { '$exists': 0 } }, doc)) self.assertIsNone(mim.match({'e': { '$exists': 1 } }, doc)) self.assertIsNotNone(mim.match({'e': { '$exists': 0 } }, doc))
def test_range(self): doc = { 'd': 2 } self.assertIsNotNone(mim.match({'d': { '$gt': 1, '$lt': 3 } }, doc)) self.assertIsNone(mim.match({'d': { '$gt': 1, '$lt': 2 } }, doc)) self.assertIsNotNone(mim.match({'d': { '$gt': 1, '$lte': 2 } }, doc))
def test_lte(self): spec = { 'd': { '$lte': 2 } } self.assertIsNotNone(mim.match(spec, { 'd': 1 } )) self.assertIsNotNone(mim.match(spec, { 'd': 2 } )) self.assertIsNone(mim.match(spec, { 'd': 3 } ))
def test_list_match(self): mspec = mim.match({'foo.bar': 4}, { 'foo': { 'bar': [1,2,3,4,5] } }) self.assertEqual(mspec, mim.MatchDoc({ 'foo': mim.MatchDoc({'bar': mim.MatchList([1,2,3,4,5], pos=3) } ) })) self.assertEqual(mspec.getvalue('foo.bar.$'), 4)
def test_dotted_match(self): mspec = mim.match({'foo.bar': 4}, { 'foo': { 'bar': 4 } }) self.assertEqual(mspec, mim.MatchDoc({'foo': mim.MatchDoc({'bar': 4}) } ))
def test_simple_match(self): mspec = mim.match({'foo': 4}, { 'foo': 4 }) self.assertEqual(mspec, mim.MatchDoc({'foo': 4}))