Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{'email': 'jim6@aol.com', 'age': 3},
{'email': 'jim7@aol.com', 'age': 5},
)
# not found
assert not Customer.nodes.filter(email='jim7@aol.com')
class Dog(StructuredNode):
name = StringProperty(required=True)
owner = RelationshipTo('Person', 'owner')
class Person(StructuredNode):
name = StringProperty(unique_index=True)
pets = RelationshipFrom('Dog', 'owner')
def test_get_or_create_with_rel():
bob = Person.get_or_create({"name": "Bob"})[0]
bobs_gizmo = Dog.get_or_create({"name": "Gizmo"}, relationship=bob.pets)
tim = Person.get_or_create({"name": "Tim"})[0]
tims_gizmo = Dog.get_or_create({"name": "Gizmo"}, relationship=tim.pets)
# not the same gizmo
assert bobs_gizmo[0] != tims_gizmo[0]
import unittest
import json
from neomodel import (
StructuredNode,
StringProperty, IntegerProperty,
RelationshipTo, RelationshipFrom,
json_encode, JsonEncoder, patch_json_dump, restore_patched_json_dump
)
class Country(StructuredNode):
code = StringProperty(unique_index=True, required=True)
inhabitant = RelationshipFrom('Person', 'IS_FROM')
json_attrs = ["code", "inhabitant"]
class Person(StructuredNode):
name = StringProperty(unique_index=True)
age = IntegerProperty(index=True, default=0)
country = RelationshipTo(Country, 'IS_FROM')
class NonSerializable:
pass
class Serializable:
def __init__(self, json_val):
self.json_val = json_val
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)
def test_filter_exclude_via_labels():
Coffee(name='Java', price=99).save()
node_set = NodeSet(Coffee)
qb = QueryBuilder(node_set).build_ast()
results = qb._execute()
assert '(coffee:Coffee)' in qb._ast['match']
assert 'result_class' in qb._ast
assert len(results) == 1
assert isinstance(results[0], Coffee)
assert results[0].name == 'Java'
name = StringProperty(unique_index=True)
age = IntegerProperty(index=True)
is_from = RelationshipTo('Country', 'IS_FROM')
knows = Relationship(u'PersonWithRels', 'KNOWS') # use unicode to check issue
@property
def special_name(self):
return self.name
def special_power(self):
return "I have no powers"
class Country(StructuredNode):
code = StringProperty(unique_index=True)
inhabitant = RelationshipFrom(PersonWithRels, 'IS_FROM')
president = RelationshipTo(PersonWithRels, 'PRESIDENT', cardinality=One)
class SuperHero(PersonWithRels):
power = StringProperty(index=True)
def special_power(self):
return "I have powers"
def test_actions_on_deleted_node():
u = PersonWithRels(name='Jim2', age=3).save()
u.delete()
with raises(ValueError):
u.is_from.connect(None)
from neomodel import (
StringProperty,
StructuredNode,
RelationshipFrom
)
from .nodeutils import NodeUtils
class Address(StructuredNode, NodeUtils):
sourceID = StringProperty()
country_codes = StringProperty()
valid_until = StringProperty()
address = StringProperty()
countries = StringProperty()
node_id = StringProperty(index = True)
officers = RelationshipFrom('.officer.Officer', 'REGISTERED_ADDRESS')
intermediaries = RelationshipFrom('.intermediary.Intermediary', 'REGISTERED_ADDRESS')
@property
def serialize(self):
return {
'node_properties': {
'sourceID': self.sourceID,
'country_codes': self.country_codes,
'valid_until': self.valid_until,
'address': self.address,
'countries': self.countries,
'node_id': self.node_id,
},
}
class Entity(StructuredNode, NodeUtils):
sourceID = StringProperty()
address = StringProperty()
jurisdiction = StringProperty()
service_provider = StringProperty()
countries = StringProperty()
jurisdiction_description = StringProperty()
valid_until = StringProperty()
ibcRUC = StringProperty()
name = StringProperty()
country_codes = StringProperty()
incorporation_date = StringProperty()
node_id = StringProperty(index = True)
status = StringProperty()
officers = RelationshipFrom('.officer.Officer', 'OFFICER_OF')
intermediaries = RelationshipFrom('.intermediary.Intermediary', 'INTERMEDIARY_OF')
addresses = RelationshipTo('.address.Address', 'REGISTERED_ADDRESS')
others = RelationshipFrom('.other.Other', 'CONNECTED_TO')
entities = Relationship('.entity.Entity', None)
@property
def serialize(self):
return {
'node_properties': {
'sourceID': self.sourceID,
'address': self.address,
'jurisdiction': self.jurisdiction,
'service_provider': self.service_provider,
'countries': self.countries,
'jurisdiction_description': self.jurisdiction_description,
'valid_until': self.valid_until,
class Entity(StructuredNode, NodeUtils):
sourceID = StringProperty()
address = StringProperty()
jurisdiction = StringProperty()
service_provider = StringProperty()
countries = StringProperty()
jurisdiction_description = StringProperty()
valid_until = StringProperty()
ibcRUC = StringProperty()
name = StringProperty()
country_codes = StringProperty()
incorporation_date = StringProperty()
node_id = StringProperty(index = True)
status = StringProperty()
officers = RelationshipFrom('.officer.Officer', 'OFFICER_OF')
intermediaries = RelationshipFrom('.intermediary.Intermediary', 'INTERMEDIARY_OF')
addresses = RelationshipTo('.address.Address', 'REGISTERED_ADDRESS')
others = RelationshipFrom('.other.Other', 'CONNECTED_TO')
entities = Relationship('.entity.Entity', None)
@property
def serialize(self):
return {
'node_properties': {
'sourceID': self.sourceID,
'address': self.address,
'jurisdiction': self.jurisdiction,
'service_provider': self.service_provider,
'countries': self.countries,
'jurisdiction_description': self.jurisdiction_description,
class Fragment(BaseMolecule):
"""
A fragment - not a real molecule
"""
molecules = RelationshipFrom(Compound, "FRAG", model=F2Edge)
class Conformer(StructuredNode):
"""
The 3D conformer of a molecule - either Docked or imaginary
"""
# Going to go with uuid - seems as good as anything - this connects to the Django database for 3D information
unique_string = StringProperty(unique_index=True)
conformer = RelationshipFrom(Compound, "CONFEDGE")
score = FloatProperty()
is_xtal_pose = BooleanProperty()
threed_sim_to_reference = FloatProperty()
rmsd_to_xtal_pose = FloatProperty()
# Connect to Molecule and Protein
class ConformerFeature(StructuredNode):
"""
A pharmacophore feature for a given Conformer
"""
# Unique id - uuid:PHARMAFEATURE:INDEX
unique_string = StringProperty(unique_index=True)
pharma_feature = StringProperty()
index = IntegerProperty()
# Connect to SpecificResidue and to other SpecificResidueFeature annotated by distance and angle
class Compound(BaseMolecule):
"""
A molecule - a real purchasable molecule
"""
fragments = RelationshipTo("Fragment", "FRAG")
conformers = RelationshipTo("Conformer", "CONFEDGE")
parent_molecules = RelationshipTo("Compound", "PARENTEDGE")
class Fragment(BaseMolecule):
"""
A fragment - not a real molecule
"""
molecules = RelationshipFrom(Compound, "FRAG", model=F2Edge)
class Conformer(StructuredNode):
"""
The 3D conformer of a molecule - either Docked or imaginary
"""
# Going to go with uuid - seems as good as anything - this connects to the Django database for 3D information
unique_string = StringProperty(unique_index=True)
conformer = RelationshipFrom(Compound, "CONFEDGE")
score = FloatProperty()
is_xtal_pose = BooleanProperty()
threed_sim_to_reference = FloatProperty()
rmsd_to_xtal_pose = FloatProperty()
# Connect to Molecule and Protein
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(),
"phone_number": fields.Str(required=True)
}
__filtered_fields__ = ["secret_field"]
uid = UniqueIdProperty()
first_name = StringProperty()
last_name = StringProperty()
phone_number = StringProperty(unique_index=True, required=True)