1+ import random
12import allure
23import pytest
3- from playwright .sync_api import Page
4+ from playwright .sync_api import Page , expect
45from pytest_check import check
56from playwright_tests .core .utilities import Utilities
67from playwright_tests .messages .ask_a_question_messages .AAQ_messages .question_page_messages import (
78 QuestionPageMessages ,
89)
910from playwright_tests .messages .common_elements_messages import CommonElementsMessages
1011from playwright_tests .pages .sumo_pages import SumoPages
12+ from kitsune .settings import TRUSTED_GROUPS
1113
1214
1315# C946237
@@ -51,16 +53,16 @@ def test_anti_spam_banner(page: Page, user_type, create_user_factory):
5153 CommonElementsMessages .AVOID_SCAM_BANNER_TEXT )
5254
5355
54- # C946274
56+ # C946275
5557@pytest .mark .smokeTest
5658@pytest .mark .antiSpamTests
57- def test_valid_tld_in_question_comment (page : Page , create_user_factory ):
59+ def test_spam_content_is_auto_flagged (page : Page , create_user_factory ):
5860 sumo_pages = SumoPages (page )
5961 utilities = Utilities (page )
60- invalid_tld = "dom.ipc.processCount"
61- valid_tld = "layout.display-list.retain.chrome"
6262 test_user = create_user_factory (groups = ["Forum Moderators" ])
6363 test_user_two = create_user_factory ()
64+ spam_content = ['https://www.example.com' , 'layout.display-list.retain.chrome' ,
65+ '800, 888, 877, 866, 855, 844, or 833' , '+1 212-555-1234' ]
6466
6567 with allure .step ("Signing in with a Forum Moderator account and creating an AAQ question" ):
6668 utilities .start_existing_session (cookies = test_user )
@@ -74,38 +76,150 @@ def test_valid_tld_in_question_comment(page: Page, create_user_factory):
7476 expected_locator = sumo_pages .question_page .questions_header
7577 )
7678
77- with allure .step ("Signing in with an account that doesn't have the bypass ratelimit "
78- "permission" ):
79- utilities .start_existing_session (cookies = test_user_two )
79+ for content in spam_content :
80+ with allure .step ("Signing in with an account that doesn't have the bypass ratelimit "
81+ "permission" ):
82+ utilities .start_existing_session (cookies = test_user_two )
8083
81- with allure .step ("Leaving a comment with an invalid TLD" ):
82- reply_one = sumo_pages .aaq_flow .post_question_reply_flow (
83- repliant_username = test_user_two ["username" ], reply = invalid_tld
84- )
84+ with allure .step (f"Leaving a comment with { content } spam content" ):
85+ sumo_pages .aaq_flow .post_question_reply_flow (
86+ repliant_username = test_user_two ["username" ], reply = content , fetch_id = False
87+ )
88+
89+ with check , allure .step ("Verifying that the spam banner is successfully displayed" ):
90+ assert (QuestionPageMessages .SPAM_FLAGGED_REPLY == sumo_pages .question_page .
91+ get_text_of_spam_marked_banner ())
92+
93+ with check , allure .step (f"Verifying that the comment is marked as spam" ):
94+ assert not sumo_pages .question_page .is_reply_with_content_displayed (content )
95+
96+ with check , allure .step ("Signing out and verifying that the reply is not displayed" ):
97+ utilities .delete_cookies ()
98+ assert not sumo_pages .question_page .is_reply_with_content_displayed (content )
99+
100+ with check , allure .step ("Signing in with an admin account and verifying that the Marked as "
101+ "spam reply is visible" ):
102+ utilities .start_existing_session (cookies = test_user )
103+ assert sumo_pages .question_page .is_reply_with_content_displayed (content )
85104
86- with check , allure .step ("Verifying that the spam banner is not displayed" ):
87- assert not sumo_pages .question_page .is_spam_marked_banner_displayed ()
88105
89- with check , allure .step ("Verifying that the invalid TLD comment is not marked as spam" ):
90- assert sumo_pages .question_page .is_reply_displayed (reply_one )
106+ # C946276
107+ @pytest .mark .antiSpamTests
108+ def test_valid_prefs_and_internal_links_are_not_flagged_as_spam (page : Page , create_user_factory ):
109+ sumo_pages = SumoPages (page )
110+ utilities = Utilities (page )
111+ test_user = create_user_factory (groups = ["Forum Moderators" ])
112+ test_user_two = create_user_factory ()
113+ test_content = ['https://support.mozilla.org' , 'dom.ipc.processCount' ]
91114
92- with allure .step ("Leaving a comment with a valid TLD" ):
93- sumo_pages .aaq_flow .post_question_reply_flow (
94- repliant_username = test_user_two ["username" ], reply = valid_tld
115+ with allure .step ("Signing in with a Forum Moderator account and creating an AAQ question" ):
116+ utilities .start_existing_session (cookies = test_user )
117+
118+ utilities .navigate_to_link (utilities .aaq_question_test_data ["products_aaq_url" ]["Firefox" ])
119+ sumo_pages .aaq_flow .submit_an_aaq_question (
120+ subject = utilities .aaq_question_test_data ["valid_firefox_question" ]["subject" ],
121+ topic_name = sumo_pages .aaq_form_page .get_aaq_form_topic_options ()[0 ],
122+ body = utilities .aaq_question_test_data ["valid_firefox_question" ]["question_body" ],
123+ attach_image = False ,
124+ expected_locator = sumo_pages .question_page .questions_header
95125 )
96126
97- with check , allure .step ("Verifying that the spam banner is successfully displayed" ):
98- assert (QuestionPageMessages .SPAM_FLAGGED_REPLY == sumo_pages .question_page .
99- get_text_of_spam_marked_banner ())
127+ for content in test_content :
128+ with allure .step ("Signing in with an account that doesn't have the bypass ratelimit "
129+ "permission" ):
130+ utilities .start_existing_session (cookies = test_user_two )
100131
101- with check , allure .step ("Verifying that the valid TLD comment is marked as spam" ):
102- assert not sumo_pages .question_page .is_reply_with_content_displayed (valid_tld )
132+ with allure .step (f"Leaving a comment with { content } spam content" ):
133+ reply_id = sumo_pages .aaq_flow .post_question_reply_flow (
134+ repliant_username = test_user_two ["username" ], reply = content ,
135+ )
103136
104- with check , allure .step ("Signing out and verifying that the reply is not displayed" ):
105- utilities .delete_cookies ()
106- assert not sumo_pages .question_page .is_reply_with_content_displayed (valid_tld )
137+ with check , allure .step ("Verifying that the spam banner is not displayed" ):
138+ expect (sumo_pages .question_page .reply_flagged_as_spam_banner ).to_be_hidden ()
139+
140+ with check , allure .step (f"Verifying that the valid pref value comment is displayed" ):
141+ assert sumo_pages .question_page .is_reply_displayed (reply_id )
142+
143+ with check , allure .step ("Signing out and verifying that the reply is displayed" ):
144+ utilities .delete_cookies ()
145+ assert sumo_pages .question_page .is_reply_displayed (reply_id )
146+
147+
148+ # C1296001, C3395616
149+ @pytest .mark .antiSpamTests
150+ def test_question_owner_is_exempted_for_spam_auto_flag (page : Page , create_user_factory ):
151+ utilities = Utilities (page )
152+ sumo_pages = SumoPages (page )
153+ spam_content = ['https://www.example.com' , 'layout.display-list.retain.chrome' ,
154+ '800, 888, 877, 866, 855, 844, or 833' , '+1 212-555-1234' ]
155+ test_user = create_user_factory ()
156+
157+ with allure .step ("Signing in creating an AAQ question" ):
158+ utilities .start_existing_session (cookies = test_user )
107159
108- with check , allure .step ("Signing in with an admin account and verifying that the Marked as "
109- "spam reply is visible" ):
160+ utilities .navigate_to_link (
161+ utilities .aaq_question_test_data ["products_aaq_url" ]["Firefox" ])
162+ sumo_pages .aaq_flow .submit_an_aaq_question (
163+ subject = utilities .aaq_question_test_data ["valid_firefox_question" ]["subject" ],
164+ topic_name = sumo_pages .aaq_form_page .get_aaq_form_topic_options ()[0 ],
165+ body = utilities .
166+ aaq_question_test_data ["valid_firefox_question" ]["question_body" ] + spam_content [1 ],
167+ attach_image = False ,
168+ expected_locator = sumo_pages .question_page .questions_header
169+ )
170+
171+ for content in spam_content :
172+ with allure .step (f"Leaving a comment with a spam comment" ):
173+ reply_id = sumo_pages .aaq_flow .post_question_reply_flow (
174+ repliant_username = test_user ["username" ], reply = content
175+ )
176+
177+ with check , allure .step ("Verifying that the spam banner is not displayed" ):
178+ expect (sumo_pages .question_page .reply_flagged_as_spam_banner ).to_be_hidden ()
179+
180+ with check , allure .step (f"Verifying that the comment is displayed" ):
181+ assert sumo_pages .question_page .is_reply_displayed (reply_id )
182+
183+
184+ # C3395573, C3395578
185+ @pytest .mark .antiSpamTests
186+ @pytest .mark .parametrize ("trusted_user_config" , [
187+ {"groups" : [random .choice (TRUSTED_GROUPS )]},
188+ {"permissions" : ["can_moderate" ]}
189+ ])
190+ def test_trusted_contributors_are_exempted_from_spam_check (page : Page , create_user_factory ,
191+ trusted_user_config ):
192+ utilities = Utilities (page )
193+ sumo_pages = SumoPages (page )
194+ test_user = create_user_factory ()
195+ trusted_group_user = create_user_factory (** trusted_user_config )
196+ spam_content = ['https://www.example.com' , 'layout.display-list.retain.chrome' ,
197+ '800, 888, 877, 866, 855, 844, or 833' , '+1 212-555-1234' ]
198+
199+ with allure .step ("Signing in creating an AAQ question" ):
110200 utilities .start_existing_session (cookies = test_user )
111- assert sumo_pages .question_page .is_reply_with_content_displayed (valid_tld )
201+
202+ utilities .navigate_to_link (
203+ utilities .aaq_question_test_data ["products_aaq_url" ]["Firefox" ])
204+ sumo_pages .aaq_flow .submit_an_aaq_question (
205+ subject = utilities .aaq_question_test_data ["valid_firefox_question" ]["subject" ],
206+ topic_name = sumo_pages .aaq_form_page .get_aaq_form_topic_options ()[0 ],
207+ body = utilities .aaq_question_test_data ["valid_firefox_question" ]["question_body" ],
208+ attach_image = False ,
209+ expected_locator = sumo_pages .question_page .questions_header
210+ )
211+
212+ for content in spam_content :
213+ with allure .step ("Signing in with a trusted user" ):
214+ utilities .start_existing_session (cookies = trusted_group_user )
215+
216+ with allure .step (f"Leaving a comment with a spam comment" ):
217+ reply_id = sumo_pages .aaq_flow .post_question_reply_flow (
218+ repliant_username = trusted_group_user ["username" ], reply = content
219+ )
220+
221+ with check , allure .step ("Verifying that the spam banner is not displayed" ):
222+ expect (sumo_pages .question_page .reply_flagged_as_spam_banner ).to_be_hidden ()
223+
224+ with check , allure .step (f"Verifying that the comment is displayed" ):
225+ assert sumo_pages .question_page .is_reply_displayed (reply_id )
0 commit comments