本文介绍了AssertionError:200!= 403的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有Django应用程序和它的测试。我收到错误:

There is Django app and a test for it. I am receiving the error:

Traceback (most recent call last):
  File "../support/tests.py", line 17, in foo
    self.assertEqual(response.status_code, HttpResponseForbidden.status_code)
AssertionError: 200 != 403

测试本身的代码,导致麻烦是:

The code for the test itself, that causes trouble is:

response = self.client.get('/support/download/bar/')
self.assertEqual(response.status_code, HttpResponseForbidden.status_code)

我不明白常规来诊断这个问题,从哪里开始看。浏览网页的类似问题没有帮助。

I don't understand the routine to diagnose this problem, where to start looking at. Browsing web for similar issue didn't help.

看起来网址有一些问题 / support / download / bar /

Looks like there is some problem with the url /support/download/bar/?

推荐答案

您在test.py中所做的测试:

The test you are doing in your tests.py :

self.assertEqual(response.status_code, HttpResponseForbidden.status_code)

当您访问url / support / download / bar / 时,您将检查响应是否为 HttpResponseForbidden (代码403)

You are checking if the response when you go to the url /support/download/bar/ is a HttpResponseForbidden (code 403).

显然,您的页面成功显示(代码200),这解释了您的错误:

Apparently, you page successfully displays (code 200), which explains your error :

AssertionError: 200 != 403

你预计会出现错误,但是您显示网页的成功。

You were expecting an error, but you got success displaying the webpage.

这篇关于AssertionError:200!= 403的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 05:44