Ticket #17497: 170988ee0f93c74d7c21661663940c5fc7e6928b.patch

File 170988ee0f93c74d7c21661663940c5fc7e6928b.patch, 1.3 KB (added by Jonas Obrist, 13 years ago)

test case

  • tests/modeltests/many_to_one/tests.py

    From 170988ee0f93c74d7c21661663940c5fc7e6928b Mon Sep 17 00:00:00 2001
    From: Jonas Obrist <ojiidotch@gmail.com>
    Date: Tue, 3 Jan 2012 14:27:01 +0100
    Subject: [PATCH] added a test illustrating potentially confusing exception
     messages when using values_list and spanning relations
    
    ---
     tests/modeltests/many_to_one/tests.py |    6 +++++-
     1 files changed, 5 insertions(+), 1 deletions(-)
    
    diff --git a/tests/modeltests/many_to_one/tests.py b/tests/modeltests/many_to_one/tests.py
    index 922506e..3e3c341 100644
    a b  
    33from copy import deepcopy
    44from datetime import datetime
    55
    6 from django.core.exceptions import MultipleObjectsReturned
     6from django.core.exceptions import MultipleObjectsReturned, FieldError
    77from django.test import TestCase
    88
    99from .models import Article, Reporter
    def test_manager_class_caching(self):  
    411411
    412412        # Same as each other
    413413        self.assertTrue(r1.article_set.__class__ is r2.article_set.__class__)
     414       
     415    def test_values_list_exception(self):
     416        expected_message = "Cannot resolve keyword 'notafield' into field. Choices are: %s" % ', '.join(Reporter._meta.get_all_field_names())
     417        self.assertRaisesMessage(FieldError, expected_message, Article.objects.values_list, 'reporter__notafield')
Back to Top