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

  • Home
  • SEARCH
  • 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 5950437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:23:36+00:00 2026-05-22T17:23:36+00:00

I am using Mock and I am not able to patch django’s render_to_response function

  • 0

I am using Mock and I am not able to patch django’s render_to_response function properly. For e.g., the following test never fails:

    from django.test.client import Client
    from mock import patch
    import nose.tools as nt

    @patch('django.shortcuts.render_to_response')
    def test_should_fail(self, render_to_response):
        def assert_response(url, context, context_instance):
            nt.assert_false(True)
        render_to_response.side_effect = assert_response
        response = Client().get('/some/url/')

What am I doing wrong?

Update: The reason I want to do this is that in my view, I am rendering the response like:

form = SomeFormClass(label_suffix='')
return render_to_response('admin/send_info_message.html', {'form': form,}, context_instance=RequestContext(request))

In my test, I want to test that these parameters are correctly called, like:

 def assert_response(url, context, context_instance):
     nt.assert_equal('admin/survey_question.html', url)
     nt.assert_equal({'form': SomeForm()}, context)
     nt.assert_equal(RequestContext(response.request), context_instance)

 render_to_response.side_effect = assert_response
  • 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-22T17:23:37+00:00Added an answer on May 22, 2026 at 5:23 pm

    Firstly, why do you want to do this?

    Secondly, the place you should patch a function is the place you are calling it – ie in the views module that handles the relevant URL. For example:

    @patch('myapp.views.render_to_response')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to be able to test a class initialises correctly using Moq: class
I have the following methods.. I'd like to be able to mock something up
I'm using the garb gem to pull some basic stats, like pageviews, from Google
I'm using factory_girl + rspec on Rails 2-3-stable: Test: context test do before(:each) do
I'm just getting into Test Driven Development with mock objects. I can do it
I am using EF4 CPT4 Code first and I have setup my ObjectContext to
I was playing around with testing using machine specifications and there is something that
We're using EF Code first, and have a data context for our sales database.
I know similar questions have been asked, e.g. here , but having done a
I'm pretty new to java programming and am looking to do basic data mappings.

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.