我想使用postgres localhost数据库中的数据(已经加载的数据)测试我的视图.我正在使用pyx和pytest-django.
我的问题:如何设置/连接到本地数据库以获取所有数据模型架构和数据本身?或者也许最好使用factory_boy?或者从.sql脚本加载整个数据(如果是,如何)?
我的测试示例:
def test_foo_view(custom_client_login):
response = custom_client_login.get('/foo/bar/123/')
assert response.status_code == 200
assert 'Transaction no. 123' in response.content
Run Code Online (Sandbox Code Playgroud)
但是不是获取状态代码200,而是获得404,这表明测试数据库中没有数据.但是当我午餐runserver并进入该视图时,('localhost:8000/foo/bar/123/')我将获得状态200和html网页以及一些数据.
请帮忙!
我正在使用: