Ejemplo n.º 1
0
def test_run_and_wait_infinite():
    exp_msg = 'ERROR'

    def func():
        raise Exception(exp_msg)

    with pytest.raises(Exception) as err:
        utils.run_and_wait(func, Exception, exp_msg, retries=1)

    assert exp_msg == str(err.value)
Ejemplo n.º 2
0
def test_run_and_wait_with_params():
    test_in = 'test'

    def func(a):
        return a

    assert test_in == utils.run_and_wait(func, Exception, '', a=test_in)
Ejemplo n.º 3
0
def test_run_and_wait_no_err():
    exp_out = 'test'

    def func():
        return exp_out

    assert exp_out == utils.run_and_wait(func, Exception, '')
Ejemplo n.º 4
0
def create_project(args, api, source):
    """Create a project.

    Parameters
    ----------
    args: argparse.Namespace
        The arguments parsed by the main script.
    api: XTMCloudAPI
        Used for interacting with the project.
    source: FileSource
        Representing the website the project is created for.

    """
    config = source.read_config()

    try:
        project_id = config.get(const.Config.XTM_SECTION,
                                const.Config.PROJECT_OPTION)
        sys.exit(const.ErrorMessages.PROJECT_EXISTS.format(project_id))
    except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
        pass

    target_langs = utils.map_locales(source)

    files_to_upload = utils.get_files_to_upload(source)

    try:
        name = utils.sanitize_project_name(args.name)
        logging.info(const.InfoMessages.PROJECT_NAME_CREATING.format(name))
        logging.info(
            const.InfoMessages.UPLOADING_FILES.format(len(files_to_upload)), )

        project_id, resulting_jobs = utils.run_and_wait(
            api.create_project,
            XTMCloudException,
            const.UNDER_ANALYSIS_MESSAGE,
            const.InfoMessages.WAITING_FOR_PROJECT,
            name=name,
            description=args.desc,
            reference_id=args.ref_id,
            target_languages=target_langs,
            customer_id=args.client_id,
            workflow_id=utils.extract_workflow_id(api, args),
            source_language=args.source_lang,
            files=files_to_upload,
        )
    except Exception as err:
        sys.exit(err)

    logging.info(const.InfoMessages.PROJECT_CREATED.format(project_id))
    utils.log_resulting_jobs(resulting_jobs)

    if args.save_id:
        source.write_to_config(
            const.Config.XTM_SECTION,
            const.Config.PROJECT_OPTION,
            str(project_id),
        )
        logging.info(const.InfoMessages.SAVED_PROJECT_ID)
Ejemplo n.º 5
0
        project_id = config.get(const.Config.XTM_SECTION,
                                const.Config.PROJECT_OPTION)
    except ConfigParser.NoOptionError, ConfigParser.NoSectionError:
        sys.exit(const.ErrorMessages.NO_PROJECT.format(source.get_path('')))

    files_to_upload = utils.get_files_to_upload(source)
    logging.info(
        const.InfoMessages.UPLOADING_FILES.format(len(files_to_upload)), )
    try:
        utils.resolve_locales(api, source)

        new_jobs = utils.run_and_wait(
            api.upload_files,
            XTMCloudException,
            const.UNDER_ANALYSIS_MESSAGE,
            const.InfoMessages.WAITING_FOR_PROJECT,
            files=files_to_upload,
            project_id=project_id,
            overwrite=not args.no_overwrite,
        )

        logging.info(const.InfoMessages.FILES_UPLOADED)
        utils.log_resulting_jobs(new_jobs)
    except XTMCloudException as err:
        sys.exit(err)


def download_files(args, api, source):
    """Download the translation files and save them as locales.

    Parameters