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 8770711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:36:38+00:00 2026-06-13T17:36:38+00:00

I have a view as such: def ProjectInfo(request): if request.method == ‘POST’: form =

  • 0

I have a view as such:

def ProjectInfo(request):
    if request.method == 'POST':
        form = ProjectInfoForm(request.POST)
        if form.is_valid():
            # if form is valid, iterate cleaned form data
            # and save data to session
            for k, v in form.cleaned_data.iteritems():
                request.session[k] = v
            return HttpResponseRedirect('/next/')
        else:
            ...
    else:
        ...

And in my tests:

from django.test import TestCase, Client
from django.core.urlresolvers import reverse
from tool.models import Module, Model
from django.contrib.sessions.models import Session

def test_project_info_form_post_submission(self):
    """
    Test if project info form can be submitted via post.
    """
    # set up our POST data
    post_data = {
        'zipcode': '90210',
        'module': self.module1.name,
        'model': self.model1.name,
        'orientation': 1,
        'tilt': 1,
        'rails_direction': 1,
    }
    ...
    self.assertEqual(response.status_code, 302)
    # test if 'zipcode' in session is equal to posted value.

So, where the last comment is in my test, I want to test if a specific value is in the session dict and that the key:value pairing is correct. How do I go about this? Can I use request.session?

Any help much appreciated.

  • 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-06-13T17:36:40+00:00Added an answer on June 13, 2026 at 5:36 pm

    According to the docs:

    from django.test import TestCase
    
    class SimpleTest(TestCase):
        def test_details(self):
            # Issue a GET request.
            self.client.get('/customer/details/')
            session = self.client.session
            self.assertEqual(session["somekey"], "test")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a things resource with a view helper method such as: module
I have such code, for making chain selects in my form View for index
I have such view that handles user registration. After creating new user i want
Suppose I'm implementing an MVP pattern and I have a view interface as such:
I have such stuff in my django view: message = 'sometext' rating = 7
I have such controller: def accumulators @pre_accums = Accumulator.all @accums = Kaminari.paginate_array(@pre_accums).page(params[:page]).per(20) end and
I'm using devise gem and showing user's objects on registrations/edit view. I have such
Code: # it's an ajax request, so parameters are passed via GET method def
I have the following decorator and view which works fine. Decorator def event_admin_only(func): Checks
I have code like the following ( it's a remote form ) def something

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.