def test_combining_same_type(self): flt1 = filtering.And( filtering.Equal('fiction', True), filtering.LessThan('rrp', 20), ) flt2 = filtering.And( filtering.Equal('authors', 1, len), filtering.NotEqual('genre', 'fantasy'), ) flt = flt1 + flt2 assert "(fiction == True AND rrp < 20 AND len(authors) == 1 AND genre != 'fantasy')" == str( flt)
def test_combine_with_comparison(self): flt1 = filtering.And( filtering.Equal('fiction', True), filtering.LessThan('rrp', 20), ) flt = flt1 + filtering.Equal('authors', 1, len) self.assertEqual( "(fiction == True AND rrp < 20 AND len(authors) == 1)", str(flt))
def test_matches_multiple_matches_resource(self): # Less than fiction $20 with a single author and not fantasy flt = filtering.And( filtering.Equal('fiction', True), filtering.LessThan('rrp', 20), filtering.Equal('authors', 1, len), filtering.NotEqual('genre', 'fantasy'), ) self.assertTrue(flt(first_book))
def test_combine_with_other_type(self): flt1 = filtering.And( filtering.Equal('fiction', True), filtering.LessThan('rrp', 20), ) self.assertRaises(TypeError, lambda: flt1 + 'abc')
def test_description(self): flt = filtering.And( filtering.Equal('fiction', True), filtering.LessThan('rrp', 20), ) self.assertEqual('(fiction == True AND rrp < 20)', str(flt))
def test_empty_description(self): flt = filtering.And() self.assertEqual('', str(flt))
def test_empty_description(self): flt = filtering.And() assert '' == str(flt)