1

に行くとhttp://localhost:8000/login/、ログインフォームが表示されるので、 と を入力usernamepasswordます。資格情報が正しい場合は、にリダイレクトされhttp://localhost:8000/dashboard/ます。usernameテスト中に私が直面している問題は、私のとpasswordが正しいにもかかわらず、リダイレクトされずhttp://localhost:8000/dashboard/http://testserver/admin/login/?next=/dashboard/. 以下のコードを使用して、django のリダイレクト機能を停止しています。

class UrlTests(TestCase):

    def test_client_cart(self):
        response = self.client.get('/login/')
        self.assertEqual(200, response.status_code)

    def test_login_client(self):
        User.objects.create_user('rakesh', 'rrs402@nyu.edu', 'ranjan')
        self.client.get('/login/')
        self.client.login(username='rakesh', password='ranjan')
        print self.client.get('/dashboard/')

http://testserver/admin/login/?next=/dashboard/代わりにリダイレクトされる理由を誰か教えてくださいhttp://localhost:8000/dashboard/

私のsettings.pyファイルでは:

LOGIN_URL = '/'
LOGOUT_URL = '/logout/'
LOGIN_REDIRECT_URL = '/dashboard/'
LOGOUT_REDIRECT_URL = '/'

アプリケーションは正常に動作していますが、リダイレクトをテストできません。誰かが私が間違っている場所を教えてもらえますか?

印刷するprint self.client.login(username='rakesh', password='ranjan')True、ログインできることを意味しますが、リダイレクトできないのはなぜですか?

更新:セレンも使ってみました

def login_user(self):
        # User opens his web browser, and goes to the website
        self.browser.get(self.live_server_url + '/login/')
        # User types in his username and passwords and hits return
        username_field = self.browser.find_element_by_name('username')
        username_field.send_keys('rakesh')
        password_field = self.browser.find_element_by_name('password')
        password_field.send_keys('ranjan')
        #User submits the form
        password_field.send_keys(Keys.RETURN)
        body = self.browser.find_element_by_tag_name('body')
        print body.text

ここでもページの body.text を取得していますが、adminページは取得していませんdashboard

アップデート :

ダッシュボード ビュー:

class PortalDashboardView(RequireStaffMixinView, TemplateView):
    template_name = "portal/dashboard.html"
4

1 に答える 1