workflows: migrate alerts with notice markup to use the level attribute (#22327) #605
|
@ -0,0 +1,44 @@
|
|||
import pytest
|
||||
from quixote import cleanup
|
||||
|
||||
from wcs.workflows import Workflow
|
||||
|
||||
from ..utilities import clean_temporary_pub, create_temporary_pub
|
||||
|
||||
|
||||
def setup_module(module):
|
||||
cleanup()
|
||||
|
||||
|
||||
def teardown_module(module):
|
||||
clean_temporary_pub()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pub():
|
||||
pub = create_temporary_pub()
|
||||
pub.cfg['language'] = {'language': 'en'}
|
||||
pub.cfg['identification'] = {'methods': ['password']}
|
||||
pub.write_cfg()
|
||||
return pub
|
||||
|
||||
|
||||
def test_display_message_migrate(pub):
|
||||
workflow = Workflow(name='display message to')
|
||||
st1 = workflow.add_status('Status1', 'st1')
|
||||
display_message = st1.add_action('displaymsg')
|
||||
display_message.level = None
|
||||
display_message.message = '<div class="errornotice">message</div>'
|
||||
workflow.store()
|
||||
|
||||
workflow.migrate()
|
||||
assert workflow.possible_status[0].items[0].level == 'error'
|
||||
assert workflow.possible_status[0].items[0].message == 'message'
|
||||
|
||||
# check the migration is skipped if there's an extra class
|
||||
display_message.level = None
|
||||
display_message.message = '<div class="errornotice blah">message</div>'
|
||||
workflow.store()
|
||||
workflow.migrate()
|
||||
assert not workflow.possible_status[0].items[0].level
|
||||
assert workflow.possible_status[0].items[0].message == '<div class="errornotice blah">message</div>'
|
|
@ -15,6 +15,7 @@
|
|||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import copy
|
||||
import re
|
||||
|
||||
from quixote import get_publisher
|
||||
from quixote.html import htmltext
|
||||
|
@ -56,6 +57,17 @@ class DisplayMessageWorkflowStatusItem(WorkflowStatusItem):
|
|||
yield from super().get_computed_strings()
|
||||
yield self.message
|
||||
|
||||
def migrate(self):
|
||||
changed = super().migrate()
|
||||
if not self.level: # 2023-08-15
|
||||
match = re.match(
|
||||
r'^<div class="(error|info|warning|success)notice">(.*)</div>$', (self.message or '').strip()
|
||||
)
|
||||
if match:
|
||||
self.level, self.message = match.groups(0)
|
||||
changed = True
|
||||
return changed
|
||||
|
||||
def get_message(self, formdata, position='top'):
|
||||
if not self.message:
|
||||
return ''
|
||||
|
|
Loading…
Reference in New Issue