When I run the test suite of django I get errors on the auth application. I have (obviously) not written any of auth code and I have not written tests for auth. yet the auth tests fail. Here are some of the errors I get, the whole stacktrace is too big to put here: Does someone has dealt with this before?
当我运行django的测试套件时,我在auth应用程序上遇到错误。我(显然)没有写任何auth代码,我没有为auth编写测试。但是验证测试失败了。以下是我得到的一些错误,整个堆栈跟踪太大了,不能放在这里:有人之前处理过这个吗?
AttributeError: 'module' object has no attribute 'handler500'
DoesNotExist: UserProfile matching query does not exist.
----------------------------------------------------------------------
Ran 30 tests in 3.813s
FAILED (errors=17)
Destroying test database...
1 个解决方案
#1
I figured it out. Failed tests in auth tests happen if the auth app uses complicated templates to render the default auth template-views. The auth app tests itself with the templates which are used by your application. I have changed the defaults to templates which look the same as the rest of my website.
我想到了。如果auth应用程序使用复杂的模板来呈现默认的auth模板视图,则会发生auth测试失败的测试。 auth应用程序使用您的应用程序使用的模板测试自身。我已将默认值更改为模板,其外观与我网站的其余部分相同。
The mistake I made in my templates:
我在模板中犯的错误:
- usage of variables and reverse urls which are not known by the auth app. In my case it where user profile information (which are not available when you are not logged in ofcourse) in auth templates and bad url reverse tags which caused errors in the auth app tests.
使用auth应用程序不知道的变量和反向URL。在我的情况下,它是用户配置文件信息(当你没有登录的时候在auth模板中不可用)和坏的url反向标签,这导致auth app测试中的错误。
When I dropped out everything which was useless anyways on the basic auth templates all auth tests succeeded again.
当我在基本的auth模板上删除所有无用的东西时,所有auth测试再次成功。
because of this I learned another lesson:
因此我学到了另一个教训:
It is usefull to separate content and structure in your templates. This is easy todo by creating a base.html template file which only defines a basic html page structure and contains a bunch of content blocks. see example code below:
将模板中的内容和结构分开是很有用的。通过创建base.html模板文件很容易做到这一点,该文件仅定义基本的html页面结构并包含一堆内容块。看下面的示例代码:
The next step is to create a base_content.html which extends base.html and only defines content blocks you use to render content into the pages. with basic simple content that is needed on every page.
下一步是创建一个base_content.html,它扩展了base.html,并且只定义了用于将内容呈现到页面中的内容块。每页都需要基本的简单内容。
In your app you extend the base_content.html and fill up the remaining empty content blocks or override them with new ones.. Using this technique it is very easy to create auth templates which extend base_content.html or base.html for the very basic authentication templates so most of the (useless) content is left out.
在你的应用程序中,你扩展base_content.html并填充剩余的空内容块或用新的覆盖它们。使用这种技术很容易创建auth模板,扩展base_content.html或base.html进行非常基本的身份验证模板,因此大多数(无用的)内容被遗漏。
example base.html
<body>
<div id="header">
{% block mainmenu %}{% endblock %}
</div>
<div id="userbar">
{% block userbar %}{% endblock %}
</div>
<div id="bigcontent">
{% block bigcontent %}{% endblock %}
</div>
</body>
example base.content
{% extends "base.html" %}
{% load i18n %}
{% block mainmenu %}
...content..
{% endblock %}
Now all templates in my app extend the base content template which has content which is shown on every page. This way you don't repeat yourself and your template code gets very DRY and by just using base.content templates for you auth views will make the auth tests succeed aggain!
现在我的应用程序中的所有模板都扩展了基本内容模板,该模板具有显示在每个页面上的内容。这样你就不会重复自己,你的模板代码会变得非常糟糕,只需使用base.content模板,auth视图就会使auth测试成功加入!
#1
I figured it out. Failed tests in auth tests happen if the auth app uses complicated templates to render the default auth template-views. The auth app tests itself with the templates which are used by your application. I have changed the defaults to templates which look the same as the rest of my website.
我想到了。如果auth应用程序使用复杂的模板来呈现默认的auth模板视图,则会发生auth测试失败的测试。 auth应用程序使用您的应用程序使用的模板测试自身。我已将默认值更改为模板,其外观与我网站的其余部分相同。
The mistake I made in my templates:
我在模板中犯的错误:
- usage of variables and reverse urls which are not known by the auth app. In my case it where user profile information (which are not available when you are not logged in ofcourse) in auth templates and bad url reverse tags which caused errors in the auth app tests.
使用auth应用程序不知道的变量和反向URL。在我的情况下,它是用户配置文件信息(当你没有登录的时候在auth模板中不可用)和坏的url反向标签,这导致auth app测试中的错误。
When I dropped out everything which was useless anyways on the basic auth templates all auth tests succeeded again.
当我在基本的auth模板上删除所有无用的东西时,所有auth测试再次成功。
because of this I learned another lesson:
因此我学到了另一个教训:
It is usefull to separate content and structure in your templates. This is easy todo by creating a base.html template file which only defines a basic html page structure and contains a bunch of content blocks. see example code below:
将模板中的内容和结构分开是很有用的。通过创建base.html模板文件很容易做到这一点,该文件仅定义基本的html页面结构并包含一堆内容块。看下面的示例代码:
The next step is to create a base_content.html which extends base.html and only defines content blocks you use to render content into the pages. with basic simple content that is needed on every page.
下一步是创建一个base_content.html,它扩展了base.html,并且只定义了用于将内容呈现到页面中的内容块。每页都需要基本的简单内容。
In your app you extend the base_content.html and fill up the remaining empty content blocks or override them with new ones.. Using this technique it is very easy to create auth templates which extend base_content.html or base.html for the very basic authentication templates so most of the (useless) content is left out.
在你的应用程序中,你扩展base_content.html并填充剩余的空内容块或用新的覆盖它们。使用这种技术很容易创建auth模板,扩展base_content.html或base.html进行非常基本的身份验证模板,因此大多数(无用的)内容被遗漏。
example base.html
<body>
<div id="header">
{% block mainmenu %}{% endblock %}
</div>
<div id="userbar">
{% block userbar %}{% endblock %}
</div>
<div id="bigcontent">
{% block bigcontent %}{% endblock %}
</div>
</body>
example base.content
{% extends "base.html" %}
{% load i18n %}
{% block mainmenu %}
...content..
{% endblock %}
Now all templates in my app extend the base content template which has content which is shown on every page. This way you don't repeat yourself and your template code gets very DRY and by just using base.content templates for you auth views will make the auth tests succeed aggain!
现在我的应用程序中的所有模板都扩展了基本内容模板,该模板具有显示在每个页面上的内容。这样你就不会重复自己,你的模板代码会变得非常糟糕,只需使用base.content模板,auth视图就会使auth测试成功加入!