コード例 #1
0
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)
コード例 #2
0
def test_token_generation(intercept, credentials, is_ok, err_msg, exp_token):
    """Test the API token generation."""
    if is_ok:
        token = get_token(*credentials)
        assert token == exp_token
    else:
        exception_test(get_token, XTMCloudException, err_msg, *credentials)
コード例 #3
0
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)
コード例 #4
0
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)
コード例 #5
0
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
コード例 #6
0
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))
コード例 #7
0
def test_remote_to_local_exception(temp_site):
    test_in = '___foo___bar___faz___test.json'
    exp_msg = const.ErrorMessages.CANT_RESOLVE_REMOTE_LANG.format('foo')

    exception_test(utils.remote_to_local,
                   Exception,
                   exp_msg,
                   test_in,
                   str(temp_site),
                   locales=['bar'])
コード例 #8
0
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
コード例 #9
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
コード例 #10
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)
コード例 #11
0
def test_dynamic_builtins_not_found(dynamic_server_builtins):
    filename = 'en/no-page-here'
    exp_msg = 'Not Found'

    exception_test(urllib2.urlopen, urllib2.HTTPError, exp_msg,
                   dynamic_server_builtins + filename)
コード例 #12
0
def test_dynamic_werkzeug_not_found(dynamic_server_werkzeug):
    filename = 'en/no-page-here'
    exp_msg = 'Not Found'

    exception_test(urllib2.urlopen, urllib2.HTTPError, exp_msg,
                   dynamic_server_werkzeug + filename)