我的測試:Selenium測試,LiveServerTestCase,Django的,和NoReverseMatch
class BasicProfileTest(LiveServerTestCase):
fixtures = ['admin_user.json', 'gym.json', 'user_profile.json']
def setUp(self):
self.browser = webdriver.Firefox()
self.browser.implicitly_wait(3)
def tearDown(self):
self.browser.quit()
def test_can_login_check_profile(self):
self.browser.get(self.live_server_url + '/trackstats/index/')
body = self.browser.find_element_by_tag_name('body')
self.assertIn('Track your workouts. See your progress. Share with friends.', body.text)
username_field = self.browser.find_element_by_name('username')
username_field.send_keys('bobo')
password_field = self.browser.find_element_by_name('password')
password_field.send_keys('.....')
password_field.send_keys(Keys.RETURN)
profile_link = self.browser.find_element_by_link_text("bobo's profile")
profile_link.click()
body = self.browser.find_element_by_tag_name('body')
self.assertIn('Change Password', body.text)
當我運行測試,它傳遞但它也拋出一個
NoReverseMatch: Reverse for 'user_profile_update' with arguments '('',)' and keyword arguments '{}' not found.
如果我把一個直接鏈接到用戶的個人資料在base.html:
/trackstats/profile/update/{{user.id}}
我沒有得到反向匹配異常。但只要我將其替換爲
{% url user_profile_update user.id %}
它與NoReverMatch異常折衷出來。
我覺得我在這裏失去了一些明顯的東西。
更新1.添加urls.py
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.contrib import admin
admin.autodiscover()
from django.views.generic.simple import redirect_to
urlpatterns = patterns('',
(r'^$', redirect_to, {'url': '/trackstats/index/'}),
url(r'^admin/', include(admin.site.urls)),
(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'registration/login.html'}),
(r'^accounts/', include('registration.backends.default.urls')),
url(r'^trackstats/index/', 'trackstats.views.index', name='index'),
url(r'^trackstats/user_profile/create/', 'trackstats.views.user_profile_create', name='user_profile_create'),
url(r'^trackstats/user_profile/update/(?P<object_id>\d{1,5})/', 'trackstats.views.user_profile_update', name='user_profile_update'),
url(r'^trackstats/gym/create/', 'trackstats.views.gym_create', name='gym_create'),
url(r'^trackstats/gym/update/(?P<object_id>\d{1,5})/', 'trackstats.views.gym_update', name='gym_update'),
url(r'^trackstats/workout/create/', 'trackstats.views.workout_create', name='workout_create'),
url(r'^trackstats/workout/update/(?P<object_id>\d{1,5})/', 'trackstats.views.workout_update', name='workout_update'),
url(r'^trackstats/workout/assign/', 'trackstats.views.workout_assign', name='workout_assign'),
)
「urls.py」中包含'user_profile_update'的相關行是什麼? –
添加了完整的urls.py文件。 – ghiotion
這個URL看起來很有意義。我已經用更多建議更新了我的答案。 –