Exemplo n.º 1
0
 def __init__(self, path):
     Action.__init__(self, path)
     self.observer = Observer()  # watchdog observer that will watch the files
     self.handler = WatchHandler()
     self.handler.on_modified = self._on_modified
     self.handler.on_created = self._on_created
     self.handler.on_moved = self._on_moved
     self.watch_queue = []  # not much slower than deque unless expecting 100+ items
     self.locale_delimiter = None
     self.ignore_ext = []  # file types to ignore as specified by the user
     self.detected_locales = {}  # dict to keep track of detected locales
Exemplo n.º 2
0
 def __init__(self, path=None, timeout=60):
     Action.__init__(self, path, True, timeout)
     self.observers = []  # watchdog observers that will watch the files
     self.handler = WatchHandler()
     self.handler.on_modified = self._on_modified
     self.handler.on_created = self._on_created
     self.handler.on_moved = self._on_moved
     self.watch_queue = []  # not much slower than deque unless expecting 100+ items
     self.locale_delimiter = None
     self.ignore_ext = []  # file types to ignore as specified by the user
     self.detected_locales = {}  # dict to keep track of detected locales
     self.watch_folder = True
     self.timeout = timeout
     self.updated = {}
     self.git_auto = Git_Auto(path)
     self.polled_list = set([])
     self.force_poll = False
 def setUp(self):
     self.action = Action(os.getcwd())
     self.action.clean_action(True, False, None)
     self.files = ['sample.txt', 'sample1.txt', 'sample2.txt']
     self.first_doc = 'sample.txt'
     for fn in self.files:
         create_txt_file(fn)
     self.action.add_action(None, ['sample*.txt'], force=True)
     self.doc_ids = self.action.doc_manager.get_doc_ids()
     for doc_id in self.doc_ids:
         assert poll_doc(self.action, doc_id)
Exemplo n.º 4
0
 def setUp(self):
     create_config()
     self.downloaded = []
     self.action = Action(os.getcwd())
     self.files = ['sample.txt', 'sample1.txt', 'sample2.txt']
     for fn in self.files:
         create_txt_file(fn)
     self.action.add_action(None, ['sample*.txt'], force=True)
     self.doc_ids = self.action.doc_manager.get_doc_ids()
     for doc_id in self.doc_ids:
         assert poll_doc(self.action, doc_id)
 def setUp(self):
     self.action = Action(os.getcwd())
     self.action.clean_action(False, False, None)
     self.files = ['sample.txt', 'sample1.txt', 'sample2.txt']
     self.forced = []
     for fn in self.files:
         create_txt_file(fn)
     self.action.add_action(None, ['sample*.txt'], force=True)
     self.entries = self.action.doc_manager.get_all_entries()
     for entry in self.entries:
         assert poll_doc(self.action, entry['id'])
Exemplo n.º 6
0
 def setUp(self):
     create_config()
     self.downloaded = []
     self.action = Action(os.getcwd())
     self.action.clean_action(True, False, None)
     self.files = ['sample.txt', 'sample1.txt', 'sample2.txt']
     for fn in self.files:
         create_txt_file(fn)
     os.system('ltk add sample*.txt -o') # Let the command line handle parsing the file pattern
     self.doc_ids = self.action.doc_manager.get_doc_ids()
     for doc_id in self.doc_ids:
         assert poll_doc(self.action, doc_id)
 def setUp(self):
     self.downloaded_files = []
     self.action = Action(os.getcwd())
     self.files = ['sample.txt', 'sample1.txt']
     self.locales = ['ja_JP', 'zh_CN']
     self.first_doc = 'sample.txt'
     for fn in self.files:
         create_txt_file(fn)
     self.action.add_action(None, ['sample*.txt'], force=True)
     self.doc_ids = self.action.doc_manager.get_doc_ids()
     for doc_id in self.doc_ids:
         assert poll_doc(self.action, doc_id)
     self.action.target_action(None, self.locales, False, None, None)
 def setUp(self):
     self.downloaded_files = []
     self.action = Action(os.getcwd())
     self.action.clean_action(False, False, None)
     self.files = ['sample.txt', 'sample1.txt']
     self.locales = ['ja_JP', 'zh_CN']
     self.first_doc = 'sample.txt'
     for fn in self.files:
         create_txt_file(fn)
     os.system('ltk add sample*.txt -o') # Let the command line handle parsing the file pattern
     self.doc_ids = self.action.doc_manager.get_doc_ids()
     for doc_id in self.doc_ids:
         assert poll_doc(self.action, doc_id)
     self.action.target_action(None, None, self.locales, False, None, None)
class TestDownload(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        create_config()

    @classmethod
    def tearDownClass(cls):
        cleanup()

    def setUp(self):
        self.downloaded_files = []
        self.action = Action(os.getcwd())
        self.files = ['sample.txt', 'sample1.txt']
        self.locales = ['ja_JP', 'zh_CN']
        self.first_doc = 'sample.txt'
        for fn in self.files:
            create_txt_file(fn)
        self.action.add_action(None, ['sample*.txt'], force=True)
        self.doc_ids = self.action.doc_manager.get_doc_ids()
        for doc_id in self.doc_ids:
            assert poll_doc(self.action, doc_id)
        self.action.target_action(None, self.locales, False, None, None)

    def tearDown(self):
        for curr_file in self.files:
            self.action.rm_action(curr_file, True)
        self.action.clean_action(False, False, None)
        for dl_file in self.downloaded_files:
            os.remove(dl_file)

    def get_dl_path(self, locale, document):
        name_parts = document.split('.')
        if len(name_parts) > 1:
            name_parts.insert(-1, locale)
            downloaded_name = '.'.join(part for part in name_parts)
        else:
            downloaded_name = name_parts[0] + '.' + locale
        dl_path = os.path.join(self.action.path, downloaded_name)
        return dl_path

    def test_download_name(self):
        self.action.download_by_name(self.first_doc, self.locales[0], False)
        dl_file = self.get_dl_path(self.locales[0], self.first_doc)
        assert self.locales[0] in dl_file
        assert os.path.isfile(dl_file)
        self.downloaded_files.append(dl_file)

    def test_pull_all(self):
        for document in self.files:
            for locale in self.locales:
                dl_file = self.get_dl_path(locale, document)
                self.downloaded_files.append(dl_file)

        self.action.pull_action(None, False)
        for path in self.downloaded_files:
            assert os.path.isfile(path)

    def test_pull_locale(self):
        for document in self.files:
            dl_file = self.get_dl_path(self.locales[0], document)
            self.downloaded_files.append(dl_file)
        self.action.pull_action(self.locales[0], False)
        for path in self.downloaded_files:
            assert os.path.isfile(path)
Exemplo n.º 10
0
class TestAdd(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        create_config()

    @classmethod
    def tearDownClass(cls):
        cleanup()

    def setUp(self):
        self.action = Action(os.getcwd())
        self.action.clean_action(False, False, None)
        self.added_files = []

    def tearDown(self):
        for fn in self.added_files:
            self.action.rm_action(fn, force=True)
        self.action.clean_action(False, False, None)
        self.action.close()

    def test_add_db(self):
        # check that document is added to db
        file_name = 'sample.txt'
        self.added_files.append(file_name)
        create_txt_file(file_name)
        self.action.add_action(None, [file_name], force=True)
        doc_id = self.action.doc_manager.get_doc_ids()[0]
        poll_doc(self.action, doc_id)
        # check that document is added in db
        assert self.action.doc_manager.get_doc_by_prop('name', file_name)

    def test_add_remote(self):
        # check that document is added to Lingotek
        file_name = 'sample.txt'
        self.added_files.append(file_name)
        create_txt_file(file_name)
        self.action.add_action(None, [file_name], force=True)
        doc_id = self.action.doc_manager.get_doc_ids()[0]
        assert poll_doc(self.action, doc_id)

    def test_add_pattern_db(self):
        # test that adding with a pattern gets all expected matches in local db
        files = ['sample.txt', 'sample1.txt', 'sample2.txt']
        self.added_files = files
        for fn in files:
            create_txt_file(fn)
        self.action.add_action(None, ['sample*.txt'])
        for fn in files:
            doc = self.action.doc_manager.get_doc_by_prop('name', fn)
            assert doc
            assert poll_doc(self.action, doc['id'])

    def test_add_pattern_remote(self):
        # test that adding with a pattern gets all expected matches in Lingotek
        files = ['sample.txt', 'sample1.txt', 'sample2.txt']
        self.added_files = files
        for fn in files:
            create_txt_file(fn)
        self.action.add_action(None, ['sample*.txt'])
        doc_ids = self.action.doc_manager.get_doc_ids()
        for doc_id in doc_ids:
            assert poll_doc(self.action, doc_id)
Exemplo n.º 11
0
class TestPush(unittest.TestCase):
    def setUp(self):
        create_config()
        self.downloaded = []
        self.action = Action(os.getcwd())
        self.action.clean_action(True, False, None)
        self.files = ['sample.txt', 'sample1.txt', 'sample2.txt']
        for fn in self.files:
            create_txt_file(fn)
        self.action.add_action(None, ['sample*.txt'], force=True)
        self.doc_ids = self.action.doc_manager.get_doc_ids()
        for doc_id in self.doc_ids:
            assert poll_doc(self.action, doc_id)

    def tearDown(self):
        for curr_file in self.files:
            self.action.rm_action(curr_file, force=True)
        for df in self.downloaded:
            os.remove(df)
        self.action.clean_action(True, False, None)
        self.action.close()
        cleanup()

    def test_push_1(self):
        append_file(self.files[0])
        locales = ['ja_JP']
        test_doc_id = self.action.doc_manager.get_doc_by_prop('file_name',self.files[0])['id']
        self.action.target_action(None, locales, False, None, None, test_doc_id)
        with open(self.files[0]) as f:
            downloaded = f.read()
        self.action.push_action()
        assert check_updated_ids(self.action, [test_doc_id]) # Poll and wait until the modification has taken effect on the cloud
        downloaded_path = self.action.download_action(test_doc_id, None, False)
        self.downloaded.append(downloaded_path)
        with open(downloaded_path, 'r') as f:
            downloaded = f.read()
        print (downloaded)
        assert "Appended text. " in downloaded
        assert "This is a sample text file. " in downloaded

    def test_push_mult(self):
        append_file(self.files[0])
        append_file(self.files[1])
        doc_id0 = self.action.doc_manager.get_doc_by_prop('file_name',self.files[0])['id']
        doc_id1 = self.action.doc_manager.get_doc_by_prop('file_name',self.files[1])['id']
        locales = ['ja_JP']
        self.action.target_action(None, locales, False, None, None, doc_id0)
        self.action.target_action(None, locales, False, None, None, doc_id1)
        self.action.push_action()
        assert check_updated_ids(self.action, [doc_id0, doc_id1]) # Poll and wait until the modification has taken effect on the cloud
        dl_path = self.action.download_action(doc_id0, None, False)
        dl_path1 = self.action.download_action(doc_id1, None, False)
        self.downloaded = [dl_path, dl_path1]        
        for path in self.downloaded:
            with open(path, 'r') as f:
                downloaded = f.read()
            print (downloaded)
            assert "Appended text. " in downloaded
            assert "This is a sample text file. " in downloaded

    def test_push_none(self):
        try:
            out = StringIO()
            sys.stdout = out
            self.action.push_action()
            info = out.getvalue()
            assert 'All documents up-to-date with Lingotek Cloud.' in info
        finally:
            sys.stdout = sys.__stdout__
class TestRequest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        create_config()

    @classmethod
    def tearDownClass(cls):
        cleanup()

    def setUp(self):
        self.action = Action(os.getcwd())
        self.action.clean_action(True, False, None)
        self.files = ['sample.txt', 'sample1.txt', 'sample2.txt']
        self.first_doc = 'sample.txt'
        for fn in self.files:
            create_txt_file(fn)
        self.action.add_action(None, ['sample*.txt'], force=True)
        self.doc_ids = self.action.doc_manager.get_doc_ids()
        for doc_id in self.doc_ids:
            assert poll_doc(self.action, doc_id)

    def tearDown(self):
        for curr_file in self.files:
            self.action.rm_action(curr_file, force=True)
        self.action.clean_action(True, False, None)
        self.action.close()

    def check_locales_exist(self, documents, locales):
        for document in documents:
            curr_doc = self.action.doc_manager.get_doc_by_prop('name', document)
            return all(locale in curr_doc['locales'] for locale in locales)

    def test_request_one_locale_doc(self):
        locales = ['ja_JP']
        self.action.target_action(self.first_doc, locales, False, None, None)
        assert self.check_locales_exist([self.first_doc], locales)

    def test_request_mult_locale_doc(self):
        locales = ['ja_JP', 'zh_CN', 'es_MX']
        self.action.target_action(self.first_doc, locales, False, None, None)
        assert self.check_locales_exist([self.first_doc], locales)

    def test_request_one_locale_proj(self):
        locales = ['ja_JP']
        self.action.target_action(None, locales, False, None, None)
        assert self.check_locales_exist(self.files, locales)

    def test_request_mult_locale_proj(self):
        locales = ['ja_JP', 'zh_CN', 'es_MX']
        self.action.target_action(None, locales, False, None, None)
        assert self.check_locales_exist(self.files, locales)

    def test_delete_locale_doc(self):
        locales = ['ja_JP']
        self.action.target_action(self.first_doc, locales, False, None, None)
        assert self.check_locales_exist([self.first_doc], locales)
        self.action.target_action(self.first_doc, locales, True, None, None)
        assert not self.check_locales_exist([self.first_doc], locales)

    def test_delete_locale_proj(self):
        locales = ['ja_JP']
        self.action.target_action(None, locales, False, None, None)
        assert self.check_locales_exist([self.first_doc], locales)
        self.action.target_action(None, locales, True, None, None)
        assert not self.check_locales_exist(self.files, locales)
Exemplo n.º 13
0
 def setUp(self):
     self.action = Action(os.getcwd())
     self.action.clean_action(False, False, None)
     self.added_files = []
     self.added_directories = []
Exemplo n.º 14
0
class TestAdd(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        create_config()

    @classmethod
    def tearDownClass(cls):
        cleanup()

    def setUp(self):
        self.action = Action(os.getcwd())
        self.action.clean_action(False, False, None)
        self.added_files = []
        self.added_directories = []

    def tearDown(self):
        for fn in self.added_files:
            self.action.rm_action(fn, force=True)

        for d in self.added_directories:
            self.action.rm_action(d, force=True)
            delete_directory(d)

        self.action.clean_action(False, False, None)
        self.action.close()

    def test_add_db(self):
        # check that document is added to db
        file_name = 'sample.txt'
        self.added_files.append(file_name)
        create_txt_file(file_name)
        self.action.add_action([file_name], force=True)
        doc_id = self.action.doc_manager.get_doc_ids()[0]
        poll_doc(self.action, doc_id)

        assert self.action.doc_manager.get_doc_by_prop('name', file_name)
        delete_file(file_name)

    def test_add_remote(self):
        # check that document is added to Lingotek
        file_name = 'sample.txt'
        self.added_files.append(file_name)
        create_txt_file(file_name)
        self.action.add_action([file_name], force=True)
        doc_id = self.action.doc_manager.get_doc_ids()[0]
        assert poll_doc(self.action, doc_id)

    def test_add_pattern_db(self):
        # test that adding with a pattern gets all expected matches in local db
        files = ['sample.txt', 'sample1.txt', 'sample2.txt']
        self.added_files = files
        for fn in files:
            create_txt_file(fn)
        # self.action.add_action(['sample*.txt'])
        os.system('ltk add sample*.txt') # Let the command line handle parsing the file pattern
        for fn in files:
            doc = self.action.doc_manager.get_doc_by_prop('name', fn)
            assert doc
            assert poll_doc(self.action, doc['id'])

    def test_add_pattern_remote(self):
        # test that adding with a pattern gets all expected matches in Lingotek
        files = ['sample.txt', 'sample1.txt', 'sample2.txt']
        self.added_files = files
        for fn in files:
            create_txt_file(fn)
        # self.action.add_action(['sample*.txt'])
        os.system('ltk add sample*.txt') # Let the command line handle parsing the file pattern
        doc_ids = self.action.doc_manager.get_doc_ids()
        for doc_id in doc_ids:
            assert poll_doc(self.action, doc_id)

    ''' Test that a directory, and documents inside directory, are added to the db '''
    def test_add_directory(self):

        #test add an empty directory
        directory = 'test_add_empty_directory'
        dir_path = os.path.join(os.getcwd(), directory)
        self.added_directories.append(dir_path)
        create_directory(dir_path)
        self.action.add_action([dir_path], force=True)

        assert self.action._is_folder_added(dir_path)
        delete_directory(dir_path)

        #test add a directory with documents inside
        directory = 'test_add_full_directory'
        dir_path = os.path.join(os.getcwd(), directory)
        self.added_directories.append(dir_path)
        create_directory(dir_path)

        files = ['sample.txt', 'sample1.txt', 'sample2.txt']
        self.added_files = files
        for fn in files:
            create_txt_file(fn, dir_path)

        self.action.add_action([dir_path], force=True)

        assert self.action._is_folder_added(dir_path)
        for fn in files:
            assert self.action.doc_manager.get_doc_by_prop('name', fn)

        #delete the files and directories created
        for fn in files:
            delete_file(fn, dir_path)

        delete_directory(dir_path)

    ''' Test adding a directory with a document inside gets added to Lingotek '''
    def test_add_remote_directory(self):

        directory = 'test_add_full_directory'
        dir_path = os.path.join(os.getcwd(), directory)
        file_name = 'file_inside_directory.txt'
        self.added_directories.append(dir_path)
        create_directory(dir_path)
        self.added_files.append(file_name)
        create_txt_file(file_name, dir_path)
        self.action.add_action([dir_path], force=True)

        doc_id = self.action.doc_manager.get_doc_ids()[0]
        assert poll_doc(self.action, doc_id)
Exemplo n.º 15
0
 def setUp(self):
     self.action = Action(os.getcwd())
     self.action.clean_action(True, False, None)
Exemplo n.º 16
0
class TestList(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        create_config()

    @classmethod
    def tearDownClass(cls):
        cleanup()

    def setUp(self):
        self.action = Action(os.getcwd())
        self.action.clean_action(True, False, None)

    def tearDown(self):
        self.action.clean_action(True, False, None)
        self.action.close()

    def test_list_doc(self):
        files = ["sample.txt", "sample1.txt", "sample2.txt"]
        file_paths = []
        for fn in files:
            file_paths.append(create_txt_file(fn))
        self.action.add_action(["sample*.txt"], overwrite=True)
        doc_ids = self.action.doc_manager.get_doc_ids()
        for doc_id in doc_ids:
            assert poll_doc(self.action, doc_id)
        try:
            out = StringIO()
            sys.stdout = out
            self.action.list_ids_action(False)
            info = out.getvalue()
            for doc_id in doc_ids:
                assert doc_id in info
        finally:
            sys.stdout = sys.__stdout__

        for fn in files:
            self.action.rm_action(fn, force=True)
        self.action.clean_action(False, False, None)

    def test_list_no_docs(self):
        try:
            out = StringIO()
            sys.stdout = out
            self.action.list_ids_action(False)
            info = out.getvalue()
            assert "No local documents" in info
        finally:
            sys.stdout = sys.__stdout__

    def test_list_workflow(self):
        try:
            out = StringIO()
            sys.stdout = out
            self.action.list_workflow_action()
            info = out.getvalue()
            assert "Workflows" in info
            assert "c675bd20-0688-11e2-892e-0800200c9a66" in info
            assert "Machine Translation" in info
        finally:
            sys.stdout = sys.__stdout__

    def test_list_locale(self):
        try:
            out = StringIO()
            sys.stdout = out
            self.action.list_locale_action()
            info = out.getvalue()
            assert "ar_AE (Arabic, United Arab Emirates)" in info
            assert "zh_TW (Chinese, Taiwan)" in info
        finally:
            sys.stdout = sys.__stdout__

    def test_list_format(self):
        try:
            out = StringIO()
            sys.stdout = out
            self.action.list_format_action()
            info = out.getvalue()
            assert info.startswith("Lingotek Cloud accepts content")
            assert "CSV" in info
            assert "XML_OKAPI" in info
        finally:
            sys.stdout = sys.__stdout__

    def test_list_filters_default(self):
        try:
            out = StringIO()
            sys.stdout = out
            self.action.list_filter_action()
            info = out.getvalue()
            decoded_info = info
            assert "Filters:" in info
            assert "*****@*****.**" in info
            assert "0e79f34d-f27b-4a0c-880e-cd9181a5d265" in info
        finally:
            sys.stdout = sys.__stdout__

    def test_list_filters_custom(self):
        # create custom filters
        # list
        # check
        pass
Exemplo n.º 17
0
class TestClean(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        create_config()

    @classmethod
    def tearDownClass(cls):
        cleanup()

    def setUp(self):
        self.action = Action(os.getcwd())
        self.action.clean_action(False, False, None)
        self.files = ['sample.txt', 'sample1.txt', 'sample2.txt']
        self.forced = []
        for fn in self.files:
            create_txt_file(fn)
        self.action.add_action(None, ['sample*.txt'], force=True)
        self.entries = self.action.doc_manager.get_all_entries()
        for entry in self.entries:
            assert poll_doc(self.action, entry['id'])

    def tearDown(self):
        for curr_file in self.files:
            if curr_file in self.forced:
                continue
            self.action.rm_action(curr_file, force=True)
        self.action.clean_action(True, False, None)
        self.action.close()

    def test_clean(self):
        delete_id = self.entries[0]['id']
        r = self.action.api.document_delete(delete_id)
        self.forced.append(self.entries[0]['file_name'])
        assert r.status_code == 204
        assert self.action.doc_manager.get_doc_by_prop('id', delete_id)
        self.action.clean_action(False, False, None)
        assert not self.action.doc_manager.get_doc_by_prop('id', delete_id)

    def test_clean_force(self):
        delete_id = self.entries[0]['id']
        doc_name = self.action.doc_manager.get_doc_by_prop('id', delete_id)['file_name']
        r = self.action.api.document_delete(delete_id)
        assert r.status_code == 204
        assert self.action.doc_manager.get_doc_by_prop('id', delete_id)
        self.action.clean_action(True, False, None)
        self.forced.append(self.entries[0]['file_name'])
        assert not self.action.doc_manager.get_doc_by_prop('id', delete_id)
        assert not os.path.isfile(os.path.join(self.action.path, doc_name))

    def test_disassociate(self):
        self.action.clean_action(False, True, None)
        for entry in self.entries:
            assert not self.action.doc_manager.get_doc_by_prop('id', entry['id'])
            delete_file(entry['file_name'])
            self.action.api.document_delete(entry['id'])
            self.forced.append(entry['file_name'])

    def test_clean_single(self):
        delete_id = self.entries[0]['id']
        doc_name = self.entries[0]['file_name']
        self.action.clean_action(False, False, doc_name)
        delete_file(doc_name)
        self.action.api.document_delete(delete_id)
        self.forced.append(doc_name)
        assert not self.action.doc_manager.get_doc_by_prop('id', delete_id)
Exemplo n.º 18
0
class TestPush(unittest.TestCase):
    def setUp(self):
        create_config()
        self.downloaded = []
        self.action = Action(os.getcwd())
        self.action.clean_action(True, False, None)
        self.files = ['sample.txt', 'sample1.txt', 'sample2.txt']
        for fn in self.files:
            create_txt_file(fn)
        os.system('ltk add sample*.txt -o') # Let the command line handle parsing the file pattern
        self.doc_ids = self.action.doc_manager.get_doc_ids()
        for doc_id in self.doc_ids:
            assert poll_doc(self.action, doc_id)

    def tearDown(self):
        #delete files added to lingotek cloud
        for curr_file in self.files:
            self.action.rm_action(curr_file, force=True)

        #delete downloaded translations
        for df in self.downloaded:
            os.remove(df)

        delete_directory("es_AR")

        self.downloaded = []
        self.action.clean_action(True, False, None)
        self.action.close()
        cleanup()

    def test_push_1(self):
        append_file(self.files[0])
        locales = ['es_AR']
        test_doc_id = self.action.doc_manager.get_doc_by_prop('file_name',self.files[0])['id']
        self.action.target_action(self.files[0], None, locales, False, None, None, test_doc_id)
        with open(self.files[0]) as f:
            downloaded = f.read()
        self.action.push_action()
        assert check_updated_ids(self.action, [test_doc_id]) # Poll and wait until the modification has taken effect in the cloud
        downloaded_path = self.action.download_action(test_doc_id, locales[0], False)
        #print("downloaded_path: "+str(downloaded_path))
        self.downloaded.append(downloaded_path)
        with open(downloaded_path, 'r') as f:
            downloaded_text = f.read()
            #print ("Downloaded_text: " + downloaded)

        assert "Texto agregado." in downloaded_text
        assert "Este es un ejemplo de archivo de texto." in downloaded_text

    def test_push_mult(self):
        append_file(self.files[0])
        append_file(self.files[1])
        locales = ['es_AR']
        test_doc_id_0 = self.action.doc_manager.get_doc_by_prop('file_name',self.files[0])['id']
        test_doc_id_1 = self.action.doc_manager.get_doc_by_prop('file_name',self.files[1])['id']
        self.action.target_action(self.files[0], None, locales, False, None, None, test_doc_id_0)
        self.action.target_action(self.files[1], None, locales, False, None, None, test_doc_id_1)
        self.action.push_action()
        assert check_updated_ids(self.action, [test_doc_id_0, test_doc_id_1]) # Poll and wait until the modification has taken effect on the cloud
        dl_path_0 = self.action.download_action(test_doc_id_0, locales[0], False)
        dl_path_1 = self.action.download_action(test_doc_id_1, locales[0], False)
        self.downloaded = [dl_path_0, dl_path_1]
        for path in self.downloaded:
            with open(path, 'r') as f:
                downloaded_text = f.read()
                #print("downloaded_text: "+downloaded_text)

            assert "Texto agregado." in downloaded_text
            assert "Este es un ejemplo de archivo de texto." in downloaded_text

    def test_push_none(self):
        try:
            # out = StringIO()
            # sys.stdout = out
            assert not self.action.push_action()
            # info = out.getvalue()
            # assert 'All documents up-to-date with Lingotek Cloud.' in info
        finally:
            sys.stdout = sys.__stdout__
Exemplo n.º 19
0
 def setUp(self):
     self.action = Action(os.getcwd())
Exemplo n.º 20
0
class TestPush(unittest.TestCase):
    def setUp(self):
        create_config()
        self.downloaded = []
        self.action = Action(os.getcwd())
        self.files = ['sample.txt', 'sample1.txt', 'sample2.txt']
        for fn in self.files:
            create_txt_file(fn)
        self.action.add_action(None, ['sample*.txt'], force=True)
        self.doc_ids = self.action.doc_manager.get_doc_ids()
        for doc_id in self.doc_ids:
            assert poll_doc(self.action, doc_id)

    def tearDown(self):
        for curr_file in self.files:
            self.action.rm_action(curr_file, True)
        for df in self.downloaded:
            os.remove(df)
        self.action.clean_action(False, False, None)
        cleanup()

    def test_push_1(self):
        append_file(self.files[0])
        locales = ['ja_JP']
        self.action.target_action(self.doc_ids[0], locales, False, None, None)
        with open('sample.txt') as f:
            downloaded = f.read()
            print (downloaded)
        self.action.push_action()
        # currently sleep for some arbitrary time while document updates in Lingotek
        # replace when api call or some way to check if update is finished is available
        print ('pushed')
        time.sleep(20)
        # print ('now')
        downloaded_path = self.action.download_action(self.doc_ids[0], None, False)
        self.downloaded.append(downloaded_path)
        with open(downloaded_path, 'r') as f:
            downloaded = f.read()
        print (downloaded)
        assert "Appended text. " in downloaded
        assert "This is a sample text file. " in downloaded

    def test_push_mult(self):
        append_file(self.files[0])
        append_file(self.files[1])
        locales = ['ja_JP']
        self.action.target_action(self.doc_ids[0], locales, False, None, None)
        self.action.target_action(self.doc_ids[1], locales, False, None, None)
        self.action.push_action()
        time.sleep(20)  # see test_push_1 comment
        dl_path = self.action.download_action(self.doc_ids[0], None, False)
        dl_path1 = self.action.download_action(self.doc_ids[1], None, False)
        self.downloaded = [dl_path, dl_path1]        
        for path in self.downloaded:
            with open(path, 'r') as f:
                downloaded = f.read()
            print (downloaded)
            assert "Appended text. " in downloaded
            assert "This is a sample text file. " in downloaded

    def test_push_none(self):
        from io import BytesIO
        import sys
        try:
            out = StringIO()
            sys.stdout = out
            self.action.push_action()
            info = out.getvalue()
            assert 'All documents up-to-date with Lingotek Cloud.' in info
        finally:
            sys.stdout = sys.__stdout__
Exemplo n.º 21
0
class TestList(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        create_config()

    @classmethod
    def tearDownClass(cls):
        cleanup()

    def setUp(self):
        self.action = Action(os.getcwd())

    def test_list_doc(self):
        files = ['sample.txt', 'sample1.txt', 'sample2.txt']
        file_paths = []
        for fn in files:
            file_paths.append(create_txt_file(fn))
        self.action.add_action(None, ['sample*.txt'], force=True)
        doc_ids = self.action.doc_manager.get_doc_ids()
        for doc_id in doc_ids:
            assert poll_doc(self.action, doc_id)
        try:
            out = StringIO()
            sys.stdout = out
            self.action.list_ids_action()
            info = out.getvalue()
            for doc_id in doc_ids:
                assert doc_id in info
        finally:
            sys.stdout = sys.__stdout__

        for fn in files:
            self.action.rm_action(fn, True)
        self.action.clean_action(False, False, None)

    def test_list_no_docs(self):
        try:
            out = StringIO()
            sys.stdout = out
            self.action.list_ids_action()
            info = out.getvalue()
            assert 'no documents' in info
        finally:
            sys.stdout = sys.__stdout__

    def test_list_workflow(self):
        try:
            out = StringIO()
            sys.stdout = out
            self.action.list_workflow_action()
            info = out.getvalue()
            assert 'workflows' in info
            assert 'c675bd20-0688-11e2-892e-0800200c9a66' in info
            assert 'Machine Translation' in info
        finally:
            sys.stdout = sys.__stdout__

    def test_list_locale(self):
        try:
            out = StringIO()
            sys.stdout = out
            self.action.list_locale_action()
            info = out.getvalue()
            assert 'ar_AE (Arabic, United Arab Emirates)' in info
            assert 'zh_TW (Chinese, Taiwan)' in info
        finally:
            sys.stdout = sys.__stdout__

    def test_list_format(self):
        try:
            out = StringIO()
            sys.stdout = out
            self.action.list_format_action()
            info = out.getvalue()
            assert info.startswith('Formats Lingotek supports')
            assert 'CSV' in info
            assert 'XML_OKAPI' in info
        finally:
            sys.stdout = sys.__stdout__

    def test_list_filters_default(self):
        try:
            out = StringIO()
            sys.stdout = out
            self.action.list_filter_action()
            info = out.getvalue()
            decoded_info = info
            assert 'filters:' in info
            assert '*****@*****.**' in info
            assert '0adc9a9d-ca67-4217-9525-d5a6af7ba91f' in info
        finally:
            sys.stdout = sys.__stdout__

    def test_list_filters_custom(self):
        # create custom filters
        # list
        # check
        pass