Django

Code

Changeset 7578

Show
Ignore:
Timestamp:
06/06/08 08:50:02 (4 months ago)
Author:
russellm
Message:

Fixed #7165 -- Added an assertNotContains() method to the test client. Thanks for the suggestion and implementation, J. Pablo Fernandez <pupeno@pupeno.com>.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/AUTHORS

    r7565 r7578  
    143143    Stefane Fermgier <sf@fermigier.com> 
    144144    Afonso Fernández Nogueira <fonzzo.django@gmail.com> 
     145        J. Pablo Fernandez <pupeno@pupeno.com> 
    145146    Matthew Flanagan <http://wadofstuff.blogspot.com> 
    146147    Eric Floehr <eric@intellovations.com> 
  • django/trunk/django/test/testcases.py

    r7056 r7578  
    128128            self.failUnless(real_count != 0, 
    129129                            "Couldn't find '%s' in response" % text) 
     130 
     131    def assertNotContains(self, response, text, status_code=200): 
     132        """ 
     133        Asserts that a response indicates that a page was retrieved 
     134        successfully, (i.e., the HTTP status code was as expected), and that 
     135        ``text`` doesn't occurs in the content of the response. 
     136        """ 
     137        self.assertEqual(response.status_code, status_code, 
     138            "Couldn't retrieve page: Response code was %d (expected %d)'" % 
     139                (response.status_code, status_code)) 
     140        self.assertEqual(response.content.count(text), 0, 
     141                         "Response should not contain '%s'" % text) 
    130142 
    131143    def assertFormError(self, response, form, field, errors): 
  • django/trunk/docs/testing.txt

    r7368 r7578  
    823823    provided, ``text`` must occur exactly ``count`` times in the response. 
    824824 
     825``assertNotContains(response, text, status_code=200)`` 
     826    Asserts that a ``Response`` instance produced the given ``status_code`` and 
     827    that ``text`` does not appears in the content of the response. 
     828 
    825829``assertFormError(response, form, field, errors)`` 
    826830    Asserts that a field on a form raises the provided list of errors when 
     
    837841    ``errors`` is an error string, or a list of error strings, that are 
    838842    expected as a result of form validation. 
     843 
     844``assertTemplateUsed(response, template_name)`` 
     845    Asserts that the template with the given name was used in rendering the 
     846    response. 
     847 
     848    The name is a string such as ``'admin/index.html'``. 
    839849 
    840850``assertTemplateNotUsed(response, template_name)`` 
     
    846856    it redirected to ``expected_url`` (including any GET data), and the subsequent 
    847857    page was received with ``target_status_code``. 
    848  
    849 ``assertTemplateUsed(response, template_name)`` 
    850     Asserts that the template with the given name was used in rendering the 
    851     response. 
    852  
    853     The name is a string such as ``'admin/index.html'``. 
    854858 
    855859E-mail services 
  • django/trunk/tests/regressiontests/test_client_regress/models.py

    r7330 r7578  
    1212        response = self.client.get('/test_client_regress/no_template_view/') 
    1313 
     14        self.assertNotContains(response, 'never') 
    1415        self.assertContains(response, 'never', 0) 
    1516        self.assertContains(response, 'once') 
     
    1920 
    2021        try: 
     22            self.assertNotContains(response, 'once') 
     23        except AssertionError, e: 
     24            self.assertEquals(str(e), "Response should not contain 'once'") 
     25             
     26        try: 
    2127            self.assertContains(response, 'never', 1) 
    2228        except AssertionError, e: