예제 #1
0
class TestImport(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        create_config()

    @classmethod
    def tearDownClass(cls):
        cleanup()

    def setUp(self):
        self.action = ImportAction(os.getcwd())
        self.files = ['sample.txt', 'sample1.txt', 'sample2.txt']
        for fn in self.files:
            create_txt_file(fn)
        self.doc_ids = []
        for fn in self.files:
            title = os.path.basename(os.path.normpath(fn))
            response = self.action.api.add_document(fn, self.action.locale, self.action.project_id, title)
            assert response.status_code == 202
            self.doc_ids.append(response.json()['properties']['id'])
        for doc_id in self.doc_ids:
            assert poll_doc(self.action, doc_id)
        for fn in self.files:
            delete_file(fn)

    def tearDown(self):
        for fn in self.files:
            #print ('deleting', fn)
            self.action.rm_action(fn, True)
        self.action.clean_action(False, False, None)

    def test_import_all(self):
        self.action.import_action(True, False, None)
        for doc_id in self.doc_ids:
            assert self.action.doc_manager.get_doc_by_prop('id', doc_id)

    def test_import_locale(self):
        locale = "ja_JP"
        doc_id = self.doc_ids[0]
        response = self.action.api.document_add_target(doc_id, locale)
        assert response.status_code == 201
        self.action.import_action(False, False, None, doc_id)
        entry = self.action.doc_manager.get_doc_by_prop("id", doc_id)
        assert locale in entry["locales"]

    def test_import_no_locale(self):
        self.action.import_action(False, False, None, self.doc_ids[0])
        entry = self.action.doc_manager.get_doc_by_prop("id", self.doc_ids[0])
        assert not entry.get("locales")
예제 #2
0
def import_command(import_all, force, path):
    """
    Import documents from Lingotek Cloud, automatically downloading to the project root
    """
    # todo import should show all documents
    # add a force option so can import all force -- overwrites all existing documents without prompting
    # check if doc id
    # if exist, prompt for overwrite
    # else automatically re-name
    # possibly have to patch title in Lingotek Cloud?
    try:
        # action = actions.Action(os.getcwd())
        action = ImportAction(os.getcwd())
        init_logger(action.path)
        action.import_action(import_all, force, path)
    except(UninitializedError, RequestFailedError) as e:
        print_log(e)
        logger.error(e)
        return
예제 #3
0
def mv(source_path, destination_path):
    """
    Moves specified local doc to a specified destination directory, moving both the file itself and file location stores in the local database.
    If SOURCE_PATH is a directory, all added files in the directory will be moved.
    """
    try:
        # action = actions.Action(os.getcwd())
        action = ImportAction(os.getcwd())
        init_logger(action.path)

        source_path = remove_powershell_formatting(source_path)
        print("Source path " + str(source_path))
        destination_path = remove_powershell_formatting(destination_path)
        print("Destination path "+str(destination_path))

        action.mv_action(source_path, destination_path)
    except(UninitializedError, RequestFailedError) as e:
        print_log(e)
        logger.error(e)
        return
예제 #4
0
 def setUp(self):
     self.action = ImportAction(os.getcwd())
     self.files = ['sample.txt', 'sample1.txt', 'sample2.txt']
     for fn in self.files:
         create_txt_file(fn)
     self.doc_ids = []
     for fn in self.files:
         title = os.path.basename(os.path.normpath(fn))
         response = self.action.api.add_document(fn, self.action.locale, self.action.project_id, title)
         assert response.status_code == 202
         self.doc_ids.append(response.json()['properties']['id'])
     for doc_id in self.doc_ids:
         assert poll_doc(self.action, doc_id)
     for fn in self.files:
         delete_file(fn)