Django selenium liveserver重定向到管理站点

时间:2012-09-04 08:32:17

标签: django selenium django-testing

我正在使用django 1.3与Django liveserver反向移植到1.3。当我从Django LiverserverTestCase documentaion做教程时,它运行正常 但是django 1.3的进口量。它测试“/ admin /”页面并且没问题,但是当我尝试测试我的网址时,即使只是“/”,它也会再次进入管理员!为什么?我没有在谷歌找到任何线索,也许这个问题只有一个。

也许我忽略了服务器的一些设置..但是localhost:8000 / test在runserver命令之后工作正常。

如果有人遇到此类问题,请回答。

from django_liveserver.testcases import LiveServerTestCase
from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium import webdriver

class MySeleniumTests(LiveServerTestCase):
fixtures = ['nstein/test-users.json']

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

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

def test_login(self):

    self.selenium.get('%s%s' % (self.live_server_url. '/admin/'))
    body = self.selenium.find_element_by_tag_name('body')
    self.assertIn('Username', body.text)
    username_input = self.selenium.find_element_by_id("id_username")
    password_input = self.selenium.find_element_by_id("id_password")
    password_input.send_keys('123')
    username_input.send_keys('admin')
    password_input.clear()
    self.selenium.find_element_by_xpath('//input[@value="Log in"]').click()
    body = self.selenium.find_element_by_tag_name('body')
    self.assertIn('Site administration', body.text) 
    # url is in the urls.py of the app, 
    #selenium gets response 302 but redirects to /admin/
    self.selenium.get('%s%s' % (self.live_server_url. '/test/')) 

app的urls.py:

#from cms import sitemaps
from django.conf.urls.defaults import *
from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from hitcount.views import update_hit_count_ajax
from django.views.generic.simple import direct_to_template

import dselector
from wcms.furniture_today.views import *

parser = dselector.Parser()

urlpatterns = patterns('',
parser.url(r'^test/$', direct_to_template, {'template': 'index.html'}, 'index'),
)

全球网址:

from django.conf.urls.defaults import *
from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from wcms.business.views import wcms_admin_redirect

urlpatterns = patterns('',
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
url(r'^', include('wcms.admin_urls')),
url(r'^', wcms_admin_redirect),
url(r'^', include('cms.urls')),
)

if settings.DEBUG: # assuming dev server
urlpatterns += patterns('', (r'^' + settings.MEDIA_URL.lstrip('/'), include('appmedia.urls')))

urlpatterns += staticfiles_urlpatterns()

1 个答案:

答案 0 :(得分:1)

尝试将self.selenium.get('%s%s' % (self.live_server_url. '/test/'))放入新功能

def test_two(self):
    self.selenium.get('%s%s' % (self.live_server_url. '/test/'))