I’m using django 1.3 with Django liveserver backported to 1.3. It worked fine, when i was doing tutorial from Django LiverserverTestCase documentaion
but with imports for django 1.3. It tests “/admin/” page and is ok, but when i try to test my urls, even just “/”, it goes to admin again! why? I didn’t find any clues in Google, maybe this problem is only one.
Maybe i dissmissed some settings of the server.. But localhost:8000/test works fine after runserver command.
Answer if somebody had this type of problem.
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/'))
urls.py of the app:
#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'),
)
global urls:
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()
Try putting
self.selenium.get('%s%s' % (self.live_server_url. '/test/'))in a new function