diff options
Diffstat (limited to 'solo-tool-project')
| -rw-r--r-- | solo-tool-project/src/solo_tool/session_manager.py | 26 | ||||
| -rw-r--r-- | solo-tool-project/test/session_manager_unittest.py | 11 | 
2 files changed, 33 insertions, 4 deletions
| diff --git a/solo-tool-project/src/solo_tool/session_manager.py b/solo-tool-project/src/solo_tool/session_manager.py index ece67d8..be928a4 100644 --- a/solo-tool-project/src/solo_tool/session_manager.py +++ b/solo-tool-project/src/solo_tool/session_manager.py @@ -58,11 +58,33 @@ class _FileSystemSessionManager(SessionManager):          with open(self._sessionPath / f"{key}.json", "w") as f:              json.dump(session, f) -    def addSong(self, name: str, content: BinaryIO): +    def addSong(self, name: str, content: BinaryIO) -> None:          from shutil import copyfileobj          newSong = self._songPool / name          with open(newSong, "wb") as f:              copyfileobj(content, f) +class _FileBrowserSessionManager(SessionManager): +    def __init__(self, songPool: str, sessionPath: str): +        pass + +    def getSessions(self) -> list[str]: +        pass + +    def loadSession(self, key: str, player=None) -> SoloTool: +        pass + +    def saveSession(self, soloTool: SoloTool, key: str) -> None: +        pass + +    def addSong(self, name: str, content: BinaryIO) -> None: +        pass +  def getSessionManager(songPool: str, sessionPath: str) -> SessionManager: -    return _FileSystemSessionManager(songPool, sessionPath) +    from re import search +    match = search(r"^([a-z0-9]+://)", sessionPath) +    if not match or match.group(0) == "file://": +        return _FileSystemSessionManager(songPool, sessionPath) +    elif match.group(0) in ["http://", "https://"]: +        return _FileBrowserSessionManager(songPool, sessionPath) + diff --git a/solo-tool-project/test/session_manager_unittest.py b/solo-tool-project/test/session_manager_unittest.py index bef4e5d..bb40fdf 100644 --- a/solo-tool-project/test/session_manager_unittest.py +++ b/solo-tool-project/test/session_manager_unittest.py @@ -2,7 +2,7 @@ import pytest  from json import loads  import os -from solo_tool.session_manager import getSessionManager +from solo_tool.session_manager import getSessionManager, _FileSystemSessionManager, _FileBrowserSessionManager  from fixtures import songPool, soloTool, mockPlayer, testSongs, sessionPath  @pytest.fixture @@ -24,7 +24,7 @@ def testSessionFile(sessionPath, testSongs):  @pytest.fixture  def sessionManager(sessionPath, songPool): -    return getSessionManager(songPool, sessionPath) +    return getSessionManager(str(songPool), str(sessionPath))  def test_loadSession(sessionManager, mockPlayer, testSessionFile):      sessions = sessionManager.getSessions() @@ -74,3 +74,10 @@ def test_uploadSong(sessionManager, songPool, tmp_path):      with open(song, "rb") as f:          sessionManager.addSong("song-to-be-uploaded.mp3", f)      assert expected.exists() + +def test_sessionManagerFactory(): +    assert type(getSessionManager("", "/some_absolute_dir")) is _FileSystemSessionManager +    assert type(getSessionManager("", "file:///some_dir_with_protocol")) is _FileSystemSessionManager +    assert type(getSessionManager("", "some_relative_dir")) is _FileSystemSessionManager +    assert type(getSessionManager("", "http://some_server")) is _FileBrowserSessionManager +    assert type(getSessionManager("", "https://some_secure_server")) is _FileBrowserSessionManager | 
