LiveServerTestCase不会将Django Application映射到url

时间:2013-09-01 20:01:21

标签: python django django-urls django-testing django-unittest

背景:

我正在尝试为Django应用程序设置我的第一个Selenium驱动集成测试。我开发了以下简单代码:

from django.test import LiveServerTestCase
from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.common.keys import Keys

class DynamicFormsIntegrationTest(LiveServerTestCase):

    @classmethod
    def setUpClass(cls):
        cls.selenium = WebDriver()
        cls.selenium.implicitly_wait(3)
        super(DynamicFormsIntegrationTest, cls).setUpClass()


    @classmethod
    def tearDownClass(cls):
        super(DynamicFormsIntegrationTest, cls).tearDownClass()
        cls.selenium.quit()


    def test_basic(self):
        """ Uses get to open application page """

        self.selenium.get(self.live_server_url + '/woc/')


        #Force Test Fail
        self.fail("FAIL")

现在,当我使用以下命令运行此测试时:

python manage.py test test2

我得到以下输出:

python manage.py test test2^JCreating test database for alias 'default'...
<QueryDict: {}>
F
======================================================================
FAIL: test_basic (test2.tests.test_forms.DynamicFormsIntegrationTest)
Adds a single set via Jquery/Javascript, Submits, and verifies it was rendered and added to Model.Sets
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/usr/path/to/app/test2/tests/test_forms.py", line 42, in test_basic
    self.fail("FAIL")
AssertionError: FAIL

----------------------------------------------------------------------
Ran 1 test in 8.901s

FAILED (failures=1)
Destroying test database for alias 'default'...

当我浏览常规设置时:

python manage.py runserver

我在页面请求时得到以下输出:

python manage.py runserver
Validating models...

0 errors found
September 01, 2013 - 14:42:34
Django version 1.5.1, using settings 'app.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
<QueryDict: {}>
[01/Sep/2013 14:42:39] "GET /test2/ HTTP/1.1" 200 9372

正如您所看到的,在运行测试时无法识别网页(实际上没有“GET”请求,正如在开发环境请求中正确完成的那样)。我实际上认为“GET”失败只是LiveServerTestCase未正确设置应用程序问题的一个指标。

问题:

为什么LiveServerTestCase无法识别我的网页网址?如何解决此问题?

0 个答案:

没有答案