Revise test decorator used in TestPageEditHandlers

- Fix clear_edit_handler decorator
- Will  allow the TestPageEditHandlers test cases to run
- Fixes test for test_check_invalid_base_form_class
- Errors might be returned out of order, so sort them before comparing them to the expected list
pull/5244/head
Alex Tomkins 2019-04-20 11:24:03 +01:00 zatwierdzone przez LB Johnston
rodzic d3b8bcb689
commit 0644f90bef
3 zmienionych plików z 10 dodań i 2 usunięć

Wyświetl plik

@ -10,6 +10,7 @@ Changelog
* Fix: ModelAdmin no longer fails when filtering over a foreign key relation (Jason Dilworth, Matt Westcott)
* Fix: The Wagtail version number is now visible within the Settings menu (Kevin Howbrook)
* Fix: Scaling images now rounds values to an integer so that images render without errors (Adrian Brunyate)
* Fix: Revised test decorator to ensure TestPageEditHandlers test cases run correctly (Alex Tomkins)
2.5 (24.04.2019)

Wyświetl plik

@ -24,6 +24,7 @@ Bug fixes
* ModelAdmin no longer fails when filtering over a foreign key relation (Jason Dilworth, Matt Westcott)
* The Wagtail version number is now visible within the Settings menu (Kevin Howbrook)
* Scaling images now rounds values to an integer so that images render without errors (Adrian Brunyate)
* Revised test decorator to ensure TestPageEditHandlers test cases run correctly (Alex Tomkins)
Upgrade considerations

Wyświetl plik

@ -1,4 +1,5 @@
from datetime import date
from functools import wraps
from unittest import mock
from django import forms
@ -121,14 +122,16 @@ class TestGetFormForModel(TestCase):
def clear_edit_handler(page_cls):
def decorator(fn):
def decorated(self):
@wraps(fn)
def decorated(*args, **kwargs):
# Clear any old EditHandlers generated
page_cls.get_edit_handler.cache_clear()
try:
fn(self)
fn(*args, **kwargs)
finally:
# Clear the bad EditHandler generated just now
page_cls.get_edit_handler.cache_clear()
return decorated
return decorator
@ -182,6 +185,9 @@ class TestPageEditHandlers(TestCase):
# don't build the CSS)
errors = [e for e in errors if e.id != 'wagtailadmin.W001']
# Errors may appear out of order, so sort them by id
errors.sort(key=lambda e: e.id)
self.assertEqual(errors, [invalid_base_form, invalid_edit_handler])
@clear_edit_handler(ValidatedPage)