def test_init_client_raise(mocked_phabricator): """It should raise PhabricatorError if unable to instantiate the Phabricator client.""" with pytest.raises(phabricator.PhabricatorError, match='Unable to instantiate Phabricator client'): phabricator.create_phabricator(get_fixture_path('phabricator', 'valid.conf')) # Values from the phabricator/valid.conf fixture mocked_phabricator.assert_called_once_with( # nosec host='https://phabricator.example.com/api/', username='******', token='api-12345')
def test_load_yaml_config_no_raise(caplog, name): """Loading an invalid config with raises=False should return an empty dictionary.""" with caplog.at_level(DEBUG): config_dict = load_yaml_config(get_fixture_path('config', name), raises=False) assert {} == config_dict check_logs(caplog, 'Could not load config file', DEBUG)
def test_load_invalid_ini_config_no_raise(caplog): """Loading an invalid config with raises=False should return an empty ConfigParser.""" with caplog.at_level(DEBUG): config = load_ini_config(get_fixture_path('config', 'invalid.ini'), raises=False) assert configparser.ConfigParser() == config check_logs(caplog, 'Could not load config file', DEBUG)
def test_create_phabricator_ok(): """It should initialize the instance.""" phab = phabricator.create_phabricator(get_fixture_path('phabricator', 'valid.conf')) assert isinstance(phab, phabricator.Phabricator)
def test_create_phabricator_missing_option(): """It should raise PhabricatorError if any of the mandatory option is missing in the bot config file.""" with pytest.raises(phabricator.PhabricatorError, match='Unable to find all required options'): phabricator.create_phabricator(get_fixture_path('phabricator', 'invalid.conf'))
def test_create_phabricator_missing_section(): """It should raise PhabricatorError if the specified section is missing in the bot config file.""" with pytest.raises(phabricator.PhabricatorError, match='Unable to find section'): phabricator.create_phabricator(get_fixture_path('phabricator', 'valid.conf'), section='nonexistent')
def test_load_invalid_ini_config(message): """Loading an invalid INI config should raise an exception.""" with pytest.raises(WmflibError, match=message): load_ini_config(get_fixture_path('config', 'invalid.ini'))
def test_load_ini_config(): """Loading a INI config should return a configparser.ConfigParser object.""" config = load_ini_config(get_fixture_path('config', 'config.ini')) assert isinstance(config, configparser.ConfigParser) assert config.defaults()['key'] == 'value'
def test_load_yaml_config_valid(): """Loading a valid config should return its content.""" config_dir = get_fixture_path('config', 'valid.yaml') config_dict = load_yaml_config(config_dir) assert 'key' in config_dict
def test_load_yaml_config_raise(name, message): """Loading an invalid config should raise Exception.""" with pytest.raises(WmflibError, match=message): load_yaml_config(get_fixture_path('config', name))
def test_load_yaml_config_empty(): """Loading an empty config should return an empty dictionary.""" config_dict = load_yaml_config(get_fixture_path('config', 'empty.yaml')) assert {} == config_dict