Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from datetime import datetime
from pytest import raises
import pytz
from neomodel import (StructuredNode, StructuredRel, Relationship, RelationshipTo,
StringProperty, DateTimeProperty, DeflateError)
HOOKS_CALLED = {
'pre_save': 0,
'post_save': 0
}
class FriendRel(StructuredRel):
since = DateTimeProperty(default=lambda: datetime.now(pytz.utc))
class HatesRel(FriendRel):
reason = StringProperty()
def pre_save(self):
HOOKS_CALLED['pre_save'] += 1
def post_save(self):
HOOKS_CALLED['post_save'] += 1
class Badger(StructuredNode):
name = StringProperty(unique_index=True)
friend = Relationship('Badger', 'FRIEND', model=FriendRel)
from datetime import datetime
from pytest import raises
from neomodel import (
INCOMING, DateTimeProperty, IntegerProperty, RelationshipFrom, RelationshipTo,
StringProperty, StructuredNode, StructuredRel
)
from neomodel.match import NodeSet, QueryBuilder, Traversal
from neomodel.exceptions import MultipleNodesReturned
class SupplierRel(StructuredRel):
since = DateTimeProperty(default=datetime.now)
courier = StringProperty()
class Supplier(StructuredNode):
name = StringProperty()
delivery_cost = IntegerProperty()
coffees = RelationshipTo('Coffee', 'COFFEE SUPPLIERS') # Space to check for escaping
class Coffee(StructuredNode):
name = StringProperty(unique_index=True)
price = IntegerProperty()
suppliers = RelationshipFrom(Supplier, 'COFFEE SUPPLIERS', model=SupplierRel)
rey = PersonWithRels(name='Rey', age=3).save()
sakis = PersonWithRels(name='Sakis', age=3).save()
rey.knows.connect(sakis)
assert rey.knows.is_connected(sakis)
assert sakis.knows.is_connected(rey)
sakis.knows.connect(rey)
result, meta = sakis.cypher("""MATCH (us), (them)
WHERE id(us)={self} and id(them)={them}
MATCH (us)-[r:KNOWS]-(them) RETURN COUNT(r)""",
{'them': rey.id})
assert int(result[0][0]) == 1
rel = rey.knows.relationship(sakis)
assert isinstance(rel, StructuredRel)
rels = rey.knows.all_relationships(sakis)
assert isinstance(rels[0], StructuredRel)
from neomodel import (StructuredNode, StructuredRel, Relationship,
StringProperty, DateTimeProperty, IntegerProperty, connection)
from datetime import datetime, timedelta
twelve_days = timedelta(days=12)
eleven_days = timedelta(days=11)
ten_days = timedelta(days=10)
nine_days = timedelta(days=9)
now = datetime.now()
class FriendRelationship(StructuredRel):
since = DateTimeProperty(default=datetime.now)
class Person(StructuredNode):
name = StringProperty()
age = IntegerProperty()
friends = Relationship('Person', 'friend_of', model=FriendRelationship)
def setup_friends(person0, person1, since=None):
rel = person0.friends.connect(person1)
if (since):
rel.since = since
rel.save()
return rel.since
rey.knows.connect(sakis)
assert rey.knows.is_connected(sakis)
assert sakis.knows.is_connected(rey)
sakis.knows.connect(rey)
result, meta = sakis.cypher("""MATCH (us), (them)
WHERE id(us)={self} and id(them)={them}
MATCH (us)-[r:KNOWS]-(them) RETURN COUNT(r)""",
{'them': rey.id})
assert int(result[0][0]) == 1
rel = rey.knows.relationship(sakis)
assert isinstance(rel, StructuredRel)
rels = rey.knows.all_relationships(sakis)
assert isinstance(rels[0], StructuredRel)
a relationship as specified by the model"
"""
import os
import neomodel
import datetime
import pytest
import random
try:
basestring
except NameError:
basestring = str
# Set up a very simple model for the tests
class PersonalRelationship(neomodel.StructuredRel):
"""
A very simple relationship between two basePersons that simply records
the date at which an acquaintance was established.
This relationship should be carried over to anything that inherits from
basePerson without any further effort.
"""
on_date = neomodel.DateProperty(default_now = True)
class BasePerson(neomodel.StructuredNode):
"""
Base class for defining some basic sort of an actor.
"""
name = neomodel.StringProperty(required = True, unique_index = True)
friends_with = neomodel.RelationshipTo("BasePerson", "FRIENDS_WITH",
model = PersonalRelationship)
return r
@classmethod
def get_class_from_type(cls, the_type):
for the_cls in cls.__base__.__subclasses__():
if the_cls.__type__ == the_type:
return the_cls
return None
class EnumeratedTypeError(Exception):
pass
class SerializableStructuredRel(StructuredRel):
r"""
The Base Relationship that all Structured Relationships must inherit from. All relationships should be structured \
starting version 1.1.0 -- okay to use model=SerializableStructuredRel
"""
secret = []
updated = DateTimeProperty(default=datetime.now())
created = DateTimeProperty(default=datetime.now())
type = StringProperty(default="serializable_structured_rel")
def get_resource_identifier_object(self, end_node):
try:
response = dict()
response['id'] = end_node.id
response['type'] = end_node.type
response['meta'] = dict()
import logging.handlers
import os
import markupsafe
import neomodel
from flask import Flask, jsonify
from flask_classful import route
from neomodel import (IntegerProperty, RelationshipFrom, RelationshipTo,
StringProperty, StructuredNode, StructuredRel,
UniqueIdProperty)
from webargs import fields
from grest import GRest, global_config, models, utils
class PetInfo(StructuredRel, models.Relation):
"""Pet Information Model (for relationship)"""
adopted_since = IntegerProperty()
class Pet(StructuredNode, models.Node):
"""Pet model"""
pet_id = UniqueIdProperty()
name = StringProperty()
owner = RelationshipFrom("User", "HAS_PET")
class User(StructuredNode, models.Node):
"""User model"""
__validation_rules__ = {
"first_name": fields.Str(),
"last_name": fields.Str(),
cursor = connection.cursor()
cursor.execute(
'REFRESH MATERIALIZED VIEW CONCURRENTLY grafit_search_index;')
logger.info("finished updating search index")
@receiver([signals.post_save, signals.post_delete], sender=Article, dispatch_uid="update_search_word")
def update_search_word(sender, instance, **kwargs):
logger.info("update search word")
cursor = connection.cursor()
cursor.execute(
'REFRESH MATERIALIZED VIEW CONCURRENTLY grafit_search_word;')
logger.info("finished updating search word")
class ArticleRel(StructuredRel):
created_at = DateTimeProperty(
default=lambda: datetime.now()
)
tf_idf = FloatProperty()
hidden = BooleanProperty(default=False)
label = StringProperty()
class GraphArticle(StructuredNode):
uid = UniqueIdProperty()
name = StringProperty()
related = Relationship('GraphArticle', 'RELATED', model=ArticleRel)
class SearchResult(models.Model):
id = models.BigIntegerField(primary_key=True)