2014-01-12 82 views
0

我正在關注TddjangoTutorial。我的問題是,當我訪問localhost:8000/admin/polls/poll訪問 以創建一個新的輪詢時,它會抱怨輪詢表不在那裏。這通過運行創建表的syncdb命令來解決。但是當我運行命令之前運行硒測試時,它運行良好。測試打開localhost:8081/admin/polls/poll。它顯示了要添加新投票的頁面。功能測試是否自動創建此表?使用硒數據庫創建django功能測試

代碼功能測試:

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

from userFactory import UserFactory 

class PollsTest(LiveServerTestCase): 
    def setUp(self): 
     self.browser = webdriver.Firefox() 
     self.browser.implicitly_wait(3) 
     self.user = UserFactory.create() 

    def tearDown(self): 
     self.browser.quit() 

    def test_can_create_new_poll_via_admin_site(self): 
     self.browser.get(self.live_server_url+'/admin/') 
     body = self.browser.find_element_by_tag_name('body') 
     self.assertIn('Django administration', body.text) 

     username_field = self.browser.find_element_by_name('username') 
     username_field.send_keys(self.user.username) 

     password_field = self.browser.find_element_by_name('password') 
     password_field.send_keys('adm1n') 
     password_field.send_keys(Keys.ENTER) 

     body = self.browser.find_element_by_tag_name('body') 

     self.assertIn('Site administration', body.text) 
     polls_links = self.browser.find_elements_by_link_text('Polls') 
     self.assertEqual(len(polls_links), 2) 
     polls_links[1].click() 

     #the user is taken to the polls listing page, which shows no polls yet 
     body = self.browser.find_element_by_tag_name('body') 
     self.assertIn('0 polls', body.text) 

     # the user clicks on add to add a new poll 
     new_poll_link = self.browser.find_element_by_link_text('Add poll') 
     new_poll_link.click() 

     body = self.browser.find_element_by_tag_name('body') 
     self.assertIn('Question:', body.text) 
     self.assertIn('Date published:', body.text) 

回答

相關問題