-
-
Notifications
You must be signed in to change notification settings - Fork 195
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
add regex validation function #29
add regex validation function #29
Conversation
Is it possible to apply functions to anything other than response body? |
@WhileLoop Thanks, this is a great addition! I suspect that you might be able to get away without the group matching aspect of this for the most part? Unless I'm missing a case where you need to be able to match the groups individually? |
I made the group matching useful by allowing them to be saved and reused. |
@WhileLoop Sorry for the delay in getting back to you on this. I've been thinking about it a bit and wondering if a nicer way of doing this could be to use "named groups" in regexes. This could mean that we automatically save the contents of the named groups to the name if provided. Un-named groups could be dropped. The re module provides this which would make it pretty easy to implement too. What do you think? |
tavern/testutils/helpers.py
Outdated
'full_match': full_match, | ||
'groups': groups | ||
}) | ||
"regex": Box(match.groupdict()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reckon they might be okay without being keyed on the dict, i.e. they could just be top level variables? so you can just return the Box(match.groupdict())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This follows the pattern of the other helpers. Also returning the matches as top level variables increases chance some other existing variable being overwritten inadvertently.
I think this is looking good @WhileLoop! I think @michaelboulton should have a look too and possibly a few tests of the functionality can be added. |
The only (minor) issue with this is that it forces people to use named match groups, but I actually like the named groups |
add a regex validation helper function and a regex example