当前位置: 首页>>代码示例>>Python>>正文


Python Person.save方法代码示例

本文整理汇总了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)
开发者ID:d10genes,项目名称:neo4django,代码行数:30,代码来源:relationship_tests.py

示例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])
开发者ID:0xmtn,项目名称:neo4django,代码行数:61,代码来源:model_tests.py

示例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'
开发者ID:d10genes,项目名称:neo4django,代码行数:11,代码来源:property_tests.py

示例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.")
开发者ID:VPechatnikov,项目名称:neo4django,代码行数:15,代码来源:nodequeryset_tests.py

示例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.'
开发者ID:chris-martin,项目名称:neo4django,代码行数:16,代码来源:model_tests.py

示例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.')
开发者ID:d10genes,项目名称:neo4django,代码行数:19,代码来源:property_tests.py

示例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)
开发者ID:clp16,项目名称:neo4django,代码行数:23,代码来源:relationship_tests.py

示例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})
开发者ID:mhluongo,项目名称:neo4django,代码行数:30,代码来源:property_tests.py

示例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())
开发者ID:mohamedturki,项目名称:crowd-io,代码行数:14,代码来源:django_tests.py

示例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()
开发者ID:d10genes,项目名称:neo4django,代码行数:7,代码来源:property_tests.py


注:本文中的neo4django.tests.Person.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。