diff --git a/src/fediblockhole/__init__.py b/src/fediblockhole/__init__.py index f79b7d6..5776b2c 100755 --- a/src/fediblockhole/__init__.py +++ b/src/fediblockhole/__init__.py @@ -171,10 +171,13 @@ def apply_mergeplan(oldblock: DomainBlock, newblock: DomainBlock, mergeplan: str log.debug(f"New block severity is higher. Using that.") blockdata['severity'] = newblock.severity - # If obfuscate is set and is True for the domain in - # any blocklist then obfuscate is set to True. - if getattr(newblock, 'obfuscate', False): - blockdata['obfuscate'] = True + # For 'reject_media', 'reject_reports', and 'obfuscate' if + # the value is set and is True for the domain in + # any blocklist then the value is set to True. + for key in ['reject_media', 'reject_reports', 'obfuscate']: + newval = getattr(newblock, key) + if newval == True: + blockdata[key] = True elif mergeplan in ['min']: # Use the lowest block level found @@ -183,10 +186,13 @@ def apply_mergeplan(oldblock: DomainBlock, newblock: DomainBlock, mergeplan: str if newblock.severity < oldblock.severity: blockdata['severity'] = newblock.severity - # If obfuscate is set and is False for the domain in - # any blocklist then obfuscate is set to False. - if not getattr(newblock, 'obfuscate', True): - blockdata['obfuscate'] = False + # For 'reject_media', 'reject_reports', and 'obfuscate' if + # the value is set and is False for the domain in + # any blocklist then the value is set to False. + for key in ['reject_media', 'reject_reports', 'obfuscate']: + newval = getattr(newblock, key) + if newval == False: + blockdata[key] = False else: raise NotImplementedError(f"Mergeplan '{mergeplan}' not implemented.") diff --git a/tests/data-noop-01.csv b/tests/data-noop-01.csv index b1ae532..3fe7492 100644 --- a/tests/data-noop-01.csv +++ b/tests/data-noop-01.csv @@ -1,14 +1,14 @@ "domain","severity","public_comment","private_comment","reject_media","reject_reports","obfuscate" -"public-comment.example.org","noop","This is a public comment","This is a private comment",TRUE,TRUE,TRUE -"private-comment.example.org","noop",,"This is a private comment",TRUE,TRUE,TRUE -"diff-comment.example.org","noop","Noop public comment","Noop private comment",TRUE,TRUE,TRUE -"2diff-comment.example.org","noop","Public duplicate","Private duplicate",TRUE,TRUE,TRUE -"qoto.org","noop",,,TRUE,TRUE,TRUE -"sealion.club","noop",,,TRUE,TRUE,TRUE -"develop.gab.com","noop",,,TRUE,TRUE,TRUE -"gab.ai","noop",,,TRUE,TRUE,TRUE -"gab.sleeck.eu","noop",,,TRUE,TRUE,TRUE -"gab.com","noop",,,TRUE,TRUE,TRUE -"kiwifarms.is","noop",,,TRUE,TRUE,TRUE -"kiwifarms.net","noop",,,TRUE,TRUE,TRUE -"gabfed.com","noop",,,TRUE,TRUE,TRUE +"public-comment.example.org","noop","This is a public comment","This is a private comment",FALSE,FALSE,FALSE +"private-comment.example.org","noop",,"This is a private comment",FALSE,FALSE,FALSE +"diff-comment.example.org","noop","Noop public comment","Noop private comment",FALSE,FALSE,FALSE +"2diff-comment.example.org","noop","Public duplicate","Private duplicate",FALSE,FALSE,FALSE +"qoto.org","noop",,,FALSE,FALSE,FALSE +"sealion.club","noop",,,FALSE,FALSE,FALSE +"develop.gab.com","noop",,,FALSE,FALSE,FALSE +"gab.ai","noop",,,FALSE,FALSE,FALSE +"gab.sleeck.eu","noop",,,FALSE,FALSE,FALSE +"gab.com","noop",,,FALSE,FALSE,FALSE +"kiwifarms.is","noop",,,FALSE,FALSE,FALSE +"kiwifarms.net","noop",,,FALSE,FALSE,FALSE +"gabfed.com","noop",,,FALSE,FALSE,FALSE diff --git a/tests/data-silences-01.csv b/tests/data-silences-01.csv index 5203924..11f4cfa 100644 --- a/tests/data-silences-01.csv +++ b/tests/data-silences-01.csv @@ -1,14 +1,14 @@ "domain","severity","public_comment","private_comment","reject_media","reject_reports","obfuscate" -"public-comment.example.org","silence","This is a public comment","This is a private comment",TRUE,TRUE,TRUE -"private-comment.example.org","silence",,"This is a private comment",TRUE,TRUE,TRUE -"diff-comment.example.org","silence","Silence public comment","Silence private comment",TRUE,TRUE,TRUE -"2diff-comment.example.org","silence","Public duplicate","Private duplicate",TRUE,TRUE,TRUE -"qoto.org","silence",,,TRUE,TRUE,TRUE -"sealion.club","silence",,,TRUE,TRUE,TRUE -"develop.gab.com","silence",,,TRUE,TRUE,TRUE -"gab.ai","silence",,,TRUE,TRUE,TRUE -"gab.sleeck.eu","silence",,,TRUE,TRUE,TRUE -"gab.com","silence",,,TRUE,TRUE,TRUE -"kiwifarms.is","silence",,,TRUE,TRUE,TRUE -"kiwifarms.net","silence",,,TRUE,TRUE,TRUE -"gabfed.com","silence",,,TRUE,TRUE,TRUE +"public-comment.example.org","silence","This is a public comment","This is a private comment",FALSE,FALSE,FALSE +"private-comment.example.org","silence",,"This is a private comment",FALSE,FALSE,FALSE +"diff-comment.example.org","silence","Silence public comment","Silence private comment",FALSE,FALSE,FALSE +"2diff-comment.example.org","silence","Public duplicate","Private duplicate",FALSE,FALSE,FALSE +"qoto.org","silence",,,FALSE,FALSE,FALSE +"sealion.club","silence",,,FALSE,FALSE,FALSE +"develop.gab.com","silence",,,FALSE,FALSE,FALSE +"gab.ai","silence",,,FALSE,FALSE,FALSE +"gab.sleeck.eu","silence",,,FALSE,FALSE,FALSE +"gab.com","silence",,,FALSE,FALSE,FALSE +"kiwifarms.is","silence",,,FALSE,FALSE,FALSE +"kiwifarms.net","silence",,,FALSE,FALSE,FALSE +"gabfed.com","silence",,,FALSE,FALSE,FALSE diff --git a/tests/test_mergeplan.py b/tests/test_mergeplan.py index 142f1da..b8454ef 100644 --- a/tests/test_mergeplan.py +++ b/tests/test_mergeplan.py @@ -2,9 +2,9 @@ """ from fediblockhole.blocklist_parser import parse_blocklist -from fediblockhole import merge_blocklists, merge_comments +from fediblockhole import merge_blocklists, merge_comments, apply_mergeplan -from fediblockhole.const import SeverityLevel +from fediblockhole.const import SeverityLevel, DomainBlock datafile01 = "data-suspends-01.csv" datafile02 = "data-silences-01.csv" @@ -71,9 +71,12 @@ def test_mergeplan_3_max(): for key in bl: assert bl[key].severity.level == SeverityLevel.SUSPEND + assert bl[key].reject_media == True + assert bl[key].reject_reports == True + assert bl[key].obfuscate == True -def test_mergeplan_3_max(): - """3 datafiles and mergeplan of 'max'""" +def test_mergeplan_3_min(): + """3 datafiles and mergeplan of 'min'""" blocklists = load_test_blocklist_data([datafile01, datafile02, datafile03]) bl = merge_blocklists(blocklists, 'min') @@ -81,6 +84,9 @@ def test_mergeplan_3_max(): for key in bl: assert bl[key].severity.level == SeverityLevel.NONE + assert bl[key].reject_media == False + assert bl[key].reject_reports == False + assert bl[key].obfuscate == False def test_mergeplan_noop_v_silence_max(): """Mergeplan of max should choose silence over noop""" @@ -198,4 +204,38 @@ def test_merge_comments_dups(): r = merge_comments(a, b) - assert r == 'boring, nazis, lack of moderation, flagged, special, spoon, happy, fork' \ No newline at end of file + assert r == 'boring, nazis, lack of moderation, flagged, special, spoon, happy, fork' + +def test_mergeplan_same_min_bools_false(): + """Test merging with mergeplan 'max' and False values doesn't change them + """ + a = DomainBlock('example.org', 'noop', '', '', False, False, False) + b = DomainBlock('example.org', 'noop', '', '', False, False, False) + + r = apply_mergeplan(a, b, 'max') + + assert r.reject_media == False + assert r.reject_reports == False + assert r.obfuscate == False + +def test_mergeplan_same_min_bools_true(): + """Test merging with mergeplan 'max' and True values doesn't change them + """ + a = DomainBlock('example.org', 'noop', '', '', True, False, True) + b = DomainBlock('example.org', 'noop', '', '', True, False, True) + + r = apply_mergeplan(a, b, 'max') + + assert r.reject_media == True + assert r.reject_reports == False + assert r.obfuscate == True + +def test_mergeplan_max_bools(): + a = DomainBlock('example.org', 'suspend', '', '', True, False, True) + b = DomainBlock('example.org', 'noop', '', '', False, False, False) + + r = apply_mergeplan(a, b, 'max') + + assert r.reject_media == True + assert r.reject_reports == False + assert r.obfuscate == True \ No newline at end of file