def order_specification_factory(): """ Fixture creating a new :class:`everest.querying.specifications.OrderSpecificationFactory` instance. """ return OrderSpecificationFactory()
def setup_registry(self, filter_specification_factory=None, order_specification_factory=None, service=None, cql_filter_specification_visitor=None, sql_filter_specification_visitor=None, eval_filter_specification_visitor=None, cql_order_specification_visitor=None, sql_order_specification_visitor=None, eval_order_specification_visitor=None, url_converter=None, **kw): # Set default values for options. if filter_specification_factory is None: filter_specification_factory = FilterSpecificationFactory() if order_specification_factory is None: order_specification_factory = OrderSpecificationFactory() if service is None: service = Service() if cql_filter_specification_visitor is None: cql_filter_specification_visitor = CqlFilterSpecificationVisitor if sql_filter_specification_visitor is None: sql_filter_specification_visitor = SqlFilterSpecificationVisitor if eval_filter_specification_visitor is None: eval_filter_specification_visitor = \ ObjectFilterSpecificationVisitor if cql_order_specification_visitor is None: cql_order_specification_visitor = CqlOrderSpecificationVisitor if sql_order_specification_visitor is None: sql_order_specification_visitor = SqlOrderSpecificationVisitor if eval_order_specification_visitor is None: eval_order_specification_visitor = ObjectOrderSpecificationVisitor if url_converter is None: url_converter = ResourceUrlConverter PyramidConfigurator.setup_registry(self, **kw) self.__setup_everest( filter_specification_factory=filter_specification_factory, order_specification_factory=order_specification_factory, service=service, cql_filter_specification_visitor=cql_filter_specification_visitor, sql_filter_specification_visitor=sql_filter_specification_visitor, eval_filter_specification_visitor=eval_filter_specification_visitor, cql_order_specification_visitor=cql_order_specification_visitor, sql_order_specification_visitor=sql_order_specification_visitor, eval_order_specification_visitor=eval_order_specification_visitor, url_converter=url_converter)
def _make_specs_factory(self): return OrderSpecificationFactory()
def set_up(self): self.factory = OrderSpecificationFactory()
class OrderSpecificationTestCase(TestCaseWithIni): def set_up(self): self.factory = OrderSpecificationFactory() def create_ascending_spec(self, attr_name): return self.factory.create_ascending(attr_name) def create_descending_spec(self, attr_name): return self.factory.create_descending(attr_name) def create_natural_spec(self, attr_name): return NaturalOrderSpecification(attr_name) def test_operations(self): first_candidate = Candidate(number_attr=0, text_attr='a') second_candidate = Candidate(number_attr=1, text_attr='b') def _test(attr): spec_asc = self.create_ascending_spec(attr) spec_desc = self.create_descending_spec(attr) self.assert_equal(spec_asc.attr_name, attr) self.assert_equal(spec_desc.attr_name, attr) self.assert_false(spec_asc.eq(first_candidate, second_candidate)) self.assert_false(spec_desc.eq(first_candidate, second_candidate)) self.assert_true(spec_asc.ne(first_candidate, second_candidate)) self.assert_true(spec_desc.ne(first_candidate, second_candidate)) self.assert_true(spec_asc.lt(first_candidate, second_candidate)) self.assert_false(spec_desc.lt(first_candidate, second_candidate)) self.assert_false(spec_asc.ge(first_candidate, second_candidate)) self.assert_true(spec_desc.ge(first_candidate, second_candidate)) self.assert_true(spec_asc.le(first_candidate, second_candidate)) self.assert_false(spec_desc.le(first_candidate, second_candidate)) self.assert_false(spec_asc.gt(first_candidate, second_candidate)) self.assert_true(spec_desc.gt(first_candidate, second_candidate)) _test('number_attr') _test('text_attr') def test_basics(self): spec = self.create_ascending_spec('foo') str_str = '<%s attr_name:' % spec.__class__.__name__ self.assert_equal(str(spec)[:len(str_str)], str_str) def test_natural(self): first_candidate = Candidate(number_attr=0, text_attr='a10') second_candidate = Candidate(number_attr=1, text_attr='a9') text_spec = self.create_natural_spec('text_attr') self.assert_false(text_spec.lt(first_candidate, second_candidate)) number_spec = self.create_natural_spec('number_attr') self.assert_true(number_spec.lt(first_candidate, second_candidate)) def test_conjunction(self): first_candidate = Candidate(number_attr=0, text_attr='a') second_candidate = Candidate(number_attr=0, text_attr='b') text_spec = self.create_natural_spec('text_attr') number_spec = self.create_natural_spec('number_attr') conj_spec = self.factory.create_conjunction(number_spec, text_spec) str_str = '<%s left:' % conj_spec.__class__.__name__ self.assert_equal(str(conj_spec)[:len(str_str)], str_str) self.assert_true(conj_spec.lt(first_candidate, second_candidate)) self.assert_true(conj_spec.le(first_candidate, second_candidate)) self.assert_false(conj_spec.eq(first_candidate, second_candidate)) self.assert_equal(conj_spec.cmp(first_candidate, second_candidate), - 1) conj_spec = self.factory.create_conjunction(text_spec, number_spec) self.assert_true(conj_spec.lt(first_candidate, second_candidate)) self.assert_true(conj_spec.le(first_candidate, second_candidate)) self.assert_false(conj_spec.eq(first_candidate, second_candidate)) self.assert_equal(conj_spec.cmp(first_candidate, second_candidate), - 1)
class OrderSpecificationTestCase(TestCaseWithIni): def set_up(self): self.factory = OrderSpecificationFactory() def create_ascending_spec(self, attr_name): return self.factory.create_ascending(attr_name) def create_descending_spec(self, attr_name): return self.factory.create_descending(attr_name) def create_natural_spec(self, attr_name): return NaturalOrderSpecification(attr_name) def test_operations(self): first_candidate = Candidate(number_attr=0, text_attr='a') second_candidate = Candidate(number_attr=1, text_attr='b') def _test(attr): spec_asc = self.create_ascending_spec(attr) spec_desc = self.create_descending_spec(attr) self.assert_equal(spec_asc.attr_name, attr) self.assert_equal(spec_desc.attr_name, attr) self.assert_false(spec_asc.eq(first_candidate, second_candidate)) self.assert_false(spec_desc.eq(first_candidate, second_candidate)) self.assert_true(spec_asc.ne(first_candidate, second_candidate)) self.assert_true(spec_desc.ne(first_candidate, second_candidate)) self.assert_true(spec_asc.lt(first_candidate, second_candidate)) self.assert_false(spec_desc.lt(first_candidate, second_candidate)) self.assert_false(spec_asc.ge(first_candidate, second_candidate)) self.assert_true(spec_desc.ge(first_candidate, second_candidate)) self.assert_true(spec_asc.le(first_candidate, second_candidate)) self.assert_false(spec_desc.le(first_candidate, second_candidate)) self.assert_false(spec_asc.gt(first_candidate, second_candidate)) self.assert_true(spec_desc.gt(first_candidate, second_candidate)) _test('number_attr') _test('text_attr') def test_basics(self): spec = self.create_ascending_spec('foo') str_str = '<%s attr_name:' % spec.__class__.__name__ self.assert_equal(str(spec)[:len(str_str)], str_str) def test_natural(self): first_candidate = Candidate(number_attr=0, text_attr='a10') second_candidate = Candidate(number_attr=1, text_attr='a9') text_spec = self.create_natural_spec('text_attr') self.assert_false(text_spec.lt(first_candidate, second_candidate)) number_spec = self.create_natural_spec('number_attr') self.assert_true(number_spec.lt(first_candidate, second_candidate)) def test_conjunction(self): first_candidate = Candidate(number_attr=0, text_attr='a') second_candidate = Candidate(number_attr=0, text_attr='b') text_spec = self.create_natural_spec('text_attr') number_spec = self.create_natural_spec('number_attr') conj_spec = self.factory.create_conjunction(number_spec, text_spec) str_str = '<%s left:' % conj_spec.__class__.__name__ self.assert_equal(str(conj_spec)[:len(str_str)], str_str) self.assert_true(conj_spec.lt(first_candidate, second_candidate)) self.assert_true(conj_spec.le(first_candidate, second_candidate)) self.assert_false(conj_spec.eq(first_candidate, second_candidate)) self.assert_equal(conj_spec.cmp(first_candidate, second_candidate), -1) conj_spec = self.factory.create_conjunction(text_spec, number_spec) self.assert_true(conj_spec.lt(first_candidate, second_candidate)) self.assert_true(conj_spec.le(first_candidate, second_candidate)) self.assert_false(conj_spec.eq(first_candidate, second_candidate)) self.assert_equal(conj_spec.cmp(first_candidate, second_candidate), -1)