Ticket #7982: 7982_against_trunk.diff

File 7982_against_trunk.diff, 2.8 KB (added by sebastian.hillig, 16 years ago)

Patch, doesn't fix /add/ but the other two cases, adds test for all three

  • django/contrib/admin/options.py

     
    181181        # Delegate to the appropriate method, based on the URL.
    182182        if url is None:
    183183            return self.changelist_view(request)
    184         elif url.endswith('add'):
     184        elif url == "add":
    185185            return self.add_view(request)
    186         elif url.endswith('history'):
     186        elif url.endswith('/history'):
    187187            return self.history_view(request, unquote(url[:-8]))
    188         elif url.endswith('delete'):
     188        elif url.endswith('/delete'):
    189189            return self.delete_view(request, unquote(url[:-7]))
    190190        else:
    191191            return self.change_view(request, unquote(url))
  • tests/regressiontests/admin_views/tests.py

     
    450450        response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/delete/' % quote(self.pk))
    451451        should_contain = """<a href="../../%s/">%s</a>""" % (quote(self.pk), escape(self.pk))
    452452        self.assertContains(response, should_contain)
     453   
     454    def test_url_conflicts_with_add(self):
     455        "A model with a primary key that ends with add should be visible"
     456        add_model = ModelWithStringPrimaryKey(id="i have something to add")
     457        add_model.save()
     458        response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(add_model.pk))
     459        should_contain = """<h1>Change model with string primary key</h1>"""
     460        self.assertContains(response, should_contain)
     461   
     462    def test_url_conflicts_with_delete(self):
     463        "A model with a primary key that ends with delete should be visible"
     464        delete_model = ModelWithStringPrimaryKey(id="delete")
     465        delete_model.save()
     466        response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(delete_model.pk))
     467        should_contain = """<h1>Change model with string primary key</h1>"""
     468        self.assertContains(response, should_contain)
     469   
     470    def test_url_conflicts_with_history(self):
     471        "A model with a primary key that ends with history should be visible"
     472        history_model = ModelWithStringPrimaryKey(id="history")
     473        history_model.save()
     474        response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(history_model.pk))
     475        should_contain = """<h1>Change model with string primary key</h1>"""
     476        self.assertContains(response, should_contain)
     477       
    453478
    454479class SecureViewTest(TestCase):
    455480    fixtures = ['admin-views-users.xml']
Back to Top