Esempio n. 1
0
 def test_modulo(self):
     self.assertEqual(self._q(query.modulo(5, 2)), 1)
     # This is (15 % 10) % 2
     self.assertEqual(self._q(query.modulo(15, 10, 2)), 1)
     self.assertEqual(self._q(query.modulo(2)), 2)
     self._assert_bad_query(query.modulo(1, 0))
     self._assert_bad_query(query.modulo())
Esempio n. 2
0
  def test_filter(self):
    evens = query.filter_(lambda a: query.equals(query.modulo(a, 2), 0), [1, 2, 3, 4])
    self.assertEqual(self._q(evens), [2, 4])

    # Works on page too
    ref = self._create(n=11, m=12)["ref"]
    self._create(n=11)
    self._create(n=11)

    page = query.paginate(query.match(self.n_index_ref, 11))
    refs_with_m = query.filter_(lambda a: query.contains_path(["data", "m"], query.get(a)), page)
    self.assertEqual(self._q(refs_with_m), {"data": [ref]})
 def test_modulo(self):
     self.assertJson(query.modulo(1), '{"modulo":1}')
     self.assertJson(query.modulo(1, 2, 3), '{"modulo":[1,2,3]}')
     self.assertJson(query.modulo([1, 2, 3]), '{"modulo":[1,2,3]}')