Tag: django testing

如何在Djangounit testing中获取请求对象?

我有一个function def getEvents(eid, request): …… 现在我想单独为上面的函数编写unit testing(不调用视图)。 那么我应该如何在TestCase调用上述内容。 是否有可能创build请求?

Django:有没有一种方法来计算unit testing的SQL查询?

我正在试图找出一个实用函数执行的查询的数量。 我已经为这个函数写了一个unit testing,这个函数运行的很好。 我想要做的是跟踪由该函数执行的SQL查询的数量,以便可以看到重构后是否有任何改进。 def do_something_in_the_database(): # Does something in the database # return result class DoSomethingTests(django.test.TestCase): def test_function_returns_correct_values(self): self.assertEqual(n, <number of SQL queries executed>) 编辑:我发现这是一个未决的Django function请求 。 不过票还是开着的。 同时还有另外一种方法可以解决这个问题吗?

Django:testing页面是否已redirect到所需的url

在我的Django应用程序中,我有一个身份validation系统。 所以,如果我不login并尝试访问某个个人资料的个人信息,我将被redirect到一个login页面。 现在,我需要为此写一个testing用例。 我得到的浏览器的回应是: GET /myprofile/data/some_id/ HTTP/1.1 302 0 GET /account/login?next=/myprofile/data/some_id/ HTTP/1.1 301 0 GET /account/login?next=/myprofile/data/some_id/ HTTP/1.1 200 6533 我如何编写我的testing? 这是我迄今为止: self.client.login(user="user", password="passwd") response = self.client.get('/myprofile/data/some_id/') self.assertEqual(response.status,200) self.client.logout() response = self.client.get('/myprofile/data/some_id/') 接下来会发生什么?

我应该如何在Django中编写testing表单?

我想在编写testing时模拟Django中对我的视图的请求。 这主要是为了testing表格。 这是一个简单的testing请求的片段: from django.tests import TestCase class MyTests(TestCase): def test_forms(self): response = self.client.post("/my/form/", {'something':'something'}) self.assertEqual(response.status_code, 200) # we get our page back with an error 无论是否存在表单错误,页面总是返回200的响应。 我怎样才能检查我的表格失败,特定的领域( soemthing )有错误?

Djangotesting应用程序错误 – 创buildtesting数据库时出现错误:权限被拒绝创build数据库

当我尝试使用命令testing任何应用程序时(当我尝试使用使用此命令的结构部署myproject时,我注意到了这一点): python manage.py test appname 我得到这个错误: Creating test database for alias 'default'… Got an error creating the test database: permission denied to create database Type 'yes' if you would like to try deleting the test database 'test_finance', or 'no' to cancel syncdb命令似乎工作。 settings.py中的我的数据库设置: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' […]