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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:56:24+00:00 2026-06-01T22:56:24+00:00

lib.py from django.core.urlresolvers import reverse def render_reverse(f, kwargs): kwargs is a dictionary, usually of

  • 0

lib.py

from django.core.urlresolvers import reverse
def render_reverse(f, kwargs):
    """
    kwargs is a dictionary, usually of the form {'args': [cbid]}
    """
    return reverse(f, **kwargs)

tests.py

from lib import render_reverse, print_ls

class LibTest(unittest.TestCase):

def test_render_reverse_is_correct(self):
    #with patch('webclient.apps.codebundles.lib.reverse') as mock_reverse:
    with patch('django.core.urlresolvers.reverse') as mock_reverse:
        from lib import render_reverse
        mock_f = MagicMock(name='f', return_value='dummy_views')
        mock_kwargs = MagicMock(name='kwargs',return_value={'args':['123']})
        mock_reverse.return_value = '/natrium/cb/details/123'
        response = render_reverse(mock_f(), mock_kwargs())

        print mock_reverse.mock_calls  # prints []
    print mock_reverse.mock_calls  # prints []
    self.assertTrue('/natrium/cb/details/' in response)

But instead, I get

  File "/var/lib/graphyte-webclient/graphyte-webenv/lib/python2.6/site-packages/django/core/urlresolvers.py", line 296, in reverse
    "arguments '%s' not found." % (lookup_view_s, args, kwargs))
NoReverseMatch: Reverse for 'dummy_readfile' with arguments '('123',)' and keyword arguments '{}' not found.

Why is it calling reverse instead of my mock_reverse (it is looking up my urls.py!!)
You can see calls returns an empty list. I even assert mock_reverse.called and it returned false.

Maybe I haven’t mentioned this, but lib is just a bunch of functions, there is no class.

  • 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-01T22:56:25+00:00Added an answer on June 1, 2026 at 10:56 pm

    Two things. 1. You need to patch reverse from Django. 2. You need to do import inside the context manager, to make lib module import mocked reverse.

    from lib import print_ls
    
    class LibTest(unittest.TestCase):
    
        def test_render_reverse_is_correct(self):
            with patch('django.core.urlresolvers.reverse') as mock_reverse:
                from lib import render_reverse
                mock_f = MagicMock(name='f', return_value='dummy_view')
                mock_kwargs = MagicMock(name='kwargs',return_value={'args':['123']})
                mock_reverse.return_value = '/natrium/cb/details/123'
                response = render_reverse(mock_f, mock_kwargs)
    
            self.assertTrue('/natrium/cb/details/' in response)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this very basic problem, >>> from django.core import serializers >>> serializers.serialize(json, {'a':1})
When I import it inside a handler with this: from django.core.validators import email_re I
My code in myapp_extras.py: from django import template register = template.Library() @register.inclusion_tag('new/userinfo.html') def address():
I'm currently using the JPGEncoder from the AS3 core lib to encode a bitmap
I'm trying to import a model from a Django application and getting an error:
I have a model project_phase : from django.db import models from django.utils import simplejson
import os from os.path import abspath, dirname import sys # Set up django project_dir
from django.db import models class Post(models.Model): title = models.CharField(max_length=100) content = models.CharField(max_length=1000) created =
I follow the description on the http://docs.djangoproject.com/en/1.2/ref/contrib/sitemaps/ I from django.contrib import sitemaps add this
[Cross-posted from lib-curl mailing list] I have a single threaded app (MSVC C++ 2005)

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.