diff --git a/sherlock_project/notify.py b/sherlock_project/notify.py index ab6f5a3866..5472c17974 100644 --- a/sherlock_project/notify.py +++ b/sherlock_project/notify.py @@ -7,10 +7,6 @@ from colorama import Fore, Style import webbrowser -# Global variable to count the number of results. -globvar = 0 - - class QueryNotify: """Query Notify Object. @@ -132,6 +128,7 @@ def __init__(self, result=None, verbose=False, print_all=False, browse=False): self.verbose = verbose self.print_all = print_all self.browse = browse + self._result_count = 0 def start(self, message): @@ -169,9 +166,8 @@ def countResults(self): Return Value: The number of results by the time we call the function. """ - global globvar - globvar += 1 - return globvar + self._result_count += 1 + return self._result_count def update(self, result): """Notify Update. @@ -258,7 +254,7 @@ def finish(self, message="The processing has been finished."): Return Value: Nothing. """ - NumberOfResults = self.countResults() - 1 + NumberOfResults = self._result_count print(Style.BRIGHT + Fore.GREEN + "[" + Fore.YELLOW + "*" + diff --git a/tests/test_notify.py b/tests/test_notify.py new file mode 100644 index 0000000000..864c337597 --- /dev/null +++ b/tests/test_notify.py @@ -0,0 +1,28 @@ +from sherlock_project.notify import QueryNotifyPrint +from sherlock_project.result import QueryResult, QueryStatus + + +def claimed_result(): + return QueryResult( + username='example', + site_name='Example', + site_url_user='https://example.com/example', + status=QueryStatus.CLAIMED, + ) + + +def test_result_count_is_scoped_to_each_notifier(capsys): + first = QueryNotifyPrint() + first.update(claimed_result()) + first.update(claimed_result()) + first.finish() + + assert ' 2 ' in capsys.readouterr().out + assert first._result_count == 2 + + second = QueryNotifyPrint() + second.update(claimed_result()) + second.finish() + + assert ' 1 ' in capsys.readouterr().out + assert second._result_count == 1