本文整理汇总了Python中neo4django.tests.Person类的典型用法代码示例。如果您正苦于以下问题:Python Person类的具体用法?Python Person怎么用?Python Person使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Person类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_basic_relationship
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)
开发者ID:d10genes,项目名称:neo4django,代码行数:28,代码来源:relationship_tests.py
示例2: test_model_pickling
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])
开发者ID:0xmtn,项目名称:neo4django,代码行数:59,代码来源:model_tests.py
示例3: test_none_prop
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})
开发者ID:mhluongo,项目名称:neo4django,代码行数:28,代码来源:property_tests.py
示例4: test_delete
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.")
开发者ID:VPechatnikov,项目名称:neo4django,代码行数:13,代码来源:nodequeryset_tests.py
示例5: test_save_delete
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.'
开发者ID:chris-martin,项目名称:neo4django,代码行数:14,代码来源:model_tests.py
示例6: test_json_serialize
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())
开发者ID:mohamedturki,项目名称:crowd-io,代码行数:12,代码来源:django_tests.py
示例7: test_none_prop
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.')
开发者ID:d10genes,项目名称:neo4django,代码行数:17,代码来源:property_tests.py
示例8: test_basic_relationship
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)
开发者ID:clp16,项目名称:neo4django,代码行数:21,代码来源:relationship_tests.py
示例9: test_prop
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'
开发者ID:d10genes,项目名称:neo4django,代码行数:9,代码来源:property_tests.py
示例10: try_int
def try_int(integer):
node = Person(name="SandraInt", age=integer)
node.save()
assert node.age == integer
node.delete()
开发者ID:d10genes,项目名称:neo4django,代码行数:5,代码来源:property_tests.py
注:本文中的neo4django.tests.Person类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论