嗨,我的Django测试用例有下面的代码,测试用例失败了,因为c.get()正在命中404。所以我得到了这个错误。当我使用python 80时,如果我去http://localost//static/recaptcha/47.jpg,我可以在那里看到我的图像。
Creating test database for alias 'default'...
..>>>img_url: /static/recaptcha/47.jpg
F...
======================================================================
FAIL: test_signup_get (fastmojo.tests.test_account.FastMojoSignUpTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "c:\dj_site_test\fastmojo\tests\test_account.py", line 46, in test_signup_get
self.assertEqual(response.status_code, 200)
AssertionError: 404 != 200
----------------------------------------------------------------------
Ran 6 tests in 0.085s我的测试用例
class SignUpTest(TestCase):
def test_signup_get(self):
rechapcha_image = soup.find('img', {'class':'recap'})
assert rechapcha_image != None
assert rechapcha_image['src'] != None
img_url = rechapcha_image['src']
print ">>>img_url: %s" % img_url
assert img_url != ""
assert img_url != None
response = c.get(img_url)
self.assertEqual(response.status_code, 200)发布于 2016-08-01 16:16:11
您是否尝试在get请求中传递完整的URL,而不是传递相对路径?
看起来c.get(img_url)应该传递给http://localhost/static/recaptcha/47.jpg而不是/static/recaptcha/47.jpg。
https://stackoverflow.com/questions/38680221
复制相似问题