我想测试我的查询数据库功能。
import pytest
from account_system.action import my_action
from account_system.models import MyUser
@pytest.mark.django_db
def test_ok_profile():
req = FakeRequest()
email = 'tester@example.com'
MyUser.objects.create_user(
email=email,
password="example",
)
# query MyUser table and return result
result = my_action.get_profile(email)
assert result == 'success'
但它失败了。
> assert result == 'success'
E assert None == 'success'
该函数没有从 DB 获得任何结果。
我检查了数据库数据,没有看到任何记录。(例如用户tester@example.com)
如何重写我的代码进行测试?
或者如何将数据保存在数据库中?
谢谢,