def test_workflow_id_extraction(intercept, token, name, exp_err, exp_msg,
                                exp_ids):
    api = XTMCloudAPI(token)
    if exp_msg is not None:
        exception_test(api.get_workflows_by_name, exp_err, exp_msg, name)
    else:
        assert exp_ids == api.get_workflows_by_name(name)
def test_file_upload(intercept, token, project_id, files, exp_err, exp_msg,
                     exp_jobs):
    """Test file uploading."""
    api = XTMCloudAPI(token)
    if exp_msg is not None:
        exception_test(api.upload_files, exp_err, exp_msg, files, project_id)
    else:
        assert exp_jobs == api.upload_files(files, project_id)
def test_adding_target_language(intercept, token, project_id, new_langs,
                                exp_msg):
    """Test adding target languages."""
    api = XTMCloudAPI(token)

    if exp_msg:
        exception_test(api.add_target_languages, XTMCloudException, exp_msg,
                       project_id, new_langs)
    else:
        api.add_target_languages(project_id, new_langs)
def test_project_creation(intercept, token, files, args, exp_msg, exp_jobs):
    """Test creation of files behaves appropriately."""
    api = XTMCloudAPI(token)

    if exp_msg:
        exception_test(api.create_project, XTMCloudException, exp_msg, *args)
    else:
        project_id, jobs = api.create_project(*args, files=files)
        assert project_id == 1234
        assert exp_jobs == jobs
def test_file_download(intercept_populated, token, project_id, exp_msg):
    """Test file downloading."""
    api = XTMCloudAPI(token)

    if exp_msg:
        exception_test(api.download_files, XTMCloudException, exp_msg,
                       project_id)
    else:
        contents = api.download_files(project_id)
        zipfile.ZipFile(BytesIO(contents))
def test_extracting_target_languages(intercept, token, project_id, exp_langs,
                                     exp_msg):
    """Test extraction of target languages."""
    api = XTMCloudAPI(token)

    if exp_msg:
        exception_test(api.get_target_languages, XTMCloudException, exp_msg,
                       project_id)
    else:
        langs = api.get_target_languages(project_id)

        assert exp_langs == langs
예제 #7
0
def test_resolve_locales_adds_langs(intercept, temp_site):
    """Test if locales are resolved correctly.

    In this environment, new target languages are added.
    """
    api = XTMCloudAPI(_API_TOKEN_VALID)
    source = FileSource(str(temp_site))
    source.write_to_config('XTM', 'project_id', str(_PROJECT_ID))
    exp_targets = {'de_DE'}

    utils.resolve_locales(api, source)

    assert exp_targets == api.get_target_languages(_PROJECT_ID)
예제 #8
0
def test_resolve_locales_raise_exception(intercept_populated, temp_site):
    """Test if locales are resolved correctly.

    In this environment, the API has more target languages configured than are
    available online. We except an exception to be raised.
    """
    api = XTMCloudAPI(_API_TOKEN_VALID)
    api.add_target_languages(_PROJECT_ID, ['ro_RO'])
    source = FileSource(str(temp_site))
    source.write_to_config('XTM', 'project_id', str(_PROJECT_ID))
    exp_msg = ('The following languages are enabled in the API, but not '
               "listed in locales: set(['ro_RO'])! Please remove them manually"
               ' from project number 1234 and then re-run the script!')

    exception_test(utils.resolve_locales, Exception, exp_msg, api, source)
예제 #9
0
def handle_projects(args):
    try:
        api = XTMCloudAPI(read_token())
    except Exception as err:
        sys.exit(err)
    with create_source(args.source_dir, cached=True) as fs:
        args.projects_func(args, api, fs)
예제 #10
0
def test_resolve_locales(intercept_populated, temp_site):
    """Test if locales are resolved correctly.

    In this environment, no languages have to be added.
    """
    api = XTMCloudAPI(_API_TOKEN_VALID)
    source = FileSource(str(temp_site))
    source.write_to_config('XTM', 'project_id', str(_PROJECT_ID))

    utils.resolve_locales(api, source)
예제 #11
0
def test_handle_workflows(intercept, id_in, name, exp_err, exp_msg, exp_id):
    """"""
    namespace = XtmMockArgs.CreationArgsNamespace()
    namespace.workflow_id = id_in
    namespace.workflow_name = name

    api = XTMCloudAPI(_API_TOKEN_VALID)

    if exp_err:
        exception_test(utils.extract_workflow_id, exp_err, exp_msg, api,
                       namespace)
    else:
        id_out = utils.extract_workflow_id(api, namespace)

        assert id_out == exp_id