def test_missing_variables_warned(self): self._config_names_set( 'CLIENT_ID', 'CLIENT_SECRET', 'REDIRECT_URI', '_' ) with handle_warnings('error'): with self.assertRaises(MissingConfigurationWarning): config_from_file(self.test_config_path, 'MISSING')
def test_config_written_with_dict(self): from tekore.util import config written = {config.client_secret_var: 'secret'} config_to_file(self.test_config_path, written) loaded = config_from_file(self.test_config_path) self.assertTupleEqual((None, 'secret', None), loaded)
def test_config_tuple_nones_not_written(self): original = ('id', 'secret', 'uri') config_to_file(self.test_config_path, original) written = (None, 'another', None) config_to_file(self.test_config_path, written) loaded = config_from_file(self.test_config_path) self.assertTupleEqual(('id', 'another', 'uri'), loaded)
def test_file_another_section_is_case_sensitive(self): self._config_names_set( 'client_id', 'client_secret', 'redirect_uri', '_' ) with handle_warnings('ignore'): conf = config_from_file(self.test_config_path) self.assertTupleEqual(conf, (None, None, None))
def test_file_missing_variables_returns_none(self): self._config_names_set( 'CLIENT_ID', 'CLIENT_SECRET', 'REDIRECT_URI', '_' ) with handle_warnings('ignore'): conf = config_from_file(self.test_config_path, 'MISSING') self.assertTupleEqual(conf, (None, None, None))
def test_file_another_section(self): self._config_names_set( 'CLIENT_ID', 'CLIENT_SECRET', 'REDIRECT_URI', '_' ) conf = config_from_file(self.test_config_path, 'ANOTHER') self.assertTupleEqual(conf, ('an_id', 'an_secret', 'an_uri'))
def test_config_written_with_tuple_refresh_token(self): written = ('id', 'secret', 'uri', 'refresh') config_to_file(self.test_config_path, written) loaded = config_from_file(self.test_config_path, return_refresh=True) self.assertTupleEqual(written, loaded)
def test_config_write_to_section(self): written = ('id', 'secret', 'uri') config_to_file(self.test_config_path, written, section='SEC') loaded = config_from_file(self.test_config_path, section='SEC') self.assertTupleEqual(written, loaded)
def test_config_written_with_tuple(self): written = ('id', 'secret', 'uri') config_to_file(self.test_config_path, written) loaded = config_from_file(self.test_config_path) self.assertTupleEqual(written, loaded)
def test_file_pathlib_path_accepted(self): from pathlib import Path path = Path(self.test_config_path) conf = config_from_file(path) self.assertTupleEqual(conf, ('df_id', 'df_secret', 'df_uri'))
def test_file_nonexistent_section_raises(self): with self.assertRaises(KeyError): config_from_file(self.test_config_path, 'NOTSECTION')
def test_file_nonexistent_file_raises(self): with self.assertRaises(FileNotFoundError): config_from_file('not_file.ini')
def test_file_refresh_returned(self): conf = config_from_file(self.test_config_path, return_refresh=True) self.assertTupleEqual(conf, ('df_id', 'df_secret', 'df_uri', 'df_refresh'))
def test_file_default_section(self): conf = config_from_file(self.test_config_path) self.assertTupleEqual(conf, ('df_id', 'df_secret', 'df_uri'))