-
-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: improve
reddit
suite to check which handler matched
- Loading branch information
Showing
1 changed file
with
41 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,32 +25,32 @@ def bot(botfactory, configfactory): | |
MATCHING_URLS = ( | ||
# URLs the reddit plugin is expected to handle | ||
# Should match ONCE each, no more, no less | ||
'https://redd.it/123456', | ||
'https://redd.it/123456/', | ||
'https://reddit.com/123456', | ||
'https://reddit.com/123456/', | ||
'https://reddit.com/r/subname', | ||
'https://reddit.com/r/subname/', | ||
'https://www.reddit.com/r/subname', | ||
'https://www.reddit.com/r/subname/', | ||
'https://reddit.com/comments/123456', | ||
'https://reddit.com/comments/123456/', | ||
'https://www.reddit.com/comments/123456', | ||
'https://www.reddit.com/comments/123456/', | ||
'https://reddit.com/r/subname/comments/123456', | ||
'https://reddit.com/r/subname/comments/123456/', | ||
'https://www.reddit.com/comments/123456?param=value', | ||
'https://www.reddit.com/comments/123456/?param=value', | ||
'https://reddit.com/r/subname/comments/123456?param=value', | ||
'https://reddit.com/r/subname/comments/123456/?param=value', | ||
'https://www.reddit.com/r/subname/comments/123456', | ||
'https://www.reddit.com/r/subname/comments/123456/', | ||
'https://reddit.com/r/subname/comments/123456/post_title_slug/234567', | ||
'https://reddit.com/r/subname/comments/123456/post_title_slug/234567/', | ||
'https://www.reddit.com/r/subname/comments/123456/post_title_slug/234567', | ||
'https://www.reddit.com/r/subname/comments/123456/post_title_slug/234567/', | ||
'https://reddit.com/r/subname/comments/123456/post_title_slug/234567/?context=1337', | ||
'https://www.reddit.com/r/subname/comments/123456/post_title_slug/234567/?context=1337', | ||
('auto_subreddit_info', 'https://reddit.com/r/subname'), | ||
('auto_subreddit_info', 'https://reddit.com/r/subname/'), | ||
('auto_subreddit_info', 'https://www.reddit.com/r/subname'), | ||
('auto_subreddit_info', 'https://www.reddit.com/r/subname/'), | ||
('post_or_comment_info', 'https://redd.it/123456'), | ||
('post_or_comment_info', 'https://redd.it/123456/'), | ||
('post_or_comment_info', 'https://reddit.com/123456'), | ||
('post_or_comment_info', 'https://reddit.com/123456/'), | ||
('post_or_comment_info', 'https://reddit.com/comments/123456'), | ||
('post_or_comment_info', 'https://reddit.com/comments/123456/'), | ||
('post_or_comment_info', 'https://www.reddit.com/comments/123456'), | ||
('post_or_comment_info', 'https://www.reddit.com/comments/123456/'), | ||
('post_or_comment_info', 'https://reddit.com/r/subname/comments/123456'), | ||
('post_or_comment_info', 'https://reddit.com/r/subname/comments/123456/'), | ||
('post_or_comment_info', 'https://www.reddit.com/comments/123456?param=value'), | ||
('post_or_comment_info', 'https://www.reddit.com/comments/123456/?param=value'), | ||
('post_or_comment_info', 'https://reddit.com/r/subname/comments/123456?param=value'), | ||
('post_or_comment_info', 'https://reddit.com/r/subname/comments/123456/?param=value'), | ||
('post_or_comment_info', 'https://www.reddit.com/r/subname/comments/123456'), | ||
('post_or_comment_info', 'https://www.reddit.com/r/subname/comments/123456/'), | ||
('post_or_comment_info', 'https://reddit.com/r/subname/comments/123456/post_title_slug/234567'), | ||
('post_or_comment_info', 'https://reddit.com/r/subname/comments/123456/post_title_slug/234567/'), | ||
('post_or_comment_info', 'https://www.reddit.com/r/subname/comments/123456/post_title_slug/234567'), | ||
('post_or_comment_info', 'https://www.reddit.com/r/subname/comments/123456/post_title_slug/234567/'), | ||
('post_or_comment_info', 'https://reddit.com/r/subname/comments/123456/post_title_slug/234567/?context=1337'), | ||
('post_or_comment_info', 'https://www.reddit.com/r/subname/comments/123456/post_title_slug/234567/?context=1337'), | ||
) | ||
|
||
|
||
|
@@ -63,17 +63,26 @@ def bot(botfactory, configfactory): | |
) | ||
|
||
|
||
@pytest.mark.parametrize('link', MATCHING_URLS) | ||
def test_url_matching(link, bot): | ||
@pytest.mark.parametrize('rule_name, link', MATCHING_URLS) | ||
def test_url_matching(link, rule_name, bot): | ||
line = PreTrigger(bot.nick, ':[email protected] PRIVMSG #channel {}'.format(link)) | ||
matches = bot.rules.get_triggered_rules(bot, line) | ||
matched_rules = [ | ||
# we can ignore matches that don't come from the plugin under test | ||
match[0] for match in bot.rules.get_triggered_rules(bot, line) | ||
if match[0].get_plugin_name() == 'reddit' | ||
] | ||
|
||
assert len([match for match in matches if match[0].get_plugin_name() == 'reddit']) == 1 | ||
assert len(matched_rules) == 1 | ||
assert matched_rules[0].get_rule_label() == rule_name | ||
|
||
|
||
@pytest.mark.parametrize('link', NON_MATCHING_URLS) | ||
def test_url_non_matching(link, bot): | ||
line = PreTrigger(bot.nick, ':[email protected] PRIVMSG #channel {}'.format(link)) | ||
matches = bot.rules.get_triggered_rules(bot, line) | ||
matched_rules = [ | ||
# we can ignore matches that don't come from the plugin under test | ||
match[0] for match in bot.rules.get_triggered_rules(bot, line) | ||
if match[0].get_plugin_name() == 'reddit' | ||
] | ||
|
||
assert len([match for match in matches if match[0].get_plugin_name() == 'reddit']) == 0 | ||
assert len(matched_rules) == 0 |