1. Lynn Rees
  2. graphalchemy

Commits

Lynn Rees  committed 7444290

- tweak

  • Participants
  • Parent commits 88847f2
  • Branches pu

Comments (0)

Files changed (13)

File graphalchemy/direct/elements.py

View file
 # -*- coding: utf-8 -*-
 '''manager element models'''
 
+from stuf.utils import lazy
 from graphalchemy.core import octopus, app
-from graphalchemy.mixins.elements import LinkMixin, NodeMixin, ThingMixin
+from graphalchemy.mixins.elements import NodeMixin, ElementMixin
+
 
 __all__ = ('Link', 'Node')
 # settings
 conf = octopus.G
 
 
-class Thing(ThingMixin, octopus.process.Thing):
+class Thing(ElementMixin, octopus.process.Thing):
 
     '''graph object'''
 
         return Link
 
 
-class Link(LinkMixin, Thing):
+class Link(Thing):
 
     '''graph link object'''
 
+    def __init__(self, element=None, link=None, this=None, that=None, **kw):
+        '''
+        init
+
+        @param element: link element (default: None)
+        @param link: link kind name (default: None)
+        @param this: one node in a link (default: None)
+        @param that: another node in a link (default: None)
+        '''
+        super(Link, self).__init__(element, **kw)
+        # link kind name
+        self.link = link
+        # one end
+        self.that = that if that is not None else self._node()(element.end)
+        # the other end
+        self.this = this if this is not None else self._node()(element.start)
+
+    def __repr__(self):
+        return '{0}: {1}'.format(self.kind, super(Link, self).__repr__())
+
+    @lazy
+    def _p(self):
+        return self.session.links
+
+    @lazy
+    def end(self):
+        '''ending node of link'''
+        return self.that if self.direction == 'incoming' else self.this
+
+    @lazy
+    def kind(self):
+        '''kind of link'''
+        return self.r.kind(self.source)
+
+    @lazy
+    def start(self):
+        '''starting node of link'''
+        return self.this if self.direction == 'incoming' else self.that
+
     @staticmethod
     def _node():
         '''node class'''
         return Node
 
+    def deep_dump(self):
+        '''deep dump link and both nodes'''
+        return self.copy(
+            end=self.end.deep_dump(),
+            id=self.id,
+            kind=self.kind,
+            start=self.start.deep_dump(),
+        )
+
+    def dump(self):
+        '''dump link and both nodes'''
+        return self.copy(
+            end=self.end.dump(),
+            id=self.id,
+            kind=self.kind,
+            start=self.start.dump(),
+        )
+
 
 class Node(NodeMixin, Thing):
 

File graphalchemy/direct/workers.py

View file
 '''graph managers'''
 
 from appspace import AppLookupError
-from graphalchemy.mixins.writers import WriterMixin
-from graphalchemy.mixins.readers import ReaderMixin
+
 from graphalchemy.core import octopus, app, factory, defer
+from graphalchemy.mixins.workers import WriterMixin, ReaderMixin
 
 __all__ = ('Links', 'Nodes')
 # settings
 db = conf.key.db
 
 
-class Direct(WriterMixin, ReaderMixin, octopus.process.Worker):
+class _Direct(WriterMixin, ReaderMixin, octopus.process.Worker):
 
     '''direct graph database interface'''
 
             yield model(element)
 
 
-class Links(Direct):
+class Links(_Direct):
 
     '''direct graph link interface'''
 
             yield model(element)
 
 
-class Nodes(Direct):
+class Nodes(_Direct):
 
     '''direct graph node interface'''
 

File graphalchemy/mixins/collections.py

View file
 __all__ = ('LinksMixin', 'NodesMixin')
 
 
-class CollectionMixin(octopus.context.thing):
+class _CollectionMixin(octopus.context.Thing):
 
     '''element collection'''
 
         @param this: graph element (default: None)
         @param model: graph model (default: None)
         '''
-        super(CollectionMixin, self).__init__()
+        super(_CollectionMixin, self).__init__()
         self._this = this
         self._model = model
         self.direction = kw.get('direction', None)
         return [n.dump() for n in self]
 
 
-class LinksMixin(CollectionMixin):
+class LinksMixin(_CollectionMixin):
 
     '''links collection'''
 
         return self._this.l.walked(self._this, self.direction)
 
 
-class NodesMixin(CollectionMixin):
+class NodesMixin(_CollectionMixin):
 
     '''nodes collection'''
 

File graphalchemy/mixins/collectors.py

View file
 __all__ = ('LinksMixin', 'NodesMixin')
 
 
-class CollectorsMixin(octopus.context.thing):
+class _CollectorsMixin(octopus.context.thing):
 
     '''element collections collector'''
 
 
         @param this: graph object (default: None)
         '''
-        super(CollectorsMixin, self).__init__()
+        super(_CollectorsMixin, self).__init__()
         self._this = this
         self._model = model
 
         return self._collection(self._this, self._model)
 
 
-class LinksMixin(CollectorsMixin):
+class LinksMixin(_CollectorsMixin):
 
     '''links collections collector'''
 
         return self._collection(self._this, self._model, direction='outgoing')
 
 
-class NodesMixin(CollectorsMixin):
+class NodesMixin(_CollectorsMixin):
 
     '''nodes collection collector'''
 

File graphalchemy/mixins/elements.py

View file
 
 from stuf.utils import both, getcls, lazy, clsname
 
-from graphalchemy.core import octopus
+__all__ = ('ElementMixin', 'NodesMixin')
 
-__all__ = ('LinksMixin', 'NodesMixin')
 
-# settings
-conf = getattr(octopus, 'S')
-
-
-class ThingMixin(object):
+class ElementMixin(object):
 
     '''graph element'''
 
         '''
         # element direction
         self.direction = kw.pop('direction', 'outgoing')
-        super(ThingMixin, self).__init__(element, **kw)
+        super(ElementMixin, self).__init__(element, **kw)
 
-    @property
+    @lazy
     def id(self):
         '''graph element id'''
         return self._p.id(self.source)
 
         @param this: this element
         '''
-        return self._p.properties(this)
+        return self.r.properties(this)
 
     def _refresh(self):
         '''refresh original'''
-        super(ThingMixin, self).sync()
+        super(ElementMixin, self).sync()
         # reset links collector
         self.links.reset()
 
         self._p.index_one(index, key, value, self)
 
 
-class LinkMixin(object):
-
-    '''link element'''
-
-    def __init__(self, element=None, link=None, this=None, that=None, **kw):
-        '''
-        init
-
-        @param element: link element (default: None)
-        @param link: link kind name (default: None)
-        @param this: one node in a link (default: None)
-        @param that: another node in a link (default: None)
-        '''
-        super(LinkMixin, self).__init__(element, **kw)
-        # link kind name
-        self.link = link
-        # one end
-        self.that = that if that is not None else self._node()(element.end)
-        # the other end
-        self.this = this if this is not None else self._node()(element.start)
-
-    def __repr__(self):
-        return '{0}: {1}'.format(self.kind, super(LinkMixin, self).__repr__())
-
-    @lazy
-    def end(self):
-        '''ending node of link'''
-        return self.that if self.direction == 'incoming' else self.this
-
-    @property
-    def kind(self):
-        '''kind of link'''
-        return self.session.links.kind(self.source)
-
-    @lazy
-    def start(self):
-        '''starting node of link'''
-        return self.this if self.direction == 'incoming' else self.that
-
-    def deep_dump(self):
-        '''deep dump link and both nodes'''
-        return self.copy(
-            end=self.end.deep_dump(),
-            id=self.id,
-            kind=self.kind,
-            start=self.start.deep_dump(),
-        )
-
-    def dump(self):
-        '''dump link and both nodes'''
-        return self.copy(
-            end=self.end.dump(),
-            id=self.id,
-            kind=self.kind,
-            start=self.start.dump(),
-        )
-
-
 class NodeMixin(object):
 
     '''node element'''
         )
 
     @lazy
+    def _p(self):
+        return self.session.nodes
+
+    @lazy
     def nodes(self):
         '''connector to all nodes linked to this node'''
         return self._nodes(self, getcls(self))

File graphalchemy/models/core.py

-# -*- coding: utf-8 -*-
-'''graph model manager'''
-
-from itertools import count
-from functools import partial
-
-from markupsafe import escape
-
-from graphalchemy.errors import ReversionError
-from graphalchemy.mixins.writers import WriterMixin
-from graphalchemy.core import octopus, app, factory, defer
-
-__all__ = ['Nodes']
-# settings
-conf = octopus.G
-backends = conf.backends
-db = conf.key.db
-
-
-class Nodes(WriterMixin, octopus.workflow.worker):
-
-    '''graph node writer'''
-
-    # graph source
-    _db = app(conf.key.backend, conf.userspace)
-    # model finder
-    _finder = app(conf.model.finder.node, conf.appspace)
-    # model query
-    _query = app(conf.model.node.reader, conf.appspace)
-    # model user
-    _using = app(conf.model.node.writer, conf.appspace)
-    # direct node reader
-    r = factory(conf.read.node, backends, db)
-    # direct node writer
-    w = factory(conf.write.node, backends, db)
-
-    def _autoslug(self, properties):
-        '''
-        auto slug an element
-
-        @param properties: graph element properties
-        '''
-        C = self.model.C
-        slug_from = C.slug_from
-        if not slug_from:
-            return
-        slug = tmpslug = self.Q.slugify(properties[slug_from])
-        slug_field = C.slug_field
-        # loop until unique slug is located
-        filter_by = self.r.filter_by
-        index = C.index
-        for cnt in count(1):
-            prev = filter_by(index, slug_field, tmpslug)
-            if not prev:
-                break
-            tmpslug = '{slug}-{count}'.format(slug=slug, count=cnt)
-        # add slug
-        properties[slug_field] = tmpslug
-
-    @defer
-    def _create(self, data):
-        '''
-        create a new graph node
-
-        @param data: data
-        '''
-        model = self.model
-        C = model.C
-        data.update(_created=self.now(), _model=C.name, _uuid=self.Q.uuid())
-        # number of versions to maintain
-        if C.versioned:
-            data['_versions'] = 0
-        self._preprocess(data)
-        thing = self.w.create(
-            data,
-            C.reference_link,
-            model.nodes.reference(),
-            partial(self._postprocess, model=model),
-        )
-        thing._refresh()
-
-    def _prepare(self, this):
-        # snapshot if flag set
-        if this.C.versioned:
-            self._snapshot(this)
-        super(Nodes, self)._prepare(this)
-
-    @defer
-    def _update(self, this, data):
-        '''
-        update a graph element's properties
-
-        @param this: graph object
-        @param data: data
-        '''
-        self._preprocess(data)
-        self.w.update(this, data, partial(self._postprocess, model=self.model))
-        this._refresh()
-
-    def _preprocess(self, this):
-        '''
-        pre-process graph element
-
-        @param this: graph object
-        '''
-        esc = escape
-        for k in self.model.C.escaped:
-            this[k] = esc(this[k])
-        this['_modified'] = self.now()
-        # slug field
-        self._autoslug(this)
-
-    def _postprocess(self, this):
-        '''
-        postprocess graph node
-
-        @param this: graph object
-        '''
-        this = self.model(this)
-        C = self.model.C
-        index = C.index
-        # index created date
-        index_one = self.index_one
-        if index:
-            index_one(index, 'created', self.now(), this)
-        # index any listed properties
-        indexed = C.indexed
-        if indexed:
-            self.index_many(index, this, indexed)
-        # add a slug if present
-        slug_from = C.slug_from
-        if slug_from:
-            index_one(index, slug_from, getattr(this, slug_from), this)
-        # index properties that support full text search
-        fts_indexed = C.fts_indexed
-        if fts_indexed:
-            self.index_many(C.fts_index, this, fts_indexed)
-        return this
-
-#    @defer
-#    def _versioning(self, diff, thing):
-#        '''snapshot node'''
-#        diff.update(_hash=thing.hash_diff(), _version=thing._version())
-#        # create new snapshot
-#        version = self._snapshot(thing, diff)
-#        thing._refresh()
-#        return version
-
-    @defer
-    def _revert(self, thing, version):
-        '''
-        change to another snapshot of this node
-
-        @param snapshot: id of previous snapshot of this node
-        '''
-        if thing.C.versioned:
-            self._snapshot(thing)
-            self.n.revert(self, version)
-            self._snapshot(thing)
-        raise ReversionError('could not revert snapshot {0}'.format(version))
-
-    def _snapshot(self, thing):
-        '''track changes for this node'''
-        diff = thing.diff()
-        # if there is a change to nodes properties...
-        return self._versioning(diff, thing) if diff else {}
-
-    def query(self, model):
-        '''
-        query using a graph model
-
-        @param model: graph model
-        '''
-        return self._query(model)
-
-    def using(self, model):
-        '''
-        use graph model
-
-        @param model: graph model
-        '''
-        return self._using(model)

File graphalchemy/models/elements.py

View file
 
 
 from graphalchemy.core import octopus, app
-from graphalchemy.mixins.elements import NodeMixin, ThingMixin
+from graphalchemy.mixins.elements import NodeMixin, ElementMixin
 
 __all__ = ['Node']
 # settings
 db = conf.key.db
 
 
-class Node(NodeMixin, ThingMixin, octopus.workflow.Thing):
+class Node(NodeMixin, ElementMixin, octopus.workflow.Thing):
 
     '''node model'''
 

File graphalchemy/models/properties.py

-# -*- coding: utf-8 -*-
-'''graph model properties'''
-
-import sys
-
-from spine.traits import Trait
-from spine.bases.keys import NoDefault
-from spine.traits import CheckedUnicode, Bool, Float as Ft, Integer, Unicode
-
-__all__ = (
-    'BooleanField', 'CharField', 'FloatField', 'IntegerField', 'StringField',
-    'TextField',
-)
-
-
-class PropertyMixin(Trait):
-
-    metadata = dict(property=True)
-
-    def __init__(self, initial=NoDefault, **kw):
-        kw.update(dict(property=True, indexed=kw.get('indexed', False)))
-        super(PropertyMixin, self).__init__(initial, **kw)
-
-
-class StringMixin(PropertyMixin):
-
-    def __init__(self, initial=NoDefault, **kw):
-        kw.update(dict(
-            escaped=kw.get('escaped', False),
-            slug_from=kw.get('slug_from', False)
-        ))
-        super(StringMixin, self).__init__(initial, **kw)
-
-
-class BooleanField(PropertyMixin, Bool):
-
-    '''boolean field'''
-
-
-class CharField(StringMixin, CheckedUnicode):
-
-    '''checked string field'''
-
-    def __init__(self, value='', minlen=0, maxlen=sys.maxsize, regex='', **kw):
-        super(CharField, self).__init__(value, minlen, maxlen, regex, **kw)
-
-
-class FloatField(PropertyMixin, Ft):
-
-    '''float field'''
-
-
-class IntegerField(PropertyMixin, Integer):
-
-    '''integer field'''
-
-
-class StringField(StringMixin, Unicode):
-
-    '''string field'''
-
-
-class TextField(StringField):
-
-    '''string that can be full text searched'''
-
-    def __init__(self, initial=NoDefault, **kw):
-        super(TextField, self).__init__(initial, **kw)
-        kw.update(dict(full_text=kw.get('full_text', False)))

File graphalchemy/models/workers.py

View file
+# -*- coding: utf-8 -*-
+'''graph model manager'''
+
+from itertools import count
+from functools import partial
+
+from markupsafe import escape
+
+from graphalchemy.mixins.workers import WriterMixin
+from graphalchemy.core import octopus, app, factory, defer
+
+__all__ = ['Nodes']
+# settings
+conf = octopus.G
+backends = conf.backends
+db = conf.key.db
+
+
+class Nodes(WriterMixin, octopus.workflow.worker):
+
+    '''graph node worker'''
+
+    # graph source
+    _db = app(conf.key.backend, conf.userspace)
+    # model finder
+    _finder = app(conf.model.finder.node, conf.appspace)
+    # model query
+    _query = app(conf.model.node.reader, conf.appspace)
+    # model user
+    _using = app(conf.model.node.writer, conf.appspace)
+    # direct node reader
+    r = factory(conf.read.node, backends, db)
+    # direct node writer
+    w = factory(conf.write.node, backends, db)
+
+    def _autoslug(self, properties):
+        '''
+        auto slug an element
+
+        @param properties: graph element properties
+        '''
+        C = self.model.C
+        slug_from = C.slug_from
+        if not slug_from:
+            return
+        slug = tmpslug = self.Q.slugify(properties[slug_from])
+        slug_field = C.slug_field
+        # loop until unique slug is located
+        filter_by = self.r.filter_by
+        index = C.index
+        for cnt in count(1):
+            prev = filter_by(index, slug_field, tmpslug)
+            if not prev:
+                break
+            tmpslug = '{slug}-{count}'.format(slug=slug, count=cnt)
+        # add slug
+        properties[slug_field] = tmpslug
+
+    @defer
+    def _create(self, data):
+        '''
+        create a new graph node
+
+        @param data: data
+        '''
+        model = self.model
+        C = model.C
+        data.update(_created=self.now(), _model=C.name, _uuid=self.Q.uuid())
+        # number of versions to maintain
+        if C.versioned:
+            data['_versions'] = 0
+        self._preprocess(data)
+        thing = self.w.create(
+            data,
+            C.reference_link,
+            model.nodes.reference(),
+            partial(self._postprocess, model=model),
+        )
+        thing._refresh()
+
+    def _prepare(self, this):
+        # snapshot if flag set
+        if this.C.versioned:
+            self._snapshot(this)
+        super(Nodes, self)._prepare(this)
+
+    @defer
+    def _update(self, this, data):
+        '''
+        update a graph element's properties
+
+        @param this: graph object
+        @param data: data
+        '''
+        self._preprocess(data)
+        self.w.update(this, data, partial(self._postprocess, model=self.model))
+        this._refresh()
+
+    def _preprocess(self, this):
+        '''
+        pre-process graph element
+
+        @param this: graph object
+        '''
+        esc = escape
+        for k in self.model.C.escaped:
+            this[k] = esc(this[k])
+        this['_modified'] = self.now()
+        # slug field
+        self._autoslug(this)
+
+    def _postprocess(self, this):
+        '''
+        postprocess graph node
+
+        @param this: graph object
+        '''
+        this = self.model(this)
+        C = self.model.C
+        index = C.index
+        # index created date
+        index_one = self.index_one
+        if index:
+            index_one(index, 'created', self.now(), this)
+        # index any listed properties
+        indexed = C.indexed
+        if indexed:
+            self.index_many(index, this, indexed)
+        # add a slug if present
+        slug_from = C.slug_from
+        if slug_from:
+            index_one(index, slug_from, getattr(this, slug_from), this)
+        # index properties that support full text search
+        fts_indexed = C.fts_indexed
+        if fts_indexed:
+            self.index_many(C.fts_index, this, fts_indexed)
+        return this
+
+    def query(self, model):
+        '''
+        query using a graph model
+
+        @param model: graph model
+        '''
+        return self._query(model)
+
+    def using(self, model):
+        '''
+        use graph model
+
+        @param model: graph model
+        '''
+        return self._using(model)

File graphalchemy/models/writers.py

View file
 # -*- coding: utf-8 -*-
 '''graph model writers'''
 
+from graphalchemy.errors import ReversionError
 from graphalchemy.mixins.workers import WriterMixin
-from graphalchemy.core import octopus, app, factory
+from graphalchemy.core import octopus, app, factory, defer
 
 __all__ = ['Nodes']
 # settings
         super(Nodes, self).__init__()
         self.model = model
 
+    @defer
     def anchor(self, **kw):
         '''create an anchor node'''
         model = self.model
             callback,
         )
 
-    def fork(self, this):
+    @defer
+    def fork(self, thing):
         '''
         clone a graph node
 
-        @param this: graph object
+        @param thing: graph object
         '''
         created = self.now()
         model = self.model
             index_one = self.index_one
             def callback(fork): #@IgnorePep8
                 # add hash
-                fork['_hash'] = this.hash_current()
+                fork['_hash'] = thing.hash_current()
                 # refer back to original
-                fork['_forked'] = this.id
+                fork['_forked'] = thing.id
                 fork = model(fork)
                 # index fork
-                index_one(index, S.label, this.id, fork)
+                index_one(index, S.label, thing.id, fork)
                 # index forked time
                 index_one(index, S.created, created, fork)
                 return fork
         else:
             callback = None
-        return self.w.clone(this, C.fork_link, callback, _created=created)
+        return self.w.clone(thing, C.fork_link, callback, _created=created)
 
+    @defer
     def refer(self, **kw):
         '''create a reference node'''
         finder = self._finder
             data, C.reference_link, finder(element=root)(root), callback,
         )
 
-    def revert(self, this, snapshot):
+    @defer
+    def revert(self, thing, snapshot):
         '''
         change a graph node to an older snapshot
 
-        @param this: graph object
+        @param thing: graph object
         @param snapshot: snapshot to revert to
         '''
-        self.update(
-            this, self.r.filter_by(self.S.snapshot.label, snapshot).properties,
-        )
+        if thing.C.versioned:
+            self.snapshot(thing)
+            self.update(
+                thing,
+                self.r.filter_by(self.S.snapshot.label, snapshot).properties,
+            )
+            self.snapshot(thing)
+        raise ReversionError('could not revert snapshot {0}'.format(snapshot))
 
-    def snapshot(self, this, diff):
+    @defer
+    def snapshot(self, thing):
         '''
         capture changes between different versions of a graph node
 
-        @param this: graph object
+        @param thing: graph object
         @param diff: differences between two versions of a graph node
         '''
+        diff = thing.diff()
         created = self.now()
         # populate diff
-        diff.update(_created=created, _versioned=this.id)
+        diff.update(
+            _created=created,
+            _versioned=thing.id,
+            _hash=thing.hash_diff(),
+            _version=thing._version()
+        )
         S = self.S.version
         model = self.model
         C = model.C
             def callback(snapshot): #@IgnorePep8
                 snapshot = model(snapshot)
                 # index snapshot with parent snapshot
-                index_one(index, S.reference, this.id, snapshot)
+                index_one(index, S.reference, thing.id, snapshot)
                 # index snapshot as snapshot
                 index_one(index, S.label, snapshot.id, snapshot)
                 # index versioned time
         else:
             callback = None
         # create snapshot and link back to previous snapshot
+        thing._refresh()
         return self.w.create(
-            diff, C.version_link, this, callback, _created=created,
+            diff, C.version_link, thing, callback, _created=created,
         )

File graphalchemy/properties.py

View file
+# -*- coding: utf-8 -*-
+'''graph model properties'''
+
+import sys
+
+from spine.traits import Trait
+from spine.bases.keys import NoDefault
+from spine.traits import CheckedUnicode, Bool, Float as Ft, Integer, Unicode
+
+__all__ = (
+    'BooleanField', 'CharField', 'FloatField', 'IntegerField', 'StringField',
+    'TextField',
+)
+
+
+class PropertyMixin(Trait):
+
+    metadata = dict(property=True)
+
+    def __init__(self, initial=NoDefault, **kw):
+        kw.update(dict(property=True, indexed=kw.get('indexed', False)))
+        super(PropertyMixin, self).__init__(initial, **kw)
+
+
+class StringMixin(PropertyMixin):
+
+    def __init__(self, initial=NoDefault, **kw):
+        kw.update(dict(
+            escaped=kw.get('escaped', False),
+            slug_from=kw.get('slug_from', False)
+        ))
+        super(StringMixin, self).__init__(initial, **kw)
+
+
+class BooleanField(PropertyMixin, Bool):
+
+    '''boolean field'''
+
+
+class CharField(StringMixin, CheckedUnicode):
+
+    '''checked string field'''
+
+    def __init__(self, value='', minlen=0, maxlen=sys.maxsize, regex='', **kw):
+        super(CharField, self).__init__(value, minlen, maxlen, regex, **kw)
+
+
+class FloatField(PropertyMixin, Ft):
+
+    '''float field'''
+
+
+class IntegerField(PropertyMixin, Integer):
+
+    '''integer field'''
+
+
+class StringField(StringMixin, Unicode):
+
+    '''string field'''
+
+
+class TextField(StringField):
+
+    '''string that can be full text searched'''
+
+    def __init__(self, initial=NoDefault, **kw):
+        super(TextField, self).__init__(initial, **kw)
+        kw.update(dict(full_text=kw.get('full_text', False)))

File graphalchemy/tests/test_db.py

View file
             pass
     graph.pipe('anyway', cleanup)
     with graph.session as session:
-        gn = session.nodes
+        gn = session.nodes.direct
         gn.index('roots')
         gn.index('questions')
         gn.index('question_text', fts=True)
         gn.index('cons')
         gn.index('con_text', fts=True)
         gn.index('tags')
-        root = gn.root()
+        root = session.nodes.root()
         question = gn.create(text='question reference node')
         question.index_under('roots', 'reference', 'question')
         question.link('QUESTION_REFERENCE_FOR', root)

File graphalchemy/tests/test_models.py

View file
 from graphalchemy.graphs import Graph
 from graphalchemy.models.elements import Node
 from graphalchemy.models.collectors import In, Out
-from graphalchemy.models.properties import IntegerField, TextField
+from graphalchemy.properties import IntegerField, TextField
 
 
 class Tag(Node):
         Session.nodes.refer(Con, user=1)
         Session.nodes.refer(Tag, user=1)
         tag_1 = Tag(_status=1, text='wicked problem', user=1)
-        Session.add(tag_1)
+        Session.nodes.add(tag_1)
         tag_1.index_under('tags', 'name', 'wicked problem')
         tag_2 = Tag(text='avoid', user=1, _status=1)
-        Session.add(tag_2)
+        Session.nodes.add(tag_2)
         tag_2.index_under('tags', 'name', 'avoid')
-        root = tag_2.n.root()
+        root = Session.nodes.root()
         root.data.public.text = 'This is the root'
         question_0 = Session.nodes.anchor(Question, user=1)
         question_1 = Question(
             up=0,
             user=1,
         )
-        Session.add(question_1)
+        Session.nodes.add(question_1)
         question_1.anchor(question_0, user=1)
         question_1.index_under('questions', 'tag', 'wicked problem')
         tag_1.link('TAGGED', question_1)
             up=0,
             user=1,
         )
-        Session.add(question_2)
+        Session.nodes.add(question_2)
         question_1.questions.link(question_2, user=1)
         idea_2 = Question(
             _status=1,
             user=1,
             link_props=dict(user=1),
         )
-        Session.add(idea_2)
+        Session.nodes.add(idea_2)
         question_2.ideas.link(idea_2)
         pro_1 = Pro(
             _status=1,
             user=1,
             link_props=dict(user=1),
         )
-        Session.add(pro_1)
+        Session.nodes.add(pro_1)
         idea_2.pros.link(pro_1)
         pro_1.up = 6
         pro_1.text = "I'd certainly really feel confused"
             user=1,
             link_props=dict(user=1),
         )
-        Session.add(con_1)
+        Session.nodes.add(con_1)
         idea_2.cons.link(con_1)
         idea_3 = Idea(
             _status=1,
             user=1,
             link_props=dict(user=1),
         )
-        Session.add(idea_3)
+        Session.nodes.add(idea_3)
         question_2.ideas.link(idea_3)
         question_3 = Question(
             _status=1,
             user=1,
             link_props=dict(user=1),
         )
-        Session.add(question_3)
+        Session.nodes.add(question_3)
         idea_3.questions.link(question_3)
         idea_4 = Question(
             _status=1,
             user=1,
             link_props=dict(user=1),
         )
-        Session.add(idea_4)
+        Session.nodes.add(idea_4)
         question_3.ideas.link(idea_4)
         idea_4.text = 'No, Really'
         idea_5 = Question(
             user=1,
             link_props=dict(user=1),
         )
-        Session.add(idea_5)
+        Session.nodes.add(idea_5)
         question_3.ideas.link(idea_5)
         con_3 = Idea(
             _status=1,
             user=1,
             link_props=dict(user=1),
         )
-        Session.add(con_3)
+        Session.nodes.add(con_3)
         idea_5.cons.link(con_3)
         con_3.user = 2
         idea_6 = Question(
             user=1,
             link_props=dict(user=1),
         )
-        Session.add(idea_6)
+        Session.nodes.add(idea_6)
         question_2.ideas.link(idea_6)
         question_4 = Idea(
             _status=1,
             user=1,
             link_props=dict(user=1),
         )
-        Session.add(question_4)
+        Session.nodes.add(question_4)
         idea_6.questions.link(question_4)
         idea_7 = Question(
             _status=1,
             user=1,
             link_props=dict(user=1),
         )
-        Session.add(idea_7)
+        Session.nodes.add(idea_7)
         question_4.ideas.link(idea_7)
         idea_1 = Idea(
             _status=1,
             user=1,
             link_props=dict(user=1),
         )
-        Session.add(idea_1)
+        Session.nodes.add(idea_1)
         question_1.ideas.link(idea_1)
         question_5 = Question(
             _status=1,
             user=1,
             link_props=dict(user=1),
         )
-        Session.add(question_5)
+        Session.nodes.add(question_5)
         idea_7.questions.link(question_5)
         question_5.up = 15
         pro_2 = Pro(
             user=1,
             link_props=dict(user=1),
         )
-        Session.add(pro_2)
+        Session.nodes.add(pro_2)
         idea_1.pros.link(pro_2)
-        pro_4 = pro_2.fork()
-        Session.add(pro_4)
+        pro_4 = Session.using(Pro).fork(pro_2)
         pro_2.user = pro_4.user
         pro_3 = Pro(
             _status=1,
             user=1,
             link_props=dict(user=1),
         )
-        Session.add(pro_3)
+        Session.nodes.add(pro_3)
         idea_1.pros.link(pro_3)
         pro_3.down = 1
         con_4 = Con(
             user=1,
             link_props=dict(user=1),
         )
-        Session.add(con_4)
+        Session.nodes.add(con_4)
         idea_1.cons.link(con_4)
         con_4.up = 1
         con_5 = Con(
             user=1,
             link_props=dict(user=1),
         )
-        Session.add(con_5)
+        Session.nodes.add(con_5)
         idea_1.cons.link(con_5)
         con_5.text = 'Harder to do while asleep with your eyes closed'
         con_5.text = 'Much harder to do while asleep with your eyes closed'
             user=1,
             link_props=dict(user=1),
         )
-        Session.add(pro_9)
+        Session.nodes.add(pro_9)
         idea_1.pros.link(pro_9)
-        Session.delete(pro_9)
+        Session.nodes.remove(pro_9)
 
     try:
         # questions