#10899: easier manipulation of sessions by test client
---------------------------------------+-----------------------------------
               Reporter:  tallfred     |          Owner:  nobody
                   Type:  New feature  |         Status:  reopened
              Milestone:               |      Component:  Testing framework
                Version:  SVN          |       Severity:  Normal
             Resolution:               |       Keywords:
           Triage Stage:  Accepted     |      Has patch:  1
    Needs documentation:  0            |    Needs tests:  0
Patch needs improvement:  1            |  Easy pickings:  0
---------------------------------------+-----------------------------------
Changes (by mir):

 * needs_better_patch:  0 => 1


Comment:

 Thanks for the updated patch!

 With the patch, I ran the test suite (using the supplied test_sqlite
 settings). There are a few tests that check the number of queries, so a
 failure is no surprise. But the strange thing is: I get 9 queries instead
 of 1. Why so many? And how do we want to deal with the problem that the
 patch might break users' test suite? I have no idea what the policy is,
 but IMHO it should be expected that the number of SQL queries can change
 with a new release.

 But in any case, your patch needs to modify the affected tests in the
 Django test suite.

 Here's the test run:

 {{{
 > ./tests/runtests.py --settings=test_sqlite test_utils
 Creating test database for alias 'default'...
 Creating test database for alias 'other'...
 ..F.F...
 ======================================================================
 FAIL: test_with_client
 (regressiontests.test_utils.tests.AssertNumQueriesContextManagerTests)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File
 
"/home/mir/kunden/django/workspace/django/tests/regressiontests/test_utils/tests.py",
 line 80, in test_with_client
     self.client.get("/test_utils/get_person/%s/" % person.pk)
   File "/home/mir/kunden/django/workspace/links/django/test/testcases.py",
 line 234, in __exit__
     executed, self.num
 AssertionError: 9 queries executed, 1 expected

 ======================================================================
 FAIL: test_assert_num_queries_with_client
 (regressiontests.test_utils.tests.AssertNumQueriesTests)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File
 
"/home/mir/kunden/django/workspace/django/tests/regressiontests/test_utils/tests.py",
 line 38, in test_assert_num_queries_with_client
     "/test_utils/get_person/%s/" % person.pk
   File "/home/mir/kunden/django/workspace/links/django/test/testcases.py",
 line 537, in assertNumQueries
     func(*args, **kwargs)
   File "/home/mir/kunden/django/workspace/links/django/test/testcases.py",
 line 234, in __exit__
     executed, self.num
 AssertionError: 9 queries executed, 1 expected

 ----------------------------------------------------------------------
 Ran 8 tests in 0.025s

 FAILED (failures=2)
 }}}

 I have another rather formal suggestion regarding your patch: Your patch
 changes the number of blank lines between functions in a few places. It
 shouldn't, first because 2 blank lines are standard in all Django files,
 second you should not touch code places that are not really related to the
 ticket, this can get a real hassle when merging in other changes. Would
 you like to clean this up by yourself?

 Re documentation: It is a bit short but might be sufficient. I don't like
 the wording, but I'm no native speaker and I guess the final committer
 will polish it up anyway. But ... I think the preceding paragraph does not
 apply after your patch, does it?

 {{{
     To modify the session and then save it, it must be stored in a
 variable
     first (because a new ``SessionStore`` is created every time this
 property
     is accessed)::

         def test_something(self):
             session = self.client.session
             session['somekey'] = 'test'
             session.save()
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/10899#comment:14>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to