Fixed not passing the logged user to the censor

master
Yo Mama 2021-10-16 20:56:12 +02:00
parent 58c74dbdaf
commit b345cedf2a
4 changed files with 26 additions and 26 deletions

View File

@ -300,7 +300,7 @@ class Comment(Base):
if not body: return ""
body = censor_slurs(body)
body = censor_slurs(body, v)
if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com")
@ -326,7 +326,7 @@ class Comment(Base):
if not body: return ""
body = censor_slurs(body)
body = censor_slurs(body, v)
if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com")

View File

@ -342,7 +342,7 @@ class Submission(Base):
if self.club and not (v and v.paid_dues): return "COUNTRY CLUB ONLY"
body = self.body_html
body = censor_slurs(body)
body = censor_slurs(body, v)
if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com")
if v and v.nitter: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net")
@ -352,7 +352,7 @@ class Submission(Base):
if self.club and not (v and v.paid_dues): return "COUNTRY CLUB ONLY"
body = self.body
body = censor_slurs(body)
body = censor_slurs(body, v)
if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com")
if v and v.nitter: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net")

View File

@ -47,8 +47,8 @@ def sub_matcher(match: Match):
return (match.group(1) or '') + replacer + (match.group(4) or '')
def censor_slurs(v, body: str):
if v and not v.slurreplacer:
def censor_slurs(body: str, logged_user):
if logged_user and not logged_user.slurreplacer:
return body
for (slur, replace) in SLURS.items():

View File

@ -83,25 +83,25 @@ def test_sub_matcher():
def test_censor_slurs():
word_censor.REPLACE_MAP = create_replace_map()
assert_that(censor_slurs(None, "<p>retard</p>")).is_equal_to("<p>r-slur</p>")
assert_that(censor_slurs(None, "<p>preretard</p>")).is_equal_to("<p>prer-slur</p>")
assert_that(censor_slurs(None, "that is Retarded like")).is_equal_to("that is R-slured like")
assert_that(censor_slurs(None, "that is SUPERRETARD like")).is_equal_to("that is SUPERR-SLUR like")
assert_that(censor_slurs(None, "<p>Manlets get out!</p>")).is_equal_to("<p>Little kings get out!</p>")
assert_that(censor_slurs("<p>retard</p>", None)).is_equal_to("<p>r-slur</p>")
assert_that(censor_slurs("<p>preretard</p>", None)).is_equal_to("<p>prer-slur</p>")
assert_that(censor_slurs("that is Retarded like", None)).is_equal_to("that is R-slured like")
assert_that(censor_slurs("that is SUPERRETARD like", None)).is_equal_to("that is SUPERR-SLUR like")
assert_that(censor_slurs("<p>Manlets get out!</p>", None)).is_equal_to("<p>Little kings get out!</p>")
assert_that(censor_slurs(None, '... "retard" ...')).is_equal_to('... "retard" ...')
assert_that(censor_slurs(None, '... ReTaRd ...')).is_equal_to('... ReTaRd ...')
assert_that(censor_slurs(None, '... xretardx ...')).is_equal_to('... xretardx ...')
assert_that(censor_slurs('... "retard" ...', None)).is_equal_to('... "retard" ...')
assert_that(censor_slurs('... ReTaRd ...', None)).is_equal_to('... ReTaRd ...')
assert_that(censor_slurs('... xretardx ...', None)).is_equal_to('... xretardx ...')
assert_that(censor_slurs(None, "LLM is a manlet hehe")).is_equal_to("LLM is a little king hehe")
assert_that(censor_slurs(None, "LLM is :marseycapitalistmanlet: hehe")) \
assert_that(censor_slurs("LLM is a manlet hehe", None)).is_equal_to("LLM is a little king hehe")
assert_that(censor_slurs("LLM is :marseycapitalistmanlet: hehe", None)) \
.is_equal_to("LLM is :marseycapitalistmanlet: hehe")
assert_that(censor_slurs(None, '... Nig ...')).is_equal_to('... πŸ€ ...')
assert_that(censor_slurs(None, '<p>NIG</p>')).is_equal_to('<p>πŸ€</p>')
assert_that(censor_slurs(None, '... nigeria ...')).is_equal_to('... nigeria ...')
assert_that(censor_slurs('... Nig ...', None)).is_equal_to('... πŸ€ ...')
assert_that(censor_slurs('<p>NIG</p>', None)).is_equal_to('<p>πŸ€</p>')
assert_that(censor_slurs('... nigeria ...', None)).is_equal_to('... nigeria ...')
assert_that(censor_slurs(None, "<p>retarded SuperManlet NIG</p>")) \
assert_that(censor_slurs("<p>retarded SuperManlet NIG</p>", None)) \
.is_equal_to("<p>r-slured SuperLittle king πŸ€</p>")
@ -110,19 +110,19 @@ def test_censor_slurs_does_not_error_out_on_exception():
word_censor.REPLACE_MAP = create_replace_map()
word_censor.REPLACE_MAP["Manlet"] = None
assert_that(censor_slurs(None, ">retarded SuperManlet NIG<")).is_equal_to(">r-slured SuperManlet πŸ€<")
assert_that(censor_slurs(">retarded SuperManlet NIG<", None)).is_equal_to(">r-slured SuperManlet πŸ€<")
@patch("files.helpers.word_censor.SLURS", {'retard': 'r-slur', 'manlet': 'little king'})
def test_censor_slurs_does_not_censor_on_flag_disabled():
word_censor.REPLACE_MAP = create_replace_map()
class V:
class User:
def __init__(self, slurreplacer):
self.slurreplacer = slurreplacer
v = V(False)
assert_that(censor_slurs(v, "<p>retard</p>")).is_equal_to("<p>retard</p>")
logger_user = User(slurreplacer=False)
assert_that(censor_slurs("<p>retard</p>", logger_user)).is_equal_to("<p>retard</p>")
v = V(True)
assert_that(censor_slurs(v, "<p>retard</p>")).is_equal_to("<p>r-slur</p>")
logger_user = User(slurreplacer=True)
assert_that(censor_slurs("<p>retard</p>", logger_user)).is_equal_to("<p>r-slur</p>")