summaryrefslogtreecommitdiff
path: root/tests/admin_docs
diff options
context:
space:
mode:
authorZan Anderle <zan.anderle@gmail.com>2014-10-30 20:45:01 +0100
committerTim Graham <timograham@gmail.com>2015-09-07 15:07:39 -0400
commitf3dc173240d2a91c831b08dd6820e1d83322f3da (patch)
tree99567a09fd1818664a81f97b2491b9f43002df1a /tests/admin_docs
parent3c5862ccb0fc77418c3b20c21c6b57c40b483464 (diff)
downloaddjango-f3dc173240d2a91c831b08dd6820e1d83322f3da.tar.gz
Fixed #24917 -- Made admindocs display model methods that take arguments.
Diffstat (limited to 'tests/admin_docs')
-rw-r--r--tests/admin_docs/models.py11
-rw-r--r--tests/admin_docs/tests.py33
2 files changed, 43 insertions, 1 deletions
diff --git a/tests/admin_docs/models.py b/tests/admin_docs/models.py
index 9ddcb762e1..a425ae0fcd 100644
--- a/tests/admin_docs/models.py
+++ b/tests/admin_docs/models.py
@@ -44,6 +44,17 @@ class Person(models.Model):
def _get_full_name(self):
return "%s %s" % (self.first_name, self.last_name)
+ def rename_company(self, new_name):
+ self.company.name = new_name
+ self.company.save()
+ return new_name
+
+ def dummy_function(self, baz, rox, *some_args, **some_kwargs):
+ return some_kwargs
+
+ def suffix_company_name(self, suffix='ltd'):
+ return self.company.name + suffix
+
def add_image(self):
pass
diff --git a/tests/admin_docs/tests.py b/tests/admin_docs/tests.py
index 7619e01465..ff860f9929 100644
--- a/tests/admin_docs/tests.py
+++ b/tests/admin_docs/tests.py
@@ -246,7 +246,7 @@ class TestModelDetailView(TestDataMixin, AdminDocsTestCase):
def setUp(self):
self.client.login(username='super', password='secret')
with captured_stderr() as self.docutils_stderr:
- self.response = self.client.get(reverse('django-admindocs-models-detail', args=['admin_docs', 'person']))
+ self.response = self.client.get(reverse('django-admindocs-models-detail', args=['admin_docs', 'Person']))
def test_method_excludes(self):
"""
@@ -261,6 +261,34 @@ class TestModelDetailView(TestDataMixin, AdminDocsTestCase):
self.assertNotContains(self.response, "<td>set_status</td>")
self.assertNotContains(self.response, "<td>save_changes</td>")
+ def test_methods_with_arguments(self):
+ """
+ Methods that take arguments should also displayed.
+ """
+ self.assertContains(self.response, "<h3>Methods with arguments</h3>")
+ self.assertContains(self.response, "<td>rename_company</td>")
+ self.assertContains(self.response, "<td>dummy_function</td>")
+ self.assertContains(self.response, "<td>suffix_company_name</td>")
+
+ def test_methods_with_arguments_display_arguments(self):
+ """
+ Methods with arguments should have their arguments displayed.
+ """
+ self.assertContains(self.response, "<td>new_name</td>")
+
+ def test_methods_with_arguments_display_arguments_default_value(self):
+ """
+ Methods with keyword arguments should have their arguments displayed.
+ """
+ self.assertContains(self.response, "<td>suffix=&#39;ltd&#39;</td>")
+
+ def test_methods_with_multiple_arguments_display_arguments(self):
+ """
+ Methods with multiple arguments should have all their arguments
+ displayed, but omitting 'self'.
+ """
+ self.assertContains(self.response, "<td>baz, rox, *some_args, **some_kwargs</td>")
+
def test_method_data_types(self):
"""
We should be able to get a basic idea of the type returned
@@ -368,6 +396,9 @@ class TestModelDetailView(TestDataMixin, AdminDocsTestCase):
self.assertContains(self.response, body, html=True)
self.assertContains(self.response, model_body, html=True)
+ def test_model_detail_title(self):
+ self.assertContains(self.response, '<h1>admin_docs.Person</h1>', html=True)
+
@unittest.skipUnless(utils.docutils_is_available, "no docutils installed.")
class TestUtils(AdminDocsTestCase):