Пример #1
0
 def test_entity_attr(self):
     attr = get_domain_class_attribute(IMyEntity, "parent")
     my_parent = MyEntityParent(id=0)
     self._run_test(attr, my_parent, "child", ValueEqualToFilterSpecification, ValueEqualToFilterSpecification, 0)
     attr = get_domain_class_attribute(IMyEntityChild, "parent")
     my_child = MyEntityChild(id=1)
     self._run_test(attr, my_child, "children", ValueContainsFilterSpecification, ValueEqualToFilterSpecification, 1)
Пример #2
0
 def test_delete_cascade(self, class_entity_repo, monkeypatch):
     new_parent1 = MyEntityParent()
     new_ent1 = MyEntity()
     new_ent1.parent = new_parent1
     new_child1 = MyEntityChild()
     new_child1.parent = new_ent1
     child_rel_agg = self._make_rel_agg(class_entity_repo, new_ent1)
     child_rel_agg.add(new_child1)
     new_parent1.id = 1
     new_ent1.id = 1
     new_child1.id = 1
     agg = class_entity_repo.get_aggregate(IMyEntity)
     child_agg = class_entity_repo.get_aggregate(IMyEntityChild)
     assert len(list(child_agg.iterator())) == 1
     assert len(list(agg.iterator())) == 1
     assert new_ent1.children == [new_child1]
     assert new_child1.parent == new_ent1
     csc = DEFAULT_CASCADE | RELATION_OPERATIONS.REMOVE
     children_attr = get_domain_class_attribute(MyEntity, 'children')
     parent_attr = get_domain_class_attribute(MyEntityChild, 'parent')
     monkeypatch.setattr(children_attr, 'cascade', csc)
     monkeypatch.setattr(parent_attr, 'cascade', csc)
     child_rel_agg.remove(new_child1)
     assert new_ent1.children == []
     assert new_child1.parent is None
     assert len(list(child_agg.iterator())) == 0
     if self.__class__.__name__.startswith('TestMemory'):
         # FIXME: Transparent modification of RDB mapper cascades
         #        does not work yet.
         assert len(list(agg.iterator())) == 0
     assert len(list(child_rel_agg.iterator())) == 0
Пример #3
0
 def _test_accessors(self, obj):
     names = list(get_domain_class_attribute_names(obj))
     self.assert_equal(list(names),
                       ['id', 'parent', 'children', 'text', 'text_ent',
                        'number', 'date_time', 'parent.text_ent'])
     self.assert_equal(list(get_domain_class_attributes(obj).keys()),
                       names)
     term_attr_name = 'number'
     term_attr = get_domain_class_attribute(obj, term_attr_name)
     self.assert_equal(term_attr.entity_attr, term_attr_name)
     self.assert_true(
                 is_domain_class_terminal_attribute(obj, term_attr_name))
     ent_attr_name = 'parent'
     ent_attr = get_domain_class_attribute(obj, ent_attr_name)
     self.assert_equal(ent_attr.entity_attr, ent_attr_name)
     self.assert_true(
                 is_domain_class_member_attribute(obj, ent_attr_name))
     self.assert_true(
                 is_domain_class_domain_attribute(obj, ent_attr_name))
     agg_attr_name = 'children'
     agg_attr = get_domain_class_attribute(obj, agg_attr_name)
     self.assert_equal(agg_attr.entity_attr, agg_attr_name)
     self.assert_true(
                 is_domain_class_collection_attribute(obj, agg_attr_name))
     self.assert_true(
                 is_domain_class_domain_attribute(obj, agg_attr_name))
     for attr in get_domain_class_terminal_attribute_iterator(obj):
         self.assert_equal(attr.kind, RESOURCE_ATTRIBUTE_KINDS.TERMINAL)
     for attr in get_domain_class_member_attribute_iterator(obj):
         self.assert_equal(attr.kind, RESOURCE_ATTRIBUTE_KINDS.MEMBER)
     for attr in get_domain_class_collection_attribute_iterator(obj):
         self.assert_equal(attr.kind, RESOURCE_ATTRIBUTE_KINDS.COLLECTION)
     for attr in get_domain_class_relationship_attribute_iterator(obj):
         self.assert_true(attr.kind in (RESOURCE_ATTRIBUTE_KINDS.MEMBER,
                                        RESOURCE_ATTRIBUTE_KINDS.COLLECTION))
Пример #4
0
 def test_entity_attr(self):
     attr = get_domain_class_attribute(IMyEntity, 'parent')
     my_parent = MyEntityParent(id=0)
     self._run_test(attr, my_parent, 'child',
                    ValueEqualToFilterSpecification,
                    ValueEqualToFilterSpecification, 0)
     attr = get_domain_class_attribute(IMyEntityChild, 'parent')
     my_child = MyEntityChild(id=1)
     self._run_test(attr, my_child, 'children',
                    ValueContainsFilterSpecification,
                    ValueEqualToFilterSpecification, 1)
Пример #5
0
 def _make_rel_agg(self, class_entity_repo, entity, attr_name=None):
     if attr_name is None:
         attr_name = 'children'
     attr = get_domain_class_attribute(entity, attr_name)
     rel = attr.make_relationship(entity)
     child_agg = class_entity_repo.get_aggregate(attr.attr_type)
     return child_agg.make_relationship_aggregate(rel)
Пример #6
0
 def test_member_representer(self, member_representer, collection,
                             monkeypatch):
     mb = next(iter(collection))
     rpr_str = member_representer.to_string(mb)
     mb_reloaded = member_representer.from_string(rpr_str)
     assert mb.id == mb_reloaded.id
     # Check unicode handling.
     mb.text = u'h\xfclfe'
     bytes_val = bytes_(mb.text, encoding=member_representer.encoding)
     attr = get_domain_class_attribute(MyEntity, 'text')
     def test(member, exp_val):
         rpr_text = member_representer.to_string(member)
         assert isinstance(rpr_text, text_type)
         rpr_bytes = member_representer.to_bytes(member)
         assert isinstance(rpr_bytes, binary_type)
         mb_reloaded_str = member_representer.from_string(rpr_text)
         assert isinstance(mb_reloaded_str.text, attr.attr_type)
         assert mb_reloaded_str.text == exp_val
         mb_reloaded_bytes = member_representer.from_bytes(rpr_bytes)
         assert isinstance(mb_reloaded_bytes.text, attr.attr_type)
         assert mb_reloaded_bytes.text == exp_val
         #
         de = member_representer.resource_to_data(member)
         assert isinstance(de, MemberDataElement)
         rpr_data_bytes = member_representer.data_to_bytes(de)
         assert isinstance(rpr_data_bytes, binary_type)
     # In PY3, the attr type will be text, in PY2 bytes.
     if not issubclass(attr.attr_type, binary_type):
         monkeypatch.setattr(attr, 'attr_type', binary_type)
     test(mb, bytes_val)
     # In PY3, the attr type will be text, in PY2 bytes.
     if not issubclass(attr.attr_type, text_type):
         monkeypatch.setattr(attr, 'attr_type', text_type)
     test(mb, mb.text)
Пример #7
0
 def test_traverse_with_add(self):
     mock_vst = MagicMock()
     ent = create_entity(entity_id=None)
     trv = SourceTargetDataTreeTraverser.make_traverser(
         ent, None, RELATION_OPERATIONS.ADD)
     trv.run(mock_vst)
     parent_attr = get_domain_class_attribute(MyEntity, 'parent')
     children_attr = get_domain_class_attribute(MyEntity, 'children')
     grandchildren_attr = get_domain_class_attribute(
         MyEntityChild, 'children')
     # Check the visiting sequence and args (depth first).
     for idx, (meth_name, attr) \
         in enumerate([('visit', parent_attr),
                       ('visit', grandchildren_attr),
                       ('visit', children_attr),
                       ]):
         meth_call = mock_vst.method_calls[idx + 1]
         self.assert_equal(meth_call[0], meth_name)
         self.assert_equal(meth_call[1][1], attr)
         prx = meth_call[1][2]
         self.assert_true(isinstance(prx, DomainDataTraversalProxy))
         self.assert_true(isinstance(prx.get_entity(), Entity))
         self.assert_is_none(meth_call[1][3])
Пример #8
0
 def test_update_cascade(self, class_entity_repo, monkeypatch):
     csc = DEFAULT_CASCADE & ~RELATION_OPERATIONS.UPDATE
     child_agg = class_entity_repo.get_aggregate(IMyEntityChild)
     new_child = self._make_child(child_agg)
     child_rel_agg = self._make_rel_agg(class_entity_repo,
                                        new_child.parent)
     children_attr = get_domain_class_attribute(MyEntity, 'children')
     monkeypatch.setattr(children_attr, 'cascade', csc)
     upd_child = MyEntityChild(id=0)
     txt = 'FROBNIC'
     upd_child.text = txt
     child_rel_agg.update(upd_child)
     assert new_child.text != txt
     assert not new_child.parent is None
Пример #9
0
 def test_traverse_with_add(self):
     mock_vst = MagicMock()
     ent = create_entity(entity_id=None)
     trv = SourceTargetDataTreeTraverser.make_traverser(
                                                 ent, None,
                                                 RELATION_OPERATIONS.ADD)
     trv.run(mock_vst)
     parent_attr = get_domain_class_attribute(MyEntity, 'parent')
     children_attr = get_domain_class_attribute(MyEntity, 'children')
     grandchildren_attr = get_domain_class_attribute(MyEntityChild,
                                                     'children')
     # Check the visiting sequence and args (depth first).
     for idx, (meth_name, attr) \
         in enumerate([('visit', parent_attr),
                       ('visit', grandchildren_attr),
                       ('visit', children_attr),
                       ]):
         meth_call = mock_vst.method_calls[idx + 1]
         self.assert_equal(meth_call[0], meth_name)
         self.assert_equal(meth_call[1][1], attr)
         prx = meth_call[1][2]
         self.assert_true(isinstance(prx, DomainDataTraversalProxy))
         self.assert_true(isinstance(prx.get_entity(), Entity))
         self.assert_is_none(meth_call[1][3])
Пример #10
0
    def test_member_representer(self, member_representer, collection,
                                monkeypatch):
        mb = next(iter(collection))
        rpr_str = member_representer.to_string(mb)
        mb_reloaded = member_representer.from_string(rpr_str)
        assert mb.id == mb_reloaded.id
        # Check unicode handling.
        mb.text = u'h\xfclfe'
        bytes_val = bytes_(mb.text, encoding=member_representer.encoding)
        attr = get_domain_class_attribute(MyEntity, 'text')

        def test(member, exp_val):
            rpr_text = member_representer.to_string(member)
            assert isinstance(rpr_text, text_type)
            rpr_bytes = member_representer.to_bytes(member)
            assert isinstance(rpr_bytes, binary_type)
            mb_reloaded_str = member_representer.from_string(rpr_text)
            assert isinstance(mb_reloaded_str.text, attr.attr_type)
            assert mb_reloaded_str.text == exp_val
            mb_reloaded_bytes = member_representer.from_bytes(rpr_bytes)
            assert isinstance(mb_reloaded_bytes.text, attr.attr_type)
            assert mb_reloaded_bytes.text == exp_val
            #
            de = member_representer.resource_to_data(member)
            assert isinstance(de, MemberDataElement)
            rpr_data_bytes = member_representer.data_to_bytes(de)
            assert isinstance(rpr_data_bytes, binary_type)

        # In PY3, the attr type will be text, in PY2 bytes.
        if not issubclass(attr.attr_type, binary_type):
            monkeypatch.setattr(attr, 'attr_type', binary_type)
        test(mb, bytes_val)
        # In PY3, the attr type will be text, in PY2 bytes.
        if not issubclass(attr.attr_type, text_type):
            monkeypatch.setattr(attr, 'attr_type', text_type)
        test(mb, mb.text)
Пример #11
0
 def test_string_representation(self):
     attr = get_domain_class_attribute(IMyEntity, "children")
     my_child = MyEntityChild(id=0)
     rel = attr.make_relationship(my_child)
     self.assert_true("<->" in str(rel))
Пример #12
0
 def test_aggregate_attr(self):
     attr = get_domain_class_attribute(IMyEntity, "children")
     my_child = MyEntityChild(id=0)
     self._run_test(
         attr, my_child, "parent", ValueEqualToFilterSpecification, ValueContainedFilterSpecification, [0]
     )
Пример #13
0
 def test_string_representation(self):
     attr = get_domain_class_attribute(IMyEntity, 'children')
     my_child = MyEntityChild(id=0)
     rel = attr.make_relationship(my_child)
     self.assert_true('<->' in str(rel))
Пример #14
0
 def test_aggregate_attr(self):
     attr = get_domain_class_attribute(IMyEntity, 'children')
     my_child = MyEntityChild(id=0)
     self._run_test(attr, my_child, 'parent',
                    ValueEqualToFilterSpecification,
                    ValueContainedFilterSpecification, [0])