Skip to content
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

test exclude_authors #536

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
10 changes: 7 additions & 3 deletions Scripts/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#from collections import Counter
from Levenshtein import ratio
from googleapiclient.errors import HttpError
import typing as T

##########################################################################################
############################## GET COMMENT THREADS #######################################
Expand Down Expand Up @@ -794,10 +795,12 @@ def check_recovered_comments(commentsList):
input("\nRecovery process finished. Press Enter to return to main menu...")
return True

# Removes comments by user-selected authors from list of comments to delete
def exclude_authors(current, config, miscData, excludedCommentsDict, authorsToExcludeSet, commentIDExcludeSet, displayString, inputtedString, logInfo=None, only=False):
def exclude_authors(current: T.Any, config:T.Dict[str, T.Any], miscData: T.Dict[str, T.Any], excludedCommentsDict: T.Dict[str, T.Any], authorsToExcludeSet: T.Set[T.Any], commentIDExcludeSet: T.Set[T.Any], displayString: str, inputtedString: str, logInfo: T.Optional[T.Dict[str, T.Any]]=None, only: bool=False):
"""Removes comments by user-selected authors from list of comments to delete."""
plaintextFormattedExcludes = ""
rtfFormattedExcludes = ""
if not hasattr(S, 'R'):
setattr(S, "R", S.RESET_ALL)

valid = False
while valid == False:
Expand Down Expand Up @@ -887,6 +890,7 @@ def exclude_authors(current, config, miscData, excludedCommentsDict, authorsToEx
print(f"\n{F.CYAN}All {len(excludedCommentsDict)} comments{S.R} from the {F.CYAN}following users{S.R} are now {F.LIGHTGREEN_EX}excluded{S.R} from deletion:")
print(displayString)

addWhitelist = True
if config['whitelist_excluded'] == 'ask':
print(f"\nAdd these {F.LIGHTGREEN_EX}excluded{S.R} users to the {F.LIGHTGREEN_EX}whitelist{S.R} for future scans?")
addWhitelist = choice("Whitelist Users?")
Expand Down Expand Up @@ -1002,4 +1006,4 @@ def print_count_stats(current, miscData, videosToScan, final):
else:
print(f" {progress} Comments Scanned: {F.YELLOW}{comScanned}{S.R} | Replies Scanned: {F.YELLOW}{repScanned}{S.R} | Matches Found So Far: {F.LIGHTRED_EX}{matchCount}{S.R}", end = "\r")

return None
return None
35 changes: 35 additions & 0 deletions tests/test_operations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from unittest.mock import MagicMock


def test_exclude_authors(tmp_path):
from Scripts.operations import exclude_authors

miscData = MagicMock()
output_txt = tmp_path / "output.txt"
miscData.resources = {"Whitelist": {"PathWithName": str(output_txt)}}
current = MagicMock()
current.matchSamplesDict = {MagicMock(): MagicMock(), MagicMock(): MagicMock()}
kwargs = dict(
current=current,
config=MagicMock(),
miscData=miscData,
excludedCommentsDict=MagicMock(),
authorsToExcludeSet=MagicMock(),
commentIDExcludeSet=MagicMock(),
displayString=MagicMock(),
inputtedString="exclude 1",
logInfo=None,
only=False,
)
exp_res = (
kwargs["current"],
kwargs["excludedCommentsDict"],
kwargs["authorsToExcludeSet"],
kwargs["commentIDExcludeSet"],
)
res = exclude_authors(**kwargs) # type: ignore
assert res == exp_res
assert not output_txt.read_text()