私のテスト:
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'),
)