예제 #1
0
    def test_addFileFromOutsideOfRepo(self):
        user = User(login="******", password="")
        srcAbsPath = os.path.abspath(os.path.join(self.repo.base_path, "..", "tmp", "file.txt"))
        dstRelPath = "file.txt"

        self.assertFalse(os.path.exists(os.path.join(self.repo.base_path, dstRelPath)),
            "Target file should not be already in the repo root")


        tool = TestsToolModel(self.repo, user)
        dialogs = TestsDialogsFacade(selectedFiles=[srcAbsPath])
        handler = AddItemsActionHandler(tool, dialogs)
        handler.handle()

        self.assertEqual(len(handler.lastSavedItemIds), 1)
        try:
            uow = self.repo.createUnitOfWork()
            savedItem = uow.executeCommand(GetExpungedItemCommand(handler.lastSavedItemIds[0]))

            self.assertIsNotNone(savedItem,
                "Item should exist")
            self.assertIsNotNone(savedItem.data_ref,
                "Item should have a DataRef object")
            self.assertEqual(savedItem.data_ref.url_raw, to_db_format(dstRelPath),
                "Item's file should be located in the root of repo")
            self.assertTrue(os.path.exists(os.path.join(self.repo.base_path, savedItem.data_ref.url)),
                "Item's file should exist")
        finally:
            uow.close()
예제 #2
0
    def test_addFileFromOutsideOfRepo(self):
        user = User(login="******", password="")
        srcAbsPath = os.path.abspath(
            os.path.join(self.repo.base_path, "..", "tmp", "file.txt"))
        dstRelPath = "file.txt"

        self.assertFalse(
            os.path.exists(os.path.join(self.repo.base_path, dstRelPath)),
            "Target file should not be already in the repo root")

        tool = TestsToolModel(self.repo, user)
        dialogs = TestsDialogsFacade(selectedFiles=[srcAbsPath])
        handler = AddItemsActionHandler(tool, dialogs)
        handler.handle()

        self.assertEqual(len(handler.lastSavedItemIds), 1)
        try:
            uow = self.repo.createUnitOfWork()
            savedItem = uow.executeCommand(
                GetExpungedItemCommand(handler.lastSavedItemIds[0]))

            self.assertIsNotNone(savedItem, "Item should exist")
            self.assertIsNotNone(savedItem.data_ref,
                                 "Item should have a DataRef object")
            self.assertEqual(
                savedItem.data_ref.url_raw, to_db_format(dstRelPath),
                "Item's file should be located in the root of repo")
            self.assertTrue(
                os.path.exists(
                    os.path.join(self.repo.base_path, savedItem.data_ref.url)),
                "Item's file should exist")
        finally:
            uow.close()
예제 #3
0
    def test_addRecursivelyDirFromOutsideOfRepo(self):
        user = User(login="******", password="")
        srcDirAbsPath = os.path.abspath(os.path.join(self.repo.base_path, "..", "tmp"))

        dstRelPaths = []
        for root, _dirs, files in os.walk(srcDirAbsPath):
            for file in files:
                dstRelPath = os.path.relpath(os.path.join(root, file), os.path.join(srcDirAbsPath, ".."))
                dstRelPaths.append(dstRelPath)

        tool = TestsToolModel(self.repo, user)
        dialogs = TestsDialogsFacade(selectedFiles=[srcDirAbsPath])
        handler = AddItemsActionHandler(tool, dialogs)
        handler.handle()


        self.assertEqual(len(handler.lastSavedItemIds), len(dstRelPaths))
        for i, savedItemId in enumerate(handler.lastSavedItemIds):
            try:
                uow = self.repo.createUnitOfWork()
                savedItem = uow.executeCommand(GetExpungedItemCommand(savedItemId))

                self.assertIsNotNone(savedItem,
                    "Item should exist")
                self.assertIsNotNone(savedItem.data_ref,
                    "Item should have a DataRef object")
                self.assertEqual(savedItem.data_ref.url_raw, to_db_format(dstRelPaths[i]),
                    "Item's file not found in repo")
                self.assertTrue(os.path.exists(os.path.join(self.repo.base_path, savedItem.data_ref.url)),
                    "Item's file should exist")
            finally:
                uow.close()
예제 #4
0
    def test_addRecursivelyDirFromOutsideOfRepo(self):
        user = User(login="******", password="")
        srcDirAbsPath = os.path.abspath(
            os.path.join(self.repo.base_path, "..", "tmp"))

        dstRelPaths = []
        for root, _dirs, files in os.walk(srcDirAbsPath):
            for file in files:
                dstRelPath = os.path.relpath(os.path.join(root, file),
                                             os.path.join(srcDirAbsPath, ".."))
                dstRelPaths.append(dstRelPath)

        tool = TestsToolModel(self.repo, user)
        dialogs = TestsDialogsFacade(selectedFiles=[srcDirAbsPath])
        handler = AddItemsActionHandler(tool, dialogs)
        handler.handle()

        self.assertEqual(len(handler.lastSavedItemIds), len(dstRelPaths))
        for i, savedItemId in enumerate(handler.lastSavedItemIds):
            try:
                uow = self.repo.createUnitOfWork()
                savedItem = uow.executeCommand(
                    GetExpungedItemCommand(savedItemId))

                self.assertIsNotNone(savedItem, "Item should exist")
                self.assertIsNotNone(savedItem.data_ref,
                                     "Item should have a DataRef object")
                self.assertEqual(savedItem.data_ref.url_raw,
                                 to_db_format(dstRelPaths[i]),
                                 "Item's file not found in repo")
                self.assertTrue(
                    os.path.exists(
                        os.path.join(self.repo.base_path,
                                     savedItem.data_ref.url)),
                    "Item's file should exist")
            finally:
                uow.close()