示例#1
0
    def test_get_session_manager(self):
        # Get absolute path to development ini file.
        script_dir = os.path.dirname(os.path.realpath(__file__))
        ini_file_path = os.path.join(script_dir,
                                     "assets",
                                     "test.conf")

        # Create temporary files and dirs the server will use.
        server_paths = helpers.server_utils.create_server_paths()

        config = configparser.ConfigParser()
        config.read(ini_file_path)

        # Use custom files and dirs in settings. Should be SqliteSessionManager
        config['sync_app'].update(server_paths)
        self.assertTrue(type(get_session_manager(config['sync_app']) == SqliteSessionManager))

        # No value defaults to SimpleSessionManager
        config.remove_option("sync_app", "session_db_path")
        self.assertTrue(type(get_session_manager(config['sync_app'])) == SimpleSessionManager)

        # A conf-specified SessionManager is loaded
        config.set("sync_app", "session_manager", 'test_sessions.FakeSessionManager')
        self.assertTrue(type(get_session_manager(config['sync_app'])) == FakeSessionManager)

        # Should fail at load time if the class doesn't inherit from  SimpleSessionManager
        config.set("sync_app", "session_manager", 'test_sessions.BadSessionManager')
        with self.assertRaises(TypeError):
            sm = get_session_manager(config['sync_app'])

        # Add the session_db_path back, it should take precedence over BadSessionManager
        config['sync_app'].update(server_paths)
        self.assertTrue(type(get_session_manager(config['sync_app'])) == SqliteSessionManager)
示例#2
0
    def __init__(self, config, user_manager=None, collection_manager=None):
        from ankisyncd.thread import get_collection_manager

        self.data_root = os.path.abspath(config["data_root"])
        self.base_url = config["base_url"]
        self.base_media_url = config["base_media_url"]
        self.setup_new_collection = None

        self.prehooks = {}
        self.posthooks = {}

        if not user_manager:
            self.user_manager = get_user_manager(config)
        else:
            self.user_manager = user_manager

        if not collection_manager:
            self.collection_manager = get_collection_manager(config)
        else:
            self.collection_manager = collection_manager

        self.session_manager = get_session_manager(config)
        self.full_sync_manager = get_full_sync_manager(config)

        # make sure the base_url has a trailing slash
        if not self.base_url.endswith("/"):
            self.base_url += "/"
        if not self.base_media_url.endswith("/"):
            self.base_media_url += "/"
示例#3
0
    def __init__(self, config):
        from ankisyncd.thread import get_collection_manager

        self.data_root = os.path.abspath(config['data_root'])
        self.base_url  = config['base_url']
        self.base_media_url  = config['base_media_url']
        self.setup_new_collection = None

        self.user_manager = get_user_manager(config)
        self.session_manager = get_session_manager(config)
        self.full_sync_manager = get_full_sync_manager(config)
        self.collection_manager = get_collection_manager(config)

        # make sure the base_url has a trailing slash
        if not self.base_url.endswith('/'):
            self.base_url += '/'
        if not self.base_media_url.endswith('/'):
            self.base_media_url += '/'
示例#4
0
    def __init__(self, config):
        from ankisyncd.thread import get_collection_manager

        self.data_root = os.path.abspath(config['data_root'])
        self.base_url  = config['base_url']
        self.base_media_url  = config['base_media_url']
        self.setup_new_collection = None

        self.prehooks = {}
        self.posthooks = {}

        self.user_manager = get_user_manager(config)
        self.session_manager = get_session_manager(config)
        self.full_sync_manager = get_full_sync_manager(config)
        self.collection_manager = get_collection_manager(config)

        # make sure the base_url has a trailing slash
        if not self.base_url.endswith('/'):
            self.base_url += '/'
        if not self.base_media_url.endswith('/'):
            self.base_media_url += '/'