python-3.x - 允许在 Django 测试中登录应用程序
问题描述
我正在将测试用例写入我的应用程序。请在下面找到tests.py的代码片段
class TestGetDetailsPositive(SimpleTestCase):
def setUp(self):
self.credentials = {
'username': '****',
'password': '****'
}
@responses.activate
def test_get_details(self):
self.client.login(username='****', password='****')
response = self.client.get('/accounts/selectdetails/')
self.assertContains(response, 'National', status_code=200)
self.assertTemplateUsed(response, 'accounts/select-details.html')
def test_view_url_exists_at_desired_location(self):
url = reverse('selectdetails')
self.assertEquals(resolve(url).func.view_class, SelectDetails)
我得到以下错误。
AssertionError: Database queries to 'default' are not allowed in SimpleTestCase subclasses. Either subclass TestCase or TransactionTestCase to ensure proper test isolation or add 'default' to accounts.tests.tests.TestGetBanksPositive.databases to silence this failure.
数据库配置如下所示
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': '****',
'USER': '****',
'PASSWORD': '****',
'HOST': '****',
'PORT': '****',
}
}
我在哪里做错了?
解决方案
推荐阅读
- python - BeautifulSoup - 元素仅多次显示第一个结果
- c++ - 使用命名空间的多重定义错误
- python - 如何用 kivy 赋予变量值
- dart - 运行 Gradle 任务“assembleDebug”-异常:Gradle 任务 assembleDebug 失败,退出代码为 -1
- mysql - MySQL 查询返回了一个空结果集
- python - Flask 应用程序出现 werkzeug.routing.BuildError
- java - Java Json 对象到 Json 数组的转换
- flutter - 如何将 GlobalKey 字段从一个类传递到另一个类?
- linux - 使用 awk 或更简单的 #scripting 以特定形式重新排序文本文件行
- javascript - TypeError: $(...).froalaEditor 不是函数 | JSP 中的 $(document).ready(function(){})