Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Add regex capability to match_messages #112

Merged
merged 1 commit into from
Dec 3, 2019

Conversation

tpapaioa
Copy link
Contributor

@tpapaioa tpapaioa commented Nov 19, 2019

This PR adds the ability to pass a compiled regex as the 'text' parameter for the match_messages, assert_message, and assert_success_message methods of the FlashMessages class.

For example, when testing VM retirement using the 'Time Delay from Now' option, the selected month/week/day/hour time delay values will be added to the date/time at which the page was loaded. The resulting flash message from a successful save is of the form "Retirement date set to 12/19/19 18:31 UTC". But if the time changes from one minute to the next while navigating to the Set Retirement Date page, it is impossible to predict accurately whether the flash message will display a time delay calculated from one or the other minute. Now, with a test like the following,

    flash_regex = re.compile(f"^Retirement date set to (12/19/19 18:31 UTC|12/19/19 18:32 UTC)$")
    view.flash.assert_success_message(flash_regex)

a single assertion against a range of dates / flash message texts can be performed.

A couple other small changes:
1.) Fixed several typos in which log messages wrote 'Boostrap tree' instead of 'Bootstrap tree'.
2.) Changed the logging in match_messages somewhat to make it clearer and to indicate when the match is actually an inverse match.
3.) Also added a unit test file, test_flashmessages.py, which tests basic functionality of the FlashMessages methods read, assert_no_error, assert_message, assert_success_message, match_messages, and dismiss.

@tpapaioa tpapaioa changed the title Add regex capability to match_messages [WIP] Add regex capability to match_messages Nov 19, 2019
@coveralls
Copy link

coveralls commented Nov 19, 2019

Coverage Status

Coverage increased (+3.7%) to 52.963% when pulling 957893f on tpapaioa:flash_messages into cc06b10 on RedHatQE:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-13.8%) to 35.57% when pulling 41e045a on tpapaioa:flash_messages into 8553b34 on RedHatQE:master.

@tpapaioa tpapaioa changed the title [WIP] Add regex capability to match_messages [RFR] Add regex capability to match_messages Nov 19, 2019
@tpapaioa tpapaioa force-pushed the flash_messages branch 8 times, most recently from 9297383 to f3fd98a Compare November 22, 2019 14:55
@izapolsk izapolsk self-requested a review December 2, 2019 14:38
Copy link
Collaborator

@mshriver mshriver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great enhancement Tasos!

@@ -274,25 +274,55 @@ def dismiss(self):
message.dismiss()

def match_messages(self, text=None, t=None, partial=False, inverse=False):
"""
Return a list of flash messages matching the specified alert text and type(s)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 👍 👍

src/widgetastic_patternfly/__init__.py Outdated Show resolved Hide resolved
Copy link
Contributor

@izapolsk izapolsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. great enhancement.

if t is not None:
self.logger.info('%s match of the flash message %r of type %r', log_part, text, t)
log_inverse = "inverse " if inverse else ""
log_type = f", type: {t!r}" if msg_type else ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mshriver, are we going to stick to py 3.6+ ? I'm about usage of f-strings in public modules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants