class RatbotConfigurationSection(StaticSection): apiurl = types.ValidatedAttribute('apiurl', str, default='') apitoken = types.ValidatedAttribute('apitoken', str, default='a') workdir = types.FilenameAttribute('workdir', directory=True, default='run') alembic = types.FilenameAttribute('alembic', directory=False, default='alembic.ini') debug_sql = BooleanAttribute('debug_sql', default=False) edsm_url = types.ValidatedAttribute( 'edsm_url', str, default="http://edsm.net/api-v1/systems?coords=1") edsm_maxage = types.ValidatedAttribute('edsm_maxage', int, default=12 * 60 * 60) edsm_autorefresh = types.ValidatedAttribute('edsm_autorefresh', int, default=4 * 60 * 60) edsm_db = types.ValidatedAttribute('edsm_db', str, default="systems.db") websocketurl = types.ValidatedAttribute('websocketurl', str, default='12') websocketport = types.ValidatedAttribute('websocketport', str, default='9000') shortenerurl = types.ValidatedAttribute('shortenerurl', str, default='') shortenertoken = types.ValidatedAttribute('shortenertoken', str, default='asdf') debug_channel = types.ValidatedAttribute('debug_channel', str, default='#mechadeploy') chunked_systems = BooleanAttribute( 'chunked_systems', default=True) # Should be edsm_chunked_systems to fit others hastebin_url = types.ValidatedAttribute('hastebin_url', 'str', default="http://hastebin.com/")
class FakeConfigSection(types.StaticSection): valattr = types.ValidatedAttribute('valattr') listattr = types.ListAttribute('listattr') choiceattr = types.ChoiceAttribute('choiceattr', ['spam', 'egg', 'bacon']) af_fileattr = types.FilenameAttribute('af_fileattr', relative=False, directory=False) ad_fileattr = types.FilenameAttribute('ad_fileattr', relative=False, directory=True) rf_fileattr = types.FilenameAttribute('rf_fileattr', relative=True, directory=False) rd_fileattr = types.FilenameAttribute('rd_fileattr', relative=True, directory=True)
def test_filename_parse_directory_create(tmpdir): testdir = tmpdir.join('foo') option = types.FilenameAttribute('foo', directory=True) assert not os.path.exists(testdir.strpath), 'Test dir must not exist yet' assert option.parse(testdir.strpath) == testdir.strpath assert os.path.exists(testdir.strpath), 'Test dir must exist now' assert os.path.isdir(testdir.strpath), 'Test dir must be a directory'
def test_filename_parse(tmpdir): testfile = tmpdir.join('foo.txt') testfile.write('') option = types.FilenameAttribute('foo') assert option.parse(testfile.strpath) == testfile.strpath assert option.parse(None) is None assert option.parse('') is None
def test_filename_attribute(): option = types.FilenameAttribute('foo') assert option.name == 'foo' assert option.default is None assert option.is_secret is False assert option.directory is False assert option.relative is True
def test_filename_parse_create(tmpdir): testfile = tmpdir.join('foo.txt') option = types.FilenameAttribute('foo') assert not os.path.exists(testfile.strpath), 'Test file must not exist yet' assert option.parse(testfile.strpath) == testfile.strpath assert os.path.exists(testfile.strpath), 'Test file must exist now' assert os.path.isfile(testfile.strpath), 'Test file must be a file'
class MeetbotSection(types.StaticSection): """Configuration file section definition""" meeting_log_path = types.FilenameAttribute("meeting_log_path", relative=False, directory=True, default="~/www/meetings") """Path to meeting logs storage directory. This should be an absolute path, accessible on a webserver. """ meeting_log_baseurl = types.ValidatedAttribute( "meeting_log_baseurl", default="http://localhost/~sopel/meetings") """Base URL for the meeting logs directory."""
def test_filename_parse_directory(tmpdir): testdir = tmpdir.join('foo') testdir.mkdir() option = types.FilenameAttribute('foo', directory=True) assert option.parse(testdir.strpath) == testdir.strpath
class GeoipSection(types.StaticSection): GeoIP_db_path = types.FilenameAttribute('GeoIP_db_path', directory=True) """Path of the directory containing the GeoIP database files.