def test_not_enabled(self, mocker) -> None: mock_class = mocker.patch("autosuspend.checks.activity.Mpd") mock_class.create.return_value = mocker.MagicMock( spec=autosuspend.Activity) parser = configparser.ConfigParser() parser.read_string(""" [check.Foo] class = Mpd enabled = False """) assert not autosuspend.set_up_checks( parser, "check", "activity", autosuspend.Activity, # type: ignore ) with pytest.raises(autosuspend.ConfigurationError): autosuspend.set_up_checks( parser, "check", "activity", autosuspend.Activity, # type: ignore error_none=True, )
def test_set_up_checks_no_such_class(mocker): parser = configparser.ConfigParser() parser.read_string('''[check.Foo] class = FooBarr enabled = True''') with pytest.raises(autosuspend.ConfigurationError): autosuspend.set_up_checks(parser)
def test_set_up_checks_not_enabled(mocker): mock_class = mocker.patch('autosuspend.Mpd') mock_class.create.return_value = mocker.MagicMock(spec=autosuspend.Check) parser = configparser.ConfigParser() parser.read_string('''[check.Foo] class = Mpd enabled = False''') with pytest.raises(autosuspend.ConfigurationError): autosuspend.set_up_checks(parser)
def test_set_up_checks(mocker): mock_class = mocker.patch('autosuspend.Mpd') mock_class.create.return_value = mocker.MagicMock(spec=autosuspend.Check) parser = configparser.ConfigParser() parser.read_string('''[check.Foo] class = Mpd enabled = True''') autosuspend.set_up_checks(parser) mock_class.create.assert_called_once_with('Foo', parser['check.Foo'])
def test_external_class(self, mocker): mock_class = mocker.patch('os.path.TestCheck', create=True) mock_class.create.return_value = mocker.MagicMock( spec=autosuspend.checks.Activity) parser = configparser.ConfigParser() parser.read_string('''[check.Foo] class = os.path.TestCheck enabled = True''') autosuspend.set_up_checks(parser, 'check', 'activity', autosuspend.Activity) mock_class.create.assert_called_once_with('Foo', parser['check.Foo'])
def test_set_up_checks_not_a_check(mocker): mock_class = mocker.patch('autosuspend.Mpd') mock_class.create.return_value = mocker.MagicMock() parser = configparser.ConfigParser() parser.read_string('''[check.Foo] class = Mpd enabled = True''') with pytest.raises(autosuspend.ConfigurationError): autosuspend.set_up_checks(parser) mock_class.create.assert_called_once_with('Foo', parser['check.Foo'])
def test_no_such_class(self, mocker) -> None: parser = configparser.ConfigParser() parser.read_string(""" [check.Foo] class = FooBarr enabled = True """) with pytest.raises(autosuspend.ConfigurationError): autosuspend.set_up_checks( parser, "check", "activity", autosuspend.Activity # type: ignore )
def test_not_enabled_continues_with_next(self, mocker) -> None: mock_mpd = mocker.patch("autosuspend.checks.activity.Mpd") mock_mpd.create.return_value = mocker.MagicMock( spec=autosuspend.Activity) mock_xidletime = mocker.patch("autosuspend.checks.activity.XIdleTime") mock_xidletime.create.return_value = mocker.MagicMock( spec=autosuspend.Activity) parser = configparser.ConfigParser() parser.read_string(""" [check.Foo] class = Mpd enabled = False [check.Bar] class = XIdleTime enabled = True """) assert (len( autosuspend.set_up_checks( parser, "check", "activity", autosuspend.Activity, # type: ignore )) == 1)
def test_not_enabled(self, mocker): mock_class = mocker.patch('autosuspend.checks.activity.Mpd') mock_class.create.return_value = mocker.MagicMock( spec=autosuspend.Activity) parser = configparser.ConfigParser() parser.read_string('''[check.Foo] class = Mpd enabled = False''') autosuspend.set_up_checks(parser, 'check', 'activity', autosuspend.Activity) with pytest.raises(autosuspend.ConfigurationError): autosuspend.set_up_checks(parser, 'check', 'activity', autosuspend.Activity, error_none=True)
def test_external_class(self, mocker) -> None: mock_class = mocker.patch("os.path.TestCheck", create=True) mock_class.create.return_value = mocker.MagicMock( spec=autosuspend.checks.Activity) parser = configparser.ConfigParser() parser.read_string(""" [check.Foo] class = os.path.TestCheck enabled = True """) autosuspend.set_up_checks( parser, "check", "activity", autosuspend.Activity # type: ignore ) mock_class.create.assert_called_once_with("Foo", parser["check.Foo"])
def test_not_a_check(self, mocker) -> None: mock_class = mocker.patch("autosuspend.checks.activity.Mpd") mock_class.create.return_value = mocker.MagicMock() parser = configparser.ConfigParser() parser.read_string(""" [check.Foo] class = Mpd enabled = True """) with pytest.raises(autosuspend.ConfigurationError): autosuspend.set_up_checks( parser, "check", "activity", autosuspend.Activity # type: ignore ) mock_class.create.assert_called_once_with("Foo", parser["check.Foo"])
def test_passwords_redacted(self, mocker, caplog) -> None: mock_class = mocker.patch("autosuspend.checks.activity.Mpd") mock_class.create.return_value = mocker.MagicMock( spec=autosuspend.checks.Activity) parser = configparser.ConfigParser() parser.read_string(""" [check.Foo] class = Mpd enabled = True password = THEPASS """) with caplog.at_level(logging.DEBUG): autosuspend.set_up_checks( parser, "check", "activity", autosuspend.Activity # type: ignore ) assert "THEPASS" not in caplog.text