예제 #1
0
 def test_class_paths(self, Document, Section, SubSection):
     assert getdotattr(Section, 'document') is Section.document
     assert (
         getdotattr(SubSection, 'section.document') is
         Section.document
     )
     assert getdotattr(Section, 'document.name') is Document.name
예제 #2
0
 def test_class_paths(self):
     assert getdotattr(self.Section, 'document') is self.Section.document
     assert (
         getdotattr(self.SubSection, 'section.document') is
         self.Section.document
     )
     assert getdotattr(self.Section, 'document.name') is self.Document.name
 def visit_field(self, dikt, instance, field, field_names=None, name=None):
     exposed_name = name or field.exposed_name
     extension = field.extras.get('extension')
     if extension is not None:
         try:
             extension_instance = instance.extension_instance(
                 extension,
                 self.session,
                 with_extensions=self.with_extensions)
             expose = extension_instance.expose
         except SkipExtension:
             return
     elif field.exposed_as is None:
         expose = lambda s, f, **kw: getdotattr(s, f.internal_name)
     elif isinstance(field.exposed_as, str):
         expose = lambda s, f, **kw: getdotattr(s, f.exposed_as)
     elif callable(field.exposed_as):
         expose = field.exposed_as
     else:
         raise TypeError(
             'Field exposed_as is expected to be a string or a function')
     exposed_value = expose(instance, field)
     dikt[exposed_name] = self.visit_value(instance,
                                           field,
                                           exposed_value,
                                           field_names=field_names)
예제 #4
0
 def test_class_paths(self):
     assert getdotattr(self.Section, 'document') is self.Section.document
     assert (
         getdotattr(self.SubSection, 'section.document') is
         self.Section.document
     )
     assert getdotattr(self.Section, 'document.name') is self.Document.name
예제 #5
0
    def test_with_instrumented_lists(self):
        document = self.Document(name=u'some document')
        section = self.Section(document=document)
        subsection = self.SubSection(section=section)
        subsubsection = self.SubSubSection(subsection=subsection)

        assert getdotattr(document, 'sections') == [section]
        assert getdotattr(document, 'sections.subsections') == [subsection]
        assert getdotattr(document, 'sections.subsections.subsubsections') == [
            subsubsection
        ]
예제 #6
0
    def test_with_instrumented_lists(self):
        document = self.Document(name=u'some document')
        section = self.Section(document=document)
        subsection = self.SubSection(section=section)
        subsubsection = self.SubSubSection(subsection=subsection)

        assert getdotattr(document, 'sections.subsections') == [
            [subsection]
        ]
        assert getdotattr(document, 'sections.subsections.subsubsections') == [
            [subsubsection]
        ]
예제 #7
0
    def gather_callback_args(self, obj, callbacks):
        session = sa.orm.object_session(obj)
        for callback in callbacks:
            backref = callback.backref

            root_objs = getdotattr(obj, backref) if backref else obj
            if root_objs:
                if not isinstance(root_objs, Iterable):
                    root_objs = [root_objs]

                for root_obj in root_objs:
                    objects = getdotattr(
                        root_obj, callback.fullpath,
                        lambda obj: obj not in session.deleted)

                    yield (root_obj, callback.func, objects)
예제 #8
0
    def test_simple_objects(self):
        document = self.Document(name=u'some document')
        section = self.Section(document=document)
        subsection = self.SubSection(section=section)

        assert getdotattr(subsection,
                          'section.document.name') == u'some document'
예제 #9
0
 def get_callback_args(self, root_obj, callback):
     session = sa.orm.object_session(root_obj)
     objects = getdotattr(root_obj, callback.fullpath,
                          lambda obj: obj not in session.deleted)
     path = str(callback.fullpath)
     if '.' in path or has_changes(root_obj, path):
         return (root_obj, callback.func, objects)
예제 #10
0
    def test_simple_objects(self):
        document = self.Document(name=u'some document')
        section = self.Section(document=document)
        subsection = self.SubSection(section=section)

        assert getdotattr(
            subsection,
            'section.document.name'
        ) == u'some document'
예제 #11
0
    def gather_callback_args(self, obj, callbacks):
        session = sa.orm.object_session(obj)
        for callback in callbacks:
            backref = callback.backref

            root_objs = getdotattr(obj, backref) if backref else obj
            if root_objs:
                if not isinstance(root_objs, Iterable):
                    root_objs = [root_objs]

                for root_obj in root_objs:
                    objects = getdotattr(
                        root_obj,
                        callback.fullpath,
                        lambda obj: obj not in session.deleted
                    )

                    yield (
                        root_obj,
                        callback.func,
                        objects
                    )
예제 #12
0
    def gather_callback_args(self, obj, callbacks):
        for callback in callbacks:
            backref = callback.backref

            root_objs = getdotattr(obj, backref) if backref else obj
            if root_objs:
                if not isinstance(root_objs, Iterable):
                    root_objs = [root_objs]

                for root_obj in root_objs:
                    if root_obj:
                        args = self.get_callback_args(root_obj, callback)
                        if args:
                            yield args
예제 #13
0
 def get_callback_args(self, root_obj, callback):
     session = sa.orm.object_session(root_obj)
     objects = getdotattr(
         root_obj,
         callback.fullpath,
         lambda obj: obj not in session.deleted
     )
     path = str(callback.fullpath)
     if '.' in path or has_changes(root_obj, path):
         return (
             root_obj,
             callback.func,
             objects
         )
예제 #14
0
    def gather_callback_args(self, obj, callbacks):
        for callback in callbacks:
            backref = callback.backref

            root_objs = getdotattr(obj, backref) if backref else obj
            if root_objs:
                if not isinstance(root_objs, Iterable):
                    root_objs = [root_objs]

                for root_obj in root_objs:
                    if root_obj:
                        args = self.get_callback_args(root_obj, callback)
                        if args:
                            yield args
예제 #15
0
 def test_class_paths(self, Document, Section, SubSection):
     assert getdotattr(Section, 'document') is Section.document
     assert (getdotattr(SubSection, 'section.document') is Section.document)
     assert getdotattr(Section, 'document.name') is Document.name