Ejemplo n.º 1
0
class AbstractTestCaseWithRepoAndSingleUOW(unittest.TestCase):

    def setUp(self):
        self.repoBasePath = tests_context.TEST_REPO_BASE_PATH
        self.copyOfRepoBasePath = tests_context.COPY_OF_TEST_REPO_BASE_PATH

        if (os.path.exists(self.copyOfRepoBasePath)):
            shutil.rmtree(self.copyOfRepoBasePath)
        shutil.copytree(self.repoBasePath, self.copyOfRepoBasePath)

        self.repo = RepoMgr(self.copyOfRepoBasePath)
        self.uow = self.repo.createUnitOfWork()

    def tearDown(self):
        self.uow.close()
        self.uow = None
        self.repo = None
        shutil.rmtree(self.copyOfRepoBasePath)
Ejemplo n.º 2
0
class AbstractTestCaseWithRepo(unittest.TestCase):

    def setUp(self):
        self.repoBasePath = tests_context.TEST_REPO_BASE_PATH
        self.copyOfRepoBasePath = tests_context.COPY_OF_TEST_REPO_BASE_PATH

        if (os.path.exists(self.copyOfRepoBasePath)):
            shutil.rmtree(self.copyOfRepoBasePath)
        shutil.copytree(self.repoBasePath, self.copyOfRepoBasePath)

        self.repo = RepoMgr(self.copyOfRepoBasePath)

    def tearDown(self):
        self.repo = None
        shutil.rmtree(self.copyOfRepoBasePath)

    def getExistingItem(self, itemId):
        try:
            uow = self.repo.createUnitOfWork()
            item = uow.executeCommand(GetExpungedItemCommand(itemId))
            self.assertIsNotNone(item)
        finally:
            uow.close()
        return item

    def getDataRef(self, url):
        # In the case when this DataRef is a file, url should be a relative path
        try:
            uow = self.repo.createUnitOfWork()
            dataRef = uow._session.query(DataRef) \
                    .filter(DataRef.url_raw==helpers.to_db_format(url)).first()
            # NOTE: dataRef could be None
        finally:
            uow.close()
        return dataRef


    def getDataRefById(self, objId):
        '''
            Returns a DataRef object with given id or None, if DataRef object not found.
        '''
        try:
            uow = self.repo.createUnitOfWork()
            dataRef = uow._session.query(DataRef).filter(DataRef.id==objId).first()
        finally:
            uow.close()
        return dataRef

    
    def getDataRefsFromDir(self, dirRelPath):
        dataRefs = []
        try:
            uow = self.repo.createUnitOfWork()
            dataRefs = uow._session.query(DataRef).filter(
                DataRef.url_raw.like(helpers.to_db_format(dirRelPath) + "/%")).all()
        finally:
            uow.close()
        return dataRefs


    def updateExistingItem(self, detachedItem, newSrcAbsPath, newDstRelPath, user_login):
        item = None
        try:
            uow = self.repo.createUnitOfWork()
            cmd = UpdateExistingItemCommand(detachedItem, newSrcAbsPath, newDstRelPath, user_login)
            item = uow.executeCommand(cmd)
        finally:
            uow.close()
        return item