def test_main_none(site): mock_linter = mock.Mock(return_value=set()) data = {f"Example{i}": f"[[{site['user']}:Example{i}]]" for i in range(0, 5)} with mock.patch("sigprobs.get_lint_errors", mock_linter): resultdata = sigprobs.main(site["domain"], data=data) assert resultdata["errors"].pop("total") == 0 assert not resultdata["errors"] assert resultdata["meta"].pop("site") == site["domain"] assert resultdata["meta"].pop("last_update") assert resultdata["meta"].pop("active_since") assert not resultdata["sigs"] mock_linter.assert_called_once()
def purge_site(site: str) -> bool: try: with open( os.path.join(flask.current_app.config["data_dir"], site + ".json")) as f: raw_data = json.load(f) except FileNotFoundError: raw_data = {} if raw_data and datetime.datetime.now() - datetime.datetime.fromisoformat( raw_data["meta"]["last_update"]) < datetime.timedelta(days=1): return False result = sigprobs.main(site) with sigprobs.output_file("", site, True) as f: json.dump(result, f) return True
def test_main(site): mock_linter = mock.Mock(return_value=set()) data = {f"Example{i}": f"[[{site['user']}:Example{i}]]" for i in range(0, 3)} data["Example1"] = "''Example1''" with mock.patch("sigprobs.get_lint_errors", mock_linter): resultdata = sigprobs.main(site["domain"], data=data) assert resultdata["errors"].pop("total") == 1 assert resultdata["errors"].pop(SigError.NO_USER_LINKS.value) == 1 assert not resultdata["errors"] assert resultdata["meta"].pop("site") == site["domain"] assert resultdata["meta"].pop("last_update") assert resultdata["meta"].pop("active_since") assert resultdata["sigs"].pop("Example1") == { "signature": data["Example1"], "errors": [SigError.NO_USER_LINKS.value], }
def test_main_sigsource(listed, active): # breakpoint() sigprobs.main("en.wikipedia.org", data=None) active.assert_called_once() listed.assert_not_called() active.reset_mock() listed.reset_mock() sigprobs.main("en.wikipedia.org", data=[]) listed.assert_called_once() active.assert_not_called() active.reset_mock() listed.reset_mock() fakedict = mock.MagicMock(return_value=[], __class__=dict) sigprobs.main("en.wikipedia.org", data=fakedict) listed.assert_not_called() active.assert_not_called() fakedict.items.assert_called_once() with pytest.raises(TypeError): sigprobs.main("en.wikipedia.org", data="Foo") listed.assert_not_called() active.assert_not_called()
def test_main_accumulate(site, count): mock_linter = mock.Mock( side_effect=lambda asig, host, checks: {SigError.MISSING_END_TAG} if "Example2" in asig else set() ) data = {f"Example{i}": f"[[{site['user']}:Example{i}]]" for i in range(0, count)} data["Example2"] = "<i>[[User:Example2]]'''" with mock.patch("sigprobs.get_lint_errors", mock_linter): resultdata = sigprobs.main(site["domain"], data=data) assert resultdata["errors"].pop("total") == 1 assert resultdata["errors"].pop("missing-end-tag") == 1 assert not resultdata["errors"] assert resultdata["meta"].pop("site") == site["domain"] assert resultdata["meta"].pop("last_update") assert resultdata["meta"].pop("active_since") e5 = resultdata["sigs"].pop("Example2") assert e5 == { "signature": data["Example2"], "errors": [SigError.MISSING_END_TAG.value], }
def test_main_skipemptysig(): with mock.patch("sigprobs.check_sig") as m: sigprobs.main("en.wikipedia.org", data={"foo": ""}) m.assert_not_called()