def test_eq_abstract_list(self): bar = self.Bar(abs_ref_list=self.foos[:3]) bar.save() result = self.Bar.find(Q('abs_ref_list', 'eq', self.foos[0])) assert_equal(len(result), 1) result = self.Bar.find(Q('abs_ref_list', 'eq', self.foos[-1])) assert_equal(len(result), 0)
def test_eq_foreign_list(self): bar = self.Bar(ref_list=self.foos[:3]) bar.save() result = self.Bar.find(Q('ref_list', 'eq', self.foos[0])) assert_equal(len(result), 1) result = self.Bar.find(Q('ref_list', 'eq', self.foos[-1])) assert_equal(len(result), 0)
def test_gte(self): """ Finds objects with the attribute greater than or equal to the parameter. """ result = self.Foo.find( Q('integer_field', 'gte', self.foos[1].integer_field)) self.assertEqual(len(result), 2)
def test_eq(self): """ Finds objects with the attribute equal to the parameter.""" self.assertEqual( self.Foo.find_one( Q('integer_field', 'eq', self.foos[1].integer_field))._id, self.foos[1]._id, )
def test_nin(self): """ Finds objects with the parameter not in the attribute.""" result = self.Foo.find(Q('integer_field', 'nin', [ 1, 11, 21, ])) self.assertEqual(len(result), 2)
def test_find_one(self): """ Given a query with exactly one result record, ``.find_one()`` should return that object. """ self.assertEqual( self.Foo.find_one(Q('_id', 'eq', 0))._id, self.foos[0]._id )
def test_lt(self): """ Finds objects with the attribute less than the parameter.""" result = self.Foo.find( Q('integer_field', 'lt', self.foos[1].integer_field)) self.assertEqual(len(result), 1)
def test_ne(self): """ Finds objects with the attribute not equal to the parameter.""" self.assertEqual( len( self.Foo.find( Q('integer_field', 'ne', self.foos[1].integer_field))), 2)
def test_find_one_return_zero(self): """ Given a query with zero result records, ``.find_one()`` should raise an appropriate error. """ with self.assertRaises(exceptions.NoResultsFound): self.Foo.find_one(Q('_id', 'eq', -1))
def test_endswith(self): """ Finds objects where the attribute ends with the substring """ result = self.Foo.find(Q('string_field', 'endswith', 'value')) self.assertEqual(len(result), 3)
def test_startwith(self): """ Finds objects where the attribute begins with the substring """ result = self.Foo.find(Q('string_field', 'startswith', 'second')) self.assertEqual(len(result), 1)
def test_icontains(self): """ Operates as ``contains``, but ignores case.""" result = self.Foo.find(Q('string_field', 'icontains', 'SeCoNd')) self.assertEqual(len(result), 1)
def test_contains(self): """ Finds objects with the attribute containing the substring.""" result = self.Foo.find(Q('string_field', 'contains', 'second')) self.assertEqual(len(result), 1)