test_models.py 文件源码

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

项目:aiopeewee 作者: kszucs 项目源码 文件源码
def test_object_id_descriptor_naming():
    class Person(Model):
        pass

    class Foo(Model):
        me = ForeignKeyField(Person, db_column='me', related_name='foo1')
        another = ForeignKeyField(Person, db_column='_whatever_',
                                  related_name='foo2')
        another2 = ForeignKeyField(Person, db_column='person_id',
                                   related_name='foo3')
        plain = ForeignKeyField(Person, related_name='foo4')

    assert Foo.me is Foo.me_id
    assert Foo.another is Foo._whatever_
    assert Foo.another2 is Foo.person_id
    assert Foo.plain is Foo.plain_id

    with pytest.raises(AttributeError):
        Foo.another_id

    with pytest.raises(AttributeError):
        Foo.another2_id
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号