test_model.py 文件源码

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

项目:django-encrypted-id 作者: amitu 项目源码 文件源码
def test_model(db):
    assert db is db

    foo = Foo.objects.create(text="hello")
    assert foo.ekey
    assert foo == Foo.objects.get_by_ekey(foo.ekey)
    assert foo == Foo.objects.get_by_ekey_or_404(foo.ekey)
    assert foo == Foo.objects.get(ekey=foo.ekey)
    assert foo == Foo.objects.filter(ekey=foo.ekey).get()

    foo = Foo2.objects.create(text="hello")
    assert foo.ekey
    assert foo == Foo2.objects.get_by_ekey(foo.ekey)
    assert foo == Foo2.objects.get_by_ekey_or_404(foo.ekey)
    assert foo == Foo2.objects.get(ekey=foo.ekey)
    assert foo == Foo2.objects.filter(ekey=foo.ekey).get()

    with pytest.raises(Http404):
        Foo.objects.get_by_ekey_or_404("123123")

    with pytest.raises(Http404):
        get_list_or_404(Foo, ekey="123123")

    with pytest.raises(Http404):
        get_object_or_404(Foo, ekey="123123")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号