浏览代码

Add docs & unit tests for assertCanCreate with publish (#9458)

- Builds on #9458
DokuaAsiedu 2 年之前
父节点
当前提交
af9f7ecbb3
共有 5 个文件被更改,包括 14 次插入1 次删除
  1. 1 0
      CHANGELOG.txt
  2. 1 0
      CONTRIBUTORS.rst
  3. 3 1
      docs/advanced_topics/testing.md
  4. 1 0
      docs/releases/4.2.md
  5. 8 0
      wagtail/tests/test_tests.py

+ 1 - 0
CHANGELOG.txt

@@ -8,6 +8,7 @@ Changelog
  * Remove unsquashed `testapp` migrations (Matt Westcott)
  * Remove unsquashed `testapp` migrations (Matt Westcott)
  * Switch to using Willow instead of Pillow for images (Darrel O'Pry)
  * Switch to using Willow instead of Pillow for images (Darrel O'Pry)
  * Add documentation for how to get started with contributing translations for the Wagtail admin (Ogunbanjo Oluwadamilare)
  * Add documentation for how to get started with contributing translations for the Wagtail admin (Ogunbanjo Oluwadamilare)
+ * Test assertion util `WagtailPageTestCase.assertCanCreate` now supports the kwarg `publish=True` to check publish redirection (Harry Percival, Akua Dokua Asiedu)
  * Fix: Make sure workflow timeline icons are visible in high-contrast mode (Loveth Omokaro)
  * Fix: Make sure workflow timeline icons are visible in high-contrast mode (Loveth Omokaro)
  * Fix: Ensure authentication forms (login, password reset) have a visible border in Windows high-contrast mode (Loveth Omokaro)
  * Fix: Ensure authentication forms (login, password reset) have a visible border in Windows high-contrast mode (Loveth Omokaro)
  * Fix: Ensure visual consistency between buttons and links as buttons in Windows high-contrast mode (Albina Starykova)
  * Fix: Ensure visual consistency between buttons and links as buttons in Windows high-contrast mode (Albina Starykova)

+ 1 - 0
CONTRIBUTORS.rst

@@ -653,6 +653,7 @@ Contributors
 * Ogunbanjo Oluwadamilare
 * Ogunbanjo Oluwadamilare
 * Damee Zivah Olawuyi
 * Damee Zivah Olawuyi
 * Harry Percival
 * Harry Percival
+* Akua Dokua Asiedu
 
 
 Translators
 Translators
 ===========
 ===========

+ 3 - 1
docs/advanced_topics/testing.md

@@ -140,11 +140,13 @@ def test_cant_create_under_event_page(self):
     self.assertCanNotCreateAt(EventPage, ContentPage)
     self.assertCanNotCreateAt(EventPage, ContentPage)
 ```
 ```
 
 
-**assertCanCreate(_parent, child_model, data, msg=None_)**
+**assertCanCreate(_parent, child_model, data, msg=None_, publish=True)**
 Assert that a child of the given Page type can be created under the parent, using the supplied POST data.
 Assert that a child of the given Page type can be created under the parent, using the supplied POST data.
 
 
 `parent` should be a Page instance, and `child_model` should be a Page subclass. `data` should be a dict that will be POSTed at the Wagtail admin Page creation method.
 `parent` should be a Page instance, and `child_model` should be a Page subclass. `data` should be a dict that will be POSTed at the Wagtail admin Page creation method.
 
 
+`publish` specifies whether the page being created should be published or not, default is `False`. When `True`, it checks if the response url includes the url of the Wagtail Explorer Page, displaying an error if does not include that url. Otherwise it checks that the correct edit page loads.
+
 ```python
 ```python
 from wagtail.test.utils.form_data import nested_form_data, streamfield
 from wagtail.test.utils.form_data import nested_form_data, streamfield
 
 

+ 1 - 0
docs/releases/4.2.md

@@ -18,6 +18,7 @@ depth: 1
  * Wagtail's documentation (v2.9 to v4.0) has been updated on [Dash user contributions](https://github.com/Kapeli/Dash-User-Contributions) for [Dash](https://kapeli.com/dash) or [Zeal](https://zealdocs.org/) offline docs applications (Damilola Oladele, (Mary Ayobami)
  * Wagtail's documentation (v2.9 to v4.0) has been updated on [Dash user contributions](https://github.com/Kapeli/Dash-User-Contributions) for [Dash](https://kapeli.com/dash) or [Zeal](https://zealdocs.org/) offline docs applications (Damilola Oladele, (Mary Ayobami)
  * Switch to using [Willow](https://github.com/wagtail/Willow/) instead of Pillow for images (Darrel O'Pry)
  * Switch to using [Willow](https://github.com/wagtail/Willow/) instead of Pillow for images (Darrel O'Pry)
  * Add documentation for how to get started with [contributing translations](contributing_translations) for the Wagtail admin (Ogunbanjo Oluwadamilare)
  * Add documentation for how to get started with [contributing translations](contributing_translations) for the Wagtail admin (Ogunbanjo Oluwadamilare)
+ * Test assertion [`WagtailPageTestCase.assertCanCreate`](testing_reference) now supports the kwarg `publish=True` to check publish redirection (Harry Percival, Akua Dokua Asiedu)
 
 
 ### Bug fixes
 ### Bug fixes
 
 

+ 8 - 0
wagtail/tests/test_tests.py

@@ -172,6 +172,14 @@ class TestWagtailPageTests(WagtailPageTests):
             },
             },
         )
         )
 
 
+    def test_assert_can_create_for_page_with_publish(self):
+        self.assertCanCreate(
+            self.root,
+            SimplePage,
+            {"title": "Simple Lorem Page", "content": "Lorem ipsum dolor sit amet"},
+            publish=True,
+        )
+
     def test_assert_can_create_with_form_helpers(self):
     def test_assert_can_create_with_form_helpers(self):
         # same as test_assert_can_create, but using the helpers from wagtail.test.utils.form_data
         # same as test_assert_can_create, but using the helpers from wagtail.test.utils.form_data
         # as an end-to-end test
         # as an end-to-end test