relation_model_models_test.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:appbackendapi 作者: codesdk 项目源码 文件源码
def test_relationship(testbed):
    # Creates 1 contact and 2 companies
    addressbook_key = ndb.Key('AddressBook', 'tmatsuo')
    mary = models.Contact(parent=addressbook_key, name='Mary')
    mary.put()
    google = models.Company(name='Google')
    google.put()
    candit = models.Company(name='Candit')
    candit.put()

    # first google hires Mary
    models.ContactCompany(parent=addressbook_key,
                          contact=mary.key,
                          company=google.key,
                          title='engineer').put()
    # then another company named 'candit' hires Mary too
    models.ContactCompany(parent=addressbook_key,
                          contact=mary.key,
                          company=candit.key,
                          title='president').put()

    # get the list of companies that Mary belongs to
    assert len(mary.companies) == 2
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号