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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:24:32+00:00 2026-05-12T18:24:32+00:00

I am using the Django testing framework (which is useful, but feels clunky and

  • 0

I am using the Django testing framework (which is useful, but feels clunky and awkward). A test keeps failing, and the traceback leads me to believe it’s an issue with the login decorators. Here are the tests, the error, and the relevant code:

class TestMain(TestCase):
    fixtures = ['timetracker']

    def test_login(self):
        c = Client()
        login = c.login(username='testclient', password='not.a.real.password')
        self.failUnless(login, 'Could not log in')

    def test_main(self):
        c = Client()
        login = c.login(username='testclient', password='not.a.real.password')
        self.failUnless(login, 'Could not log in')

        response = c.get('/', follow=True)
        print response.content
        #assert response.status_code == 200, response.status_code




markov:biorhythm vinceb$ nosetests -v --with-django
test_login (biorhythm.timetracker.tests.test_urls.TestMain) ... ok
test_main (biorhythm.timetracker.tests.test_urls.TestMain) ... ERROR

======================================================================
ERROR: test_main (biorhythm.timetracker.tests.test_urls.TestMain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/vinceb/Code/python/biorhythm/timetracker/tests/test_urls.py", line 20, 

in test_main
        response = c.get('/', follow=True)
      File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/test/client.py", line 281, in get
 [...]
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/template/__init__.py", line 792, in render_node
        return node.render(context)
      File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/template/defaulttags.py", line 382, in render
        raise e
    NoReverseMatch: Reverse for '<django.contrib.auth.decorators._CheckLogin object at 0x22d4650>' with arguments '()' and keyword arguments '{'report_type': u'this_week'}' not found.

----------------------------------------------------------------------
Ran 2 tests in 1.112s

FAILED (errors=1)
Destroying test database...
markov:biorhythm vinceb$ 






@login_required
def time(request):
    # initials
    from biorhythm.timetracker.forms import TimeForm, TimeFormSet
    from django.forms.formsets import formset_factory

    # instantiate our formset factory
    TimeSet = formset_factory(TimeForm, extra=1)
    formset = None

    # sorting worklogs
    order_by = ordered(request)
    success = None

What’s really strange is that keyword args being inserted into the request, leading me to think it’s a template request.

EDIT: more code

urlpatterns = patterns('biorhythm.timetracker.views',

    # Home
    url(r'^/?$', 'time', name='home'),

    # CSV exports
    url(r'^reports/csv/(?P<from_date>\d{8})/(?P<to_date>\d{8})/?$', 'export_csv_report', name='csv_out'),   
    url(r'^dashboard/csv/?$', 'export_qbcsv', name='csv_report'),

    # Reports
    url(r'^summary/?$', 'reports', name='reports'),
    (r'^summary/(?P<from_date>\d{8})/(?P<to_date>\d{8})/?$', 'reports'),
    (r'^summary/(?P<report_type>.*?)/?$', 'reports'),

    # test
    (r'new_dashboard/$', 'new_dashboard'),
    url(r'remove_query/(?P<position>.*?)/$', 'remove_query', name='remove_query'),


    # Aggregate timesheets
    url(r'^dashboard/$', 'new_dashboard', name='dashboard'),
    url(r'old_dashboard/$', 'dashboard', name='old_dashboard'),
    (r'^dashboard/(?P<user_id>.*?)/?$', 'dashboard'),
    (r'^dashboard/(?P<from_date>\d{8})/(?P<to_date>\d{8})/?$', 'dashboard'),
)



@login_required
def time(request):
    # initials
    from biorhythm.timetracker.forms import TimeForm, TimeFormSet
    from django.forms.formsets import formset_factory

    # instantiate our formset factory
    TimeSet = formset_factory(TimeForm, extra=1)
    formset = None

    # sorting worklogs
    order_by = ordered(request)
    success = None

    if request.method == 'POST':
        from django.contrib.admin.models import LogEntry, ADDITION
        from django.contrib.contenttypes.models import ContentType
        # we have to make sure we have a matching contenttype for this model
        # normally we will, but first entry may not have this
        worklog, created = ContentType.objects.get_or_create(name='worklog', app_label='timetracker', model='worklog')

        # pertinent fields
        dats = 'project duration note category start_date'.split()

        # instantiate formset
        formset = TimeSet(request.POST)
        for i, form in enumerate(formset.forms):
            labs = ['form-%d-%s' % (i, d) for d in dats]
            project, duration, note, category, start_date = [request.POST.get(l, None) for l in labs]
            check_against = [project, duration, note, start_date] 

            # Checks that required fields have been filled with input longer than 0.
            if 0 not in [len(x) for x in check_against]:
                if form.is_valid():
                    project, duration, note, category, start_date = [form.cleaned_data.get(l, None) for l in dats]

                    if None not in check_against:
                        # this is a form we can process & save so let's
                        # get our pk for logging activity
                        instance = form.save(commit=False)
                        if instance:
                            # default values and save again
                            instance.start_date = form.cleaned_data.get('start_date')
                            instance.user = request.user
                            instance.save()

                            # Output a nice message to the client
                            s = 's' if duration > 1 else '' # pluralization!
                            message = "%s hour%s spent %s on %s" % (duration, s, note, project.name)
                            request.user.message_set.create(message=message)

                            # Append this action (addition) to the LogEntry table
                            _send_LogEntry(request.user.pk, worklog.id, worklog.id,
                                           force_unicode(project), message)


                            success = True
                else:
                    # Form _not_ valid. Continue outputting the formset with error messages.
                    pass
            else:
                # Form missing required field
                continue  
        if success is True:
            return http.HttpResponseRedirect(request.get_full_path())

    # get our data
    worklogs = Worklog.objects.select_related().filter(user=request.user.id).order_by(order_by, '-id')
    time_week = worklogs.filter(start_date__gte=start_of_week()).aggregate(Sum('duration'))
    time_day = worklogs.filter(start_date__gte=today()).aggregate(Sum('duration'))
    #time_week = worklogs.filter(start_date__gte=start_of_week()).objects.objects.get_total_time()
    #time_day = worklogs.filter(start_date__gte=today()).objects.get_total_time()

    reports = return_time_report()

    # instantiate projects for initial data for form for the last 14 days
    # was 30 days, now 14 at Nik's request -J
    month = datetime.timedelta(days=14)
    worklog_projects = worklogs.filter(start_date__gte=today()-month)
    projects = dict.fromkeys([p.project for p in worklog_projects]).keys()

    if not formset:
        initial_data = [{'project':p.id, 'start_date':'today'} for p in projects]
        formset = TimeSet(initial=initial_data)
    has_logs = True if int(worklogs.count()) > 0 else False
    logs = paginate(request, worklogs, 'worklogs')
    logs_list = logs.object_list


    # Initialize categories from a query object, so they can be sent to JQuery
    # via JSON to make auto-complete work.
    cat_list = []
    for c in Category.objects.all():
        cat_list.append(dict(id=str(c.id), name=c.name))
    cats = json.dumps(cat_list)


    context = RequestContext(request)
    return render_to_response('log.html', {'formset':formset, 'worklogs':logs_list, 'v':locals(), 't':reports}, context)

That’s the entire view.

This is a huge post, so the template is here: http://dpaste.com/110860/

  • 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-12T18:24:32+00:00Added an answer on May 12, 2026 at 6:24 pm

    The error log reported there tells you most of what you need to know:

    First you’ve got:

    in test_main
            response = c.get('/', follow=True)
    

    Which means it’s dying while trying to process that request. Next:

          File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/test/client.py", line 281, in get
     [...]
    "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/template/__init__.py", line 792, in render_node
            return node.render(context)
    

    It’s dying while rendering a node in the template, which means it’s getting to the template, not dying at the login. Last:

          File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/template/defaulttags.py", line 382, in render
            raise e
        NoReverseMatch: Reverse for '<django.contrib.auth.decorators._CheckLogin object at 0x22d4650>' with arguments '()' and keyword arguments '{'report_type': u'this_week'}' not found.
    

    It’s raising an exception while trying to reverse a url in your template, which means you called the {% url %} tag somewhere with the path to your view function and the argument “this_week”, but that’s not the appropriate way to call your view function according to your URLconf.

    Fix your {% url %} tag or your view function definition and it’ll work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to automate 404 pages testing using Django 1.4's testing framework. If
I'm testing a django project using the test sever when it gives me the
I am using unittest.TestCase to write test cases for my django app (which is
I'm using the python version of selenium for some testing with django, but firefox
I'm using this django app to implement PayPal IPN. I'm testing it using PayPal's
Using django, which is the way to check if data is present? I know
Using django comments framework http://docs.djangoproject.com/en/dev/ref/contrib/comments/ Not sure is there option, to make all comments
I am developing a small testing website using Django 1.2 in Aptana Studio build
Hi i am using django 1.2 .I my case i have few models which
I'm testing out using memcached to cache django views. How can I tell if

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.