def generateLocking(): lock = LockFile(LockingManager.LOCKFILE_DIR + LockingManager.LOCKFILE_NAME) lock["project/jeffsPart.dwg"] = "jeff" lock["project/jeffs2ndPart.dwg"] = "bob" lock["src/other.txt"] = "bob" lock.save() LockingManager._LockingManager__instance = None LockingManager() yield len(lock) os.remove(LockingManager.LOCKFILE_DIR + LockingManager.LOCKFILE_NAME) os.rmdir(LockingManager.LOCKFILE_DIR)
def test_findLock(generateLockfile): lock = LockFile(generateLockfile) lock["project/jeffsPart.dwg"] = "jeff" lock["project/jeffs2ndPart.dwg"] = "bob" entry = lock["project/jeffs2ndPart.dwg"] assert entry["user"] == "bob"
def test_removeLock(generateLockfile): lock = LockFile(generateLockfile) lock["project/jeffsPart.dwg"] = "jeff" lock["project/jeffs2ndPart.dwg"] = "bob" del lock["project/jeffsPart.dwg"] del lock["nonExistantLock"] #should not error assert len(lock) == 1 assert not lock["project/jeffs2ndPart.dwg"] is None
def __init__(self): """ Args: permissionsManager (PermissionsManager): the active permissions manager """ if not LockingManager.__instance is None: raise Exception( "Trying to create a second instance of LockingManager, which is a singleton" ) else: LockingManager.__instance = self LockingManager.__instance._lockFile = LockFile( LockingManager.LOCKFILE_DIR + LockingManager.LOCKFILE_NAME)
def generateLockfile(): fileName = ".meg/templockfile" tempFile = LockFile(fileName) yield fileName os.remove(fileName) os.rmdir(".meg")
def test_addLock(generateLockfile): lock = LockFile(generateLockfile) lock["project/jeffsPart.dwg"] = "jeff" lock["project/jeffs2ndPart.dwg"] = "bob" assert lock["project/jeffsPart.dwg"]["user"] == "jeff" assert lock["project/jeffs2ndPart.dwg"]["user"] == "bob"
def test_locks(generateLockfile): lock = LockFile(generateLockfile) lock["project/jeffsPart.dwg"] = "jeff" lock["project/jeffs2ndPart.dwg"] = "jeff" assert len(lock) == 2
def test_load(generateLockfile, loadEmptyFile): lock = LockFile(generateLockfile) lock["project/jeffsPart.dwg"] = "jeff" lock.load(loadEmptyFile) assert len(lock) == 0