def test_library(self): db_path = '/tmp/foo/bar/library.db' if os.path.exists(db_path): os.remove(db_path) config_root = fsopendir('temp://') config_root.createfile(CONFIG_FILE) config_file_syspath = config_root.getsyspath(CONFIG_FILE) with open(config_file_syspath, 'w') as f: f.write(""" library: category: development filesystem_root: /tmp/foo/bar remotes: census: s3://test.library.civicknowledge.com/census public: s3://test.library.civicknowledge.com/public restricted: s3://test.library.civicknowledge.com/restricted test: s3://test.library.civicknowledge.com/test""") config = load(config_root.getsyspath('/')) lf = LibraryFilesystem(config) self.assertTrue('/tmp/foo/bar', lf.root) l = Library(config) l.sync_config() self.assertEqual( sorted(['test', 'restricted', 'census', 'public']), sorted([x.short_name for x in l.remotes]))
def test_library(self): db_path = '/tmp/foo/bar/library.db' if os.path.exists(db_path): os.remove(db_path) config_root = fsopendir('temp://') config_root.createfile(CONFIG_FILE) config_file_syspath = config_root.getsyspath(CONFIG_FILE) with open(config_file_syspath, 'w') as f: f.write(""" library: category: development filesystem_root: /tmp/foo/bar remotes: census: s3://test.library.civicknowledge.com/census public: s3://test.library.civicknowledge.com/public restricted: s3://test.library.civicknowledge.com/restricted test: s3://test.library.civicknowledge.com/test""") config = load(config_root.getsyspath('/')) lf = LibraryFilesystem(config) self.assertTrue('/tmp/foo/bar', lf.root) l = Library(config) l.sync_config() self.assertEqual(sorted(['test', 'restricted', 'census', 'public']), sorted([x.short_name for x in l.remotes]))
def run_command(args, rc): from . import global_logger if args.test_library: rc.set_lirbary_database('test') try: from ambry.library import global_library, Library global global_library l = Library(rc, echo=args.echo) global_library = l l.logger = global_logger l.sync_config() except Exception as e: if args.subcommand != 'info': warn('Failed to instantiate library: {}'.format(e)) l = None if args.exceptions: raise try: globals()['root_' + args.subcommand](args, l, rc) except NotFoundError as e: if args.exceptions: raise fatal(e) except Exception: raise
def test_remotes_accounts(self): import test from os.path import dirname, join, exists from os import makedirs import ambry.run from ambry.library import Library test_config_dir = join(dirname(test.__file__), 'test_config', 'separate_files') config = ambry.run.load(test_config_dir, load_user=False) if not exists(config.library.filesystem_root): makedirs(config.library.filesystem_root) l = Library(config) l.sync_config(force=True) for r in l.remotes: print r.short_name, r.access, r.secret