def test_rpc_documentation_missing(): config_get = config.get def mock_get(section: str, key: str) -> str: if section == "options" and key == "aurwebdir": return "/missing" return config_get(section, key) with mock.patch("aurweb.config.get", side_effect=mock_get): config.rehash() expr = r"^doc/rpc\.html could not be read$" with pytest.raises(OSError, match=expr): rpc.documentation() config.rehash()
def config_mock(tmpdir: py.path.local) -> None: config_get = config.get archivedir = config.get("mkpkglists", "archivedir") def mock_config(section: str, key: str) -> str: if section == "mkpkglists": if key == "archivedir": return str(tmpdir) return config_get(section, key).replace(archivedir, str(tmpdir)) return config_get(section, key) with mock.patch("aurweb.config.get", side_effect=mock_config): config.rehash() yield config.rehash()
def test_smtp(user: User): with db.begin(): user.ResetKey = "12345678901234567890123456789012" smtp = FakeSMTP() get = "aurweb.config.get" getboolean = "aurweb.config.getboolean" with mock.patch(get, side_effect=mock_smtp_config(str)): with mock.patch(getboolean, side_effect=mock_smtp_config(bool)): with mock.patch("smtplib.SMTP", side_effect=smtp): config.rehash() notif = notify.WelcomeNotification(user.ID) notif.send() config.rehash() assert len(smtp.emails) == 1
def setup(db_test, alpm_db: AlpmDatabase, tempdir: py.path.local) -> None: config_get = config.get def mock_config_get(section: str, key: str) -> str: value = config_get(section, key) if section == "aurblup": if key == "db-path": return alpm_db.local elif key == "server": return f'file://{alpm_db.remote}' elif key == "sync-dbs": return alpm_db.repo return value with mock.patch("aurweb.config.get", side_effect=mock_config_get): config.rehash() yield config.rehash()
def test_config_main_set_real(tmpdir: py.path.local): """ Test a real set_option path. """ # Copy AUR_CONFIG to {tmpdir}/aur.config. aur_config = os.environ.get("AUR_CONFIG") tmp_aur_config = os.path.join(str(tmpdir), "aur.config") with open(aur_config) as f: with open(tmp_aur_config, "w") as o: o.write(f.read()) # Force reset the parser. This should NOT be done publicly. config._parser = None value = 666 args = ["aurweb-config", "set", "options", "fake-key", str(value)] with mock.patch.dict("os.environ", {"AUR_CONFIG": tmp_aur_config}): with mock.patch("sys.argv", args): # Run aurweb.config.main(). main() # Update the config; fake-key should be set. config.rehash() assert config.getint("options", "fake-key") == 666 # Restore config back to normal. args = ["aurweb-config", "unset", "options", "fake-key"] with mock.patch("sys.argv", args): main() # Return the config back to normal. config.rehash() # fake-key should no longer exist. assert config.getint("options", "fake-key") is None
def setup(db_test): config.rehash()