예제 #1
0
class NegationFilterSpecificationTestCase(TestCaseWithIni):

    def set_up(self):
        self.factory = FilterSpecificationFactory()
        self.candidate = object()
        self.always_true = AlwaysTrueFilterSpecification()
        self.always_false = AlwaysFalseFilterSpecification()

    def create_negation_spec(self, wrapped_spec):
        return self.factory.create_negation(wrapped_spec)

    def test_basics(self):
        spec = self.create_negation_spec(self.always_false)
        self.assert_equal(spec, spec)
        spec_other_spec = self.create_negation_spec(self.always_true)
        self.assert_not_equal(spec, spec_other_spec)
        str_str = '<%s wrapped_spec:' % spec.__class__.__name__
        self.assert_equal(str(spec)[:len(str_str)], str_str)

    def test_negation_is_satisfied_by_candidate(self):
        spec = self.create_negation_spec(self.always_false)
        self.assert_true(spec.is_satisfied_by(self.candidate))

    def test_negation_is_not_satisfied_by_candidate(self):
        spec = self.create_negation_spec(self.always_true)
        self.assert_false(spec.is_satisfied_by(self.candidate))
예제 #2
0
def filter_specification_factory():
    """
    Fixture creating a new
    :class:`everest.querying.specifications.FilterSpecificationFactory`
    instance.
    """
    return FilterSpecificationFactory()
예제 #3
0
class NegationFilterSpecificationTestCase(TestCaseWithIni):
    def set_up(self):
        self.factory = FilterSpecificationFactory()
        self.candidate = object()
        self.always_true = AlwaysTrueFilterSpecification()
        self.always_false = AlwaysFalseFilterSpecification()

    def create_negation_spec(self, wrapped_spec):
        return self.factory.create_negation(wrapped_spec)

    def test_basics(self):
        spec = self.create_negation_spec(self.always_false)
        self.assert_equal(spec, spec)
        spec_other_spec = self.create_negation_spec(self.always_true)
        self.assert_not_equal(spec, spec_other_spec)
        str_str = '<%s wrapped_spec:' % spec.__class__.__name__
        self.assert_equal(str(spec)[:len(str_str)], str_str)

    def test_negation_is_satisfied_by_candidate(self):
        spec = self.create_negation_spec(self.always_false)
        self.assert_true(spec.is_satisfied_by(self.candidate))

    def test_negation_is_not_satisfied_by_candidate(self):
        spec = self.create_negation_spec(self.always_true)
        self.assert_false(spec.is_satisfied_by(self.candidate))
예제 #4
0
 def test_filter_specification_visitor(self):
     coll = get_root_collection(IMyEntity)
     mb_cls = get_member_class(coll)
     my_entity = create_entity()
     member = coll.create_member(my_entity)
     spec_fac = FilterSpecificationFactory()
     specs = [
         # Terminal access.
         spec_fac.create_equal_to('text', self.TEST_TEXT),
         # Terminal access with different name in entity.
         spec_fac.create_equal_to('text_rc', self.TEST_TEXT),
         # Nested member access with different name in entity.
         spec_fac.create_equal_to('parent.text_rc', self.TEST_TEXT),
         # Nested collection access with different name in entity.
         spec_fac.create_equal_to('children.text_rc', self.TEST_TEXT),
         # Access with dotted entity name in rc attr declaration.
         spec_fac.create_equal_to('parent_text', self.TEST_TEXT),
         # Access to member.
         spec_fac.create_equal_to('parent', member.parent.get_entity()),
     ]
     expecteds = [
         ('text', MyEntity.text.__eq__(self.TEST_TEXT)),
         ('text_ent', MyEntity.text_ent.__eq__(self.TEST_TEXT)),
         ('parent.text_ent',
          MyEntity.parent.has(MyEntityParent.text_ent.__eq__(
              self.TEST_TEXT))),
         ('children.text_ent',
          MyEntity.children.any(
              MyEntityChild.text_ent.__eq__(self.TEST_TEXT))),
         ('parent.text_ent',
          MyEntity.parent.has(MyEntityParent.text_ent.__eq__(
              self.TEST_TEXT))),
         ('parent', MyEntity.parent.__eq__(member.parent.get_entity())),
     ]
     for spec, expected in zip(specs, expecteds):
         new_attr_name, expr = expected
         visitor = ResourceToEntityFilterSpecificationVisitor(mb_cls)
         spec.accept(visitor)
         new_spec = visitor.expression
         self.assert_equal(new_spec.attr_name, new_attr_name)
         visitor = SqlFilterSpecificationVisitor(MyEntity)
         new_spec.accept(visitor)
         self.assert_equal(str(visitor.expression), str(expr))
     invalid_spec = spec_fac.create_equal_to('foo', self.TEST_TEXT)
     vst = ResourceToEntityFilterSpecificationVisitor(mb_cls)
     self.assert_raises(AttributeError, invalid_spec.accept, vst)
예제 #5
0
 def test_filter_specification_visitor(self):
     coll = get_root_collection(IMyEntity)
     mb_cls = get_member_class(coll)
     my_entity = create_entity()
     member = coll.create_member(my_entity)
     spec_fac = FilterSpecificationFactory()
     specs = [
             # Terminal access.
             spec_fac.create_equal_to('text', self.TEST_TEXT),
             # Terminal access with different name in entity.
             spec_fac.create_equal_to('text_rc', self.TEST_TEXT),
             # Nested member access with different name in entity.
             spec_fac.create_equal_to('parent.text_rc', self.TEST_TEXT),
             # Nested collection access with different name in entity.
             spec_fac.create_equal_to('children.text_rc', self.TEST_TEXT),
             # Access with dotted entity name in rc attr declaration.
             spec_fac.create_equal_to('parent_text', self.TEST_TEXT),
             # Access to member.
             spec_fac.create_equal_to('parent',
                                      member.parent.get_entity()),
             ]
     expecteds = [('text', MyEntity.text.__eq__(self.TEST_TEXT)),
                  ('text_ent', MyEntity.text_ent.__eq__(self.TEST_TEXT)),
                  ('parent.text_ent',
                   MyEntity.parent.has(
                                 MyEntityParent.text_ent.__eq__(
                                                     self.TEST_TEXT))),
                  ('children.text_ent',
                   MyEntity.children.any(
                                 MyEntityChild.text_ent.__eq__(
                                                     self.TEST_TEXT))),
                  ('parent.text_ent',
                   MyEntity.parent.has(
                                 MyEntityParent.text_ent.__eq__(
                                                     self.TEST_TEXT))),
                  ('parent',
                   MyEntity.parent.__eq__(member.parent.get_entity())),
                  ]
     for spec, expected in zip(specs, expecteds):
         new_attr_name, expr = expected
         visitor = ResourceToEntityFilterSpecificationVisitor(mb_cls)
         spec.accept(visitor)
         new_spec = visitor.expression
         self.assert_equal(new_spec.attr_name, new_attr_name)
         visitor = SqlFilterSpecificationVisitor(MyEntity)
         new_spec.accept(visitor)
         self.assert_equal(str(visitor.expression), str(expr))
     invalid_spec = spec_fac.create_equal_to('foo', self.TEST_TEXT)
     vst = ResourceToEntityFilterSpecificationVisitor(mb_cls)
     self.assert_raises(AttributeError, invalid_spec.accept, vst)
예제 #6
0
class CompositeFilterSpecificationTestCase(TestCaseWithIni):
    def set_up(self):
        self.factory = FilterSpecificationFactory()
        self.candidate = object()
        self.always_true = AlwaysTrueFilterSpecification()
        self.always_false = AlwaysFalseFilterSpecification()

    def create_Conjunction_spec(self, left_spec, right_spec):
        return self.factory.create_conjunction(left_spec, right_spec)

    def create_disjunction_spec(self, left_spec, right_spec):
        return self.factory.create_disjunction(left_spec, right_spec)

    def test_basics(self):
        conj_spec = self.create_Conjunction_spec(self.always_true,
                                                 self.always_false)
        self.assert_equal(conj_spec, conj_spec)
        conj_spec_other_spec = self.create_Conjunction_spec(
            self.always_false, self.always_true)
        self.assert_not_equal(conj_spec, conj_spec_other_spec)
        str_str = '<%s left_spec:' % conj_spec.__class__.__name__
        self.assert_equal(str(conj_spec)[:len(str_str)], str_str)
예제 #7
0
class CompositeFilterSpecificationTestCase(TestCaseWithIni):

    def set_up(self):
        self.factory = FilterSpecificationFactory()
        self.candidate = object()
        self.always_true = AlwaysTrueFilterSpecification()
        self.always_false = AlwaysFalseFilterSpecification()

    def create_Conjunction_spec(self, left_spec, right_spec):
        return self.factory.create_conjunction(left_spec, right_spec)

    def create_disjunction_spec(self, left_spec, right_spec):
        return self.factory.create_disjunction(left_spec, right_spec)

    def test_basics(self):
        conj_spec = self.create_Conjunction_spec(self.always_true,
                                                self.always_false)
        self.assert_equal(conj_spec, conj_spec)
        conj_spec_other_spec = self.create_Conjunction_spec(self.always_false,
                                                           self.always_true)
        self.assert_not_equal(conj_spec, conj_spec_other_spec)
        str_str = '<%s left_spec:' % conj_spec.__class__.__name__
        self.assert_equal(str(conj_spec)[:len(str_str)], str_str)
예제 #8
0
 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)
예제 #9
0
 def _make_specs_factory(self):
     return FilterSpecificationFactory()
예제 #10
0
 def set_up(self):
     self.factory = FilterSpecificationFactory()
     self.candidate = object()
     self.always_true = AlwaysTrueFilterSpecification()
     self.always_false = AlwaysFalseFilterSpecification()
예제 #11
0
 def set_up(self):
     self.factory = FilterSpecificationFactory()
     self.candidate = object()
     self.always_true = AlwaysTrueFilterSpecification()
     self.always_false = AlwaysFalseFilterSpecification()
예제 #12
0
 def set_up(self):
     self.factory = FilterSpecificationFactory()
     self.candidate = self.create_candidate(text_attr=self.TEXT_VALUE,
                                            number_attr=self.NUMBER_VALUE,
                                            date_attr=self.DATE_VALUE,
                                            list_attr=self.LIST_VALUES)