Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7499047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:40:56+00:00 2026-05-29T19:40:56+00:00

I’m using django_webtest to test my application. I faced with problem when try to

  • 0

I’m using django_webtest to test my application. I faced with problem when try to test sign-up page. This page should create user and make other initial actions, authenticate newly created user and redirect it to the page specified in next parameter of GET request.

Here is the code of view method:

def _redirect_path(referrer, restricted_paths=()):
if not referrer or referrer in (reverse(name) for name in restricted_paths):
    return reverse('home')
else:
    return referrer

...

def sign_up(request):
if request.user.is_authenticated():
    return redirect(reverse('home'))
if request.method == 'POST':
    form = forms.SignUpForm(request.POST)
    if form.is_valid():
        with transaction.commit_on_success():
            user = form.save()
            profile = Profile.objects.create(user=user)
            tokens.create_token(profile, 'unsubscribe')
            mail.send_welcome_letter(request, user)
        messages.success(request, _('You have successfully signed up. Welcome!'))
        authenticated_user = auth.authenticate(username=user.username, password=form.cleaned_data['password'])
        if authenticated_user:
            auth.login(request, authenticated_user)
            remember_user(request, authenticated_user)
            redirect_path = _redirect_path(form.clean_referrer(), ('password_reset', 'sign_up'))
            return redirect(redirect_path)
        else:
            raise Exception("Newly created user couldn't be authenticated.")
else:
    referrer = request.GET.get('next')
    form = forms.SignUpForm(initial={'referrer': referrer})

return render_to_response('sign_up.html', {'form': form}, context_instance=RequestContext(request))

Now I try to test its behavior when user entered example.com/sign_up/?next=/settings/ in his browser, fill all fields of form correctly and submit it.

View that handles /settings/ has decorator @login_required, but after user is successfully signed up, he should be authenticated, so I expect that after submit user will go to example.com/settings/ (and he goes when I test it manually).

But when I run test:

def test_user_creation_redirect_to_settings(self):
    form = self.app.get('/sign_up/', {'next': '/settings/'}).form
    self.fill_sign_up_form(form)
    submit_response = form.submit()
    self.assertRedirects(submit_response, '/settings/')

it returns “AssertionError: Couldn’t retrieve redirection page ‘/settings/’: response code was 302 (expected 200)”. When I debugged, I have seen that *submit_response* is really 302 FOUND with location path /settings/. But when method assertRedirects tries to get target page, it faces with redirect again – example.com/settings/ redirects to example.com/login/?next=/settings/. So user is not logged in after submit.

OK, I tried to log in him with test client’s login method:

def test_user_creation_redirect_to_settings(self):
    form = self.app.get('/sign_up/', {'next': '/settings/'}).form
    self.fill_sign_up_form(form)
    submit_response = form.submit()

    submit_response.client.login(username='User', password='secret')

    self.assertRedirects(submit_response, '/settings/')

But still the same. Seems, this method is not works:

def test_user_creation_redirect_to_settings(self):
    form = self.app.get('/sign_up/', {'next': '/settings/'}).form
    self.fill_sign_up_form(form)
    submit_response = form.submit()

    inside = self.client.login(username='User', password='secret')
    print inside and 'Login successful in self client'
    print 'Authenticated: %s' % bool('_auth_user_id' in self.client.session)

    inside = submit_response.client.login(username='User', password='secret')
    print inside and 'Login successful in response client'
    print 'Authenticated: %s' % bool('_auth_user_id' in submit_response.client.session)

prints

    Login successful in self client
    Authenticated: True
    Login successful in response client
    Authenticated: False

Could you please help me to understand why login functionality doesn’t work in test case and how to log in user before redirect.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T19:40:57+00:00Added an answer on May 29, 2026 at 7:40 pm

    Have you tried using the follow method in your tests? Doing so follows redirects.

    form.submit().follow()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.