本文整理汇总了Python中neo4django.tests.Person.save方法的典型用法代码示例。如果您正苦于以下问题:Python Person.save方法的具体用法?Python Person.save怎么用?Python Person.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neo4django.tests.Person
的用法示例。
在下文中一共展示了Person.save方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_basic_relationship
# 需要导入模块: from neo4django.tests import Person [as 别名]
# 或者: from neo4django.tests.Person import save [as 别名]
def test_basic_relationship():
"""
Tests both sides of a simple many-to-many relationship (without relationship
properties).
"""
class RelatedPaper(models.NodeModel):
authors = models.Relationship(Person,
rel_type = neo4django.Outgoing.OWNED_BY,
related_name = 'papers'
)
sandra = Person(name="Sandra")
sandra.save()
lifesWork = RelatedPaper()
lifesWork.save()
lifesWork.authors.add(sandra)
lifesWork.save()
work = list(sandra.papers.all())
assert lifesWork in work, "Paper not found in %s" % repr(work)
authors = list(lifesWork.authors.all())
assert sandra in authors, "Author not found in %s" % repr(work)
#find all shared neo4j relationships
sandras = sandra.node.relationships.all(['OWNED_BY'])[:]
eq_(len(sandras), 1)
#test proper direction
eq_(sandras[0].end, sandra.node)
eq_(sandras[0].start, lifesWork.node)
示例2: test_model_pickling
# 需要导入模块: from neo4django.tests import Person [as 别名]
# 或者: from neo4django.tests.Person import save [as 别名]
def test_model_pickling():
"""
Covers issue #46, pickling `NodeModel`s.
"""
def pickle_and_restore(m):
import pickle
return pickle.loads(pickle.dumps(m))
def pickle_eq(m1, m2):
eq_(m1.name, m2.name)
eq_(m2.using, m2.using)
eq_(m2.id, m2.id)
# try a simple model
pete = Person(name="Pete")
restored_pete = pickle_and_restore(pete)
pickle_eq(pete, restored_pete)
# try a saved model
pete.save()
restored_saved_pete = pickle_and_restore(pete)
pickle_eq(pete, restored_saved_pete)
# try related models
from .models import IndexedMouse, RelatedCat, LazyCat
jerry = IndexedMouse.objects.create(name='Jerry')
tom = RelatedCat(name='Jerry')
tom.chases = jerry
tom.save()
restored_tom = pickle_and_restore(tom)
pickle_eq(tom, restored_tom)
pickle_eq(jerry, list(restored_tom.chases.all())[0])
# try a model with a lazy relation
garfield = LazyCat(name='Garfield')
garfield.chases.add(jerry)
restored_garfield = pickle_and_restore(garfield)
pickle_eq(garfield, restored_garfield)
pickle_eq(jerry, list(restored_garfield.chases.all())[0])
# and finally a saved model with a lazy relation
garfield.save()
restored_saved_garfield = pickle_and_restore(garfield)
pickle_eq(garfield, restored_saved_garfield)
pickle_eq(jerry, list(restored_saved_garfield.chases.all())[0])
示例3: test_prop
# 需要导入模块: from neo4django.tests import Person [as 别名]
# 或者: from neo4django.tests.Person import save [as 别名]
def test_prop():
pete = Person(name='Pete')
assert pete.name == 'Pete'
pete.save()
assert pete.name == 'Pete'
pete.name = 'Peter'
assert pete.name == 'Peter'
pete.save()
assert pete.name == 'Peter'
示例4: test_delete
# 需要导入模块: from neo4django.tests import Person [as 别名]
# 或者: from neo4django.tests.Person import save [as 别名]
def test_delete():
"""Confirm 'delete()' works for NodeQuerySet."""
jack = Person(name='jack')
jack.save()
jacks_pk = jack.pk
Person.objects.filter(name='jack').delete()
try:
gdb.nodes.get(jacks_pk)
except:
pass
else:
raise AssertionError("Jack's pk is still in the graph- he wasn't "
"deleted.")
示例5: test_save_delete
# 需要导入模块: from neo4django.tests import Person [as 别名]
# 或者: from neo4django.tests.Person import save [as 别名]
def test_save_delete():
"""Basic sanity check for NodeModel save and delete. """
from neo4jrestclient.client import NotFoundError
pete = Person(name='Pete')
pete.save()
node_id = pete.id
pete.delete()
try:
gdb.nodes.get(node_id)
except NotFoundError:
pass
else:
assert False, 'Pete was not properly deleted.'
示例6: test_none_prop
# 需要导入模块: from neo4django.tests import Person [as 别名]
# 或者: from neo4django.tests.Person import save [as 别名]
def test_none_prop():
"""Confirm that `None` and null verification work properly."""
pete = Person()
pete.save()
assert pete.name is None
class NotNullPerson(models.NodeModel):
class Meta:
app_label = 'test'
name = models.StringProperty(null=False)
try:
andy = NotNullPerson(name = None)
andy.save()
except:
pass
else:
raise AssertionError('Non-nullable field accepted `None` as a value.')
示例7: test_basic_relationship
# 需要导入模块: from neo4django.tests import Person [as 别名]
# 或者: from neo4django.tests.Person import save [as 别名]
def test_basic_relationship():
"""
Tests both sides of a simple many-to-many relationship (without relationship
properties).
"""
class RelatedPaper(neo4django.NodeModel):
authors = neo4django.Relationship(Person,
rel_type = neo4django.Outgoing.OWNED_BY,
related_name = 'papers'
)
sandra = Person(name="Sandra")
sandra.save()
lifesWork = RelatedPaper()
lifesWork.save()
lifesWork.authors.add(sandra)
lifesWork.save()
work = list(sandra.papers.all())
assert lifesWork in work, "Paper not found in %s" % repr(work)
authors = list(lifesWork.authors.all())
assert sandra in authors, "Author not found in %s" % repr(work)
示例8: test_none_prop
# 需要导入模块: from neo4django.tests import Person [as 别名]
# 或者: from neo4django.tests.Person import save [as 别名]
def test_none_prop():
"""Confirm that `None` and null verification work properly."""
#first show that unsert properties are None
pete = Person()
pete.save()
assert pete.name is None
#then that `null=False` works properly
class NotNullPerson(models.NodeModel):
class Meta:
app_label = 'test'
name = models.StringProperty(null=False)
try:
andy = NotNullPerson(name = None)
andy.save()
except:
pass
else:
raise AssertionError('Non-nullable field accepted `None` as a value.')
#and finally, that setting a property to None deletes it in the db
pete.name = 'Pete'
pete.save()
pete.name = None
pete.save()
assert_gremlin('results=!g.v(node_id).any{it.hasProperty("name")}',
{'node_id':pete.id})
示例9: test_json_serialize
# 需要导入模块: from neo4django.tests import Person [as 别名]
# 或者: from neo4django.tests.Person import save [as 别名]
def test_json_serialize():
from django.core import serializers
dave = Person(name='dave')
dave.save()
json_serializer = serializers.get_serializer('json')()
assert json_serializer.serialize(Person.objects.all())
dave = Person(name='dave', age=12)
dave.save()
assert json_serializer.serialize(Person.objects.all())
dave = Person()
dave.save()
assert json_serializer.serialize(Person.objects.all())
示例10: try_int
# 需要导入模块: from neo4django.tests import Person [as 别名]
# 或者: from neo4django.tests.Person import save [as 别名]
def try_int(integer):
node = Person(name="SandraInt", age=integer)
node.save()
assert node.age == integer
node.delete()