예제 #1
0
def test_workflow_registration_generic_link(app_client, client_auth_method,
                                            user1, user1_auth,
                                            client_credentials_registry,
                                            valid_workflow):
    logger.debug("User: %r", user1)
    logger.debug("headers: %r", user1_auth)

    workflow = {
        'uuid': str(uuid.uuid4()),
        'version': '1',
        'roc_link':
        "http://webserver:5000/download?file=ro-crate-galaxy-sortchangecase.crate.zip",
        'name': 'Galaxy workflow from Generic Link',
        'testing_service_type': 'jenkins',
        'authorization': app_client.application.config['WEB_SERVER_AUTH_TOKEN']
    }
    logger.debug("Selected workflow: %r", workflow)
    logger.debug("Using oauth2 user: %r", user1)
    assert workflow['name'] is not None, "MMMMM"
    logger.debug("The BODY: %r", workflow)
    response = app_client.post(utils.build_workflow_path(),
                               json=workflow,
                               headers=user1_auth)

    logger.debug("The actual response: %r", response.data)
    utils.assert_status_code(201, response.status_code)
    data = json.loads(response.data)
    logger.debug("Response data: %r", data)
    assert data['wf_uuid'] == workflow['uuid'] and data['wf_version'] == workflow['version'], \
        "Response should be equal to the workflow UUID"
예제 #2
0
def test_workflow_registration_same_workflow_by_different_users(
        app_client, client_auth_method, user1, user1_auth, user2, user2_auth,
        client_credentials_registry):
    original_workflow = utils.pick_workflow(user1, name='sort-and-change-case')
    assert len(models.Workflow.all()) == 0, "Unexpected number of workflows"
    for user, user_auth in [(user1, user1_auth), (user2, user2_auth)]:
        workflow = original_workflow.copy()
        logger.debug("Selected workflow: %r", workflow)
        logger.debug("User: %r", user)
        logger.debug("headers: %r", user_auth)
        logger.debug("Using oauth2 user: %r", user)
        # When the client is a registry and it uses the ClientCredentials auth flow,
        # it must provide the submitter ID
        if client_auth_method == ClientAuthenticationMethod.CLIENT_CREDENTIALS:
            workflow['submitter_id'] = \
                list(user1["user"].oauth_identity.values())[0].provider_user_id
        elif client_auth_method in [
                ClientAuthenticationMethod.AUTHORIZATION_CODE,
                ClientAuthenticationMethod.API_KEY
        ]:
            workflow['registry'] = client_credentials_registry.uri
        logger.debug("The BODY: %r", workflow)
        response = app_client.post(utils.build_workflow_path(),
                                   json=workflow,
                                   headers=user_auth)
        logger.debug("The actual response: %r", response.data)
        if user == user1:
            utils.assert_status_code(201, response.status_code)
            data = json.loads(response.data)
            logger.debug("Response data: %r", data)
            assert data['wf_uuid'] == workflow['uuid'] and data['wf_version'] == workflow['version'], \
                "Response should be equal to the workflow UUID"
        else:
            utils.assert_status_code(409, response.status_code)
예제 #3
0
def test_get_workflow_version(app_client, client_auth_method, user1,
                              user1_auth, valid_workflow):
    workflow = utils.pick_workflow(user1, valid_workflow)
    wv1 = workflow.copy()
    wv2 = workflow.copy()

    wv1['version'] = "1"
    wv2['version'] = "2"
    utils.register_workflow(user1, wv1)
    utils.register_workflow(user1, wv2)

    response = app_client.get(utils.build_workflow_path(), headers=user1_auth)
    utils.assert_status_code(response.status_code, 200)
    workflows = json.loads(response.data)
    logger.debug("Workflows: %r", workflows)

    # Check version 1 and 2
    for v_id in (1, 2):
        url = f"{utils.build_workflow_path()}/{workflow['uuid']}/{v_id}"
        logger.debug("URL: %r", url)
        response = app_client.get(url, headers=user1_auth)
        logger.debug(response)
        utils.assert_status_code(response.status_code, 200)
        data = json.loads(response.data)
        logger.debug("Response data: %r", data)
        assert data['uuid'] == workflow['uuid'], "Unexpected workflow ID"
        assert data['version'][
            'version'] == f"{v_id}", "Unexpected workflow version number: it should the latest (=2)"
        assert data['version']['is_latest'] is (v_id == 2), \
            "It shouldn't be the latest version"
예제 #4
0
def test_workflow_registration_by_external_id_auto_roc_link(
        app_client, client_auth_method, user1, user1_auth,
        client_credentials_registry, valid_workflow):
    logger.debug("User: %r", user1)
    logger.debug("headers: %r", user1_auth)
    workflow = utils.pick_workflow(user1, valid_workflow)
    logger.debug("Selected workflow: %r", workflow)
    logger.debug("Using oauth2 user: %r", user1)
    # Remove the UUID and set the external identifier
    workflow['identifier'] = workflow['external_id']
    wf_uuid = workflow['uuid']
    del workflow['uuid']
    del workflow['roc_link']
    # When the client is a registry and it uses the ClientCredentials auth flow,
    # it must provide the submitter ID
    if client_auth_method == ClientAuthenticationMethod.CLIENT_CREDENTIALS:  # ClientCredentials case
        workflow['submitter_id'] = \
            list(user1["user"].oauth_identity.values())[0].provider_user_id
    logger.debug("The BODY: %r", workflow)
    response = app_client.post(utils.build_workflow_path(),
                               json=workflow,
                               headers=user1_auth)
    logger.debug("The actual response: %r", response.data)
    utils.assert_status_code(201, response.status_code)
    data = json.loads(response.data)
    logger.debug("Response data: %r", data)
    assert data['wf_uuid'] == wf_uuid and data['wf_version'] == workflow['version'], \
        "Response should be equal to the workflow UUID"
예제 #5
0
def test_empty_workflows(app_client, client_auth_method, user1, user1_auth):
    response = app_client.get(utils.build_workflow_path(), headers=user1_auth)
    utils.assert_status_code(200, response.status_code)
    assert response.data, "Empty response"
    data = json.loads(response.data)
    logger.debug("Response %r", data)
    assert len(data['items']) == 0, "Invalid number of workflows"
예제 #6
0
def test_get_instance_builds_limit_parameter(app_client, client_auth_method,
                                             user1, user1_auth,
                                             valid_workflow):
    w, workflow = utils.pick_and_register_workflow(user1, valid_workflow)
    assert len(workflow.test_suites) > 0, "Unexpected number of test suites"
    suite = workflow.test_suites[0]
    logger.debug("The test suite: %r", suite)
    assert len(suite.test_instances) > 0, "Unexpected number of test instances"
    instance = suite.test_instances[0]
    logger.debug("The test instance: %r", instance)

    # check limit parameter
    for limit in range(1, 4):
        response = app_client.get(
            f"{utils.build_instances_path(instance.uuid)}/latest-builds?limit={limit}",
            headers=user1_auth)
        logger.debug(response)
        utils.assert_status_code(200, response.status_code)
        data = json.loads(response.data)
        logger.debug("Response data: %r", data)
        # redundant check: the validation is performed by the connexion framework
        assert "items" in data, "Missing item property"
        num_items = len(data['items'])
        logger.info("Number of items: %d", num_items)
        assert num_items == limit, "Unexpected number of items"
        logger.info("Loaded builds: %s", data)
예제 #7
0
def test_get_workflow_versions(app_client, client_auth_method, user1,
                               user1_auth, valid_workflow):
    workflow = utils.pick_workflow(user1, valid_workflow)
    wv1 = workflow.copy()
    wv2 = workflow.copy()

    wv1['version'] = "1"
    wv2['version'] = "2"
    utils.register_workflow(user1, wv1)
    utils.register_workflow(user1, wv2)

    url = f"{utils.build_workflow_path()}/{workflow['uuid']}/versions"
    logger.debug("URL: %r", url)
    response = app_client.get(url, headers=user1_auth)
    logger.debug(response)
    utils.assert_status_code(200, response.status_code)
    data = json.loads(response.data)
    logger.debug("Response data: %r", data)

    assert data['workflow']['uuid'] == workflow[
        'uuid'], "Unexpected workflow ID"
    assert 'versions' in data, "Unable to find versions field"
    # Check versions
    assert len(data['versions']) == 2, "Unexpected number of versions"
    assert data['versions'][0]['is_latest'] is (data['versions'][0]['version'] == "2"), \
        "It shouldn't be the latest version"
예제 #8
0
def test_get_registries_no_authorization(app_client, fake_registry):
    response = app_client.get(utils.build_registries_path())
    utils.assert_status_code(200, response.status_code)
    assert response.data, "Empty response"
    data = json.loads(response.data)
    logger.debug("Response %r", data)
    assert len(data['items']) == 2, "Invalid number of registries"
예제 #9
0
def test_get_workflow_latest_version(app_client, client_auth_method, user1,
                                     user1_auth, valid_workflow):
    workflow = utils.pick_workflow(user1, valid_workflow)
    wv1 = workflow.copy()
    wv2 = workflow.copy()

    wv1['version'] = "1"
    wv2['version'] = "2"
    utils.register_workflow(user1, wv1)
    utils.register_workflow(user1, wv2)

    response = app_client.get(utils.build_workflow_path(), headers=user1_auth)
    utils.assert_status_code(200, response.status_code)
    workflows = json.loads(response.data)
    logger.debug("Workflows: %r", workflows)

    url = f"{utils.build_workflow_path()}/{workflow['uuid']}?previous_versions=true"
    logger.debug("URL: %r", url)
    response = app_client.get(url, headers=user1_auth)
    logger.debug(response)
    utils.assert_status_code(200, response.status_code)
    data = json.loads(response.data)
    logger.debug("Response data: %r", data)
    assert data['uuid'] == workflow['uuid'], "Unexpected workflow ID"
    assert data['version'][
        'version'] == "2", "Unexpected workflow version number: it should the latest (=2)"
    assert "previous_versions" in data, "Unable to find the versions field"
    assert "1" in [_['version'] for _ in data['previous_versions']
                   ], "Previous version not defined"
예제 #10
0
def test_get_registry_not_authorized_api_key(app_client,
                                             client_credentials_registry,
                                             client_auth_method, user1,
                                             user1_auth):
    response = app_client.get(utils.build_registries_path('current'),
                              headers=user1_auth)
    utils.assert_status_code(401, response.status_code)
예제 #11
0
def test_workflow_registration_same_workflow_by_different_users(
        app_client, client_auth_method, user1, user1_auth, user2, user2_auth,
        client_credentials_registry):
    original_workflow = utils.pick_workflow(user1, name='sort-and-change-case')
    assert len(models.Workflow.all()) == 0, "Unexpected number of workflows"
    for user, user_auth in [(user1, user1_auth), (user2, user2_auth)]:
        workflow = original_workflow.copy()
        logger.debug("Selected workflow: %r", workflow)
        logger.debug("User: %r", user)
        logger.debug("headers: %r", user_auth)
        logger.debug("Using oauth2 user: %r", user)
        body = {
            'identifier': workflow['external_id'],
            'version': workflow['version']
        }
        logger.debug("The BODY: %r", body)
        response = app_client.post(
            f"/users/{user['user_info']['id']}/workflows",
            json=body,
            headers=user_auth)
        logger.debug("The actual response: %r", response.data)
        if user == user1:
            utils.assert_status_code(201, response.status_code)
            data = json.loads(response.data)
            logger.debug("Response data: %r", data)
            assert data['wf_uuid'] == workflow['uuid'] and data['wf_version'] == workflow['version'], \
                "Response should be equal to the workflow UUID"
        else:
            utils.assert_status_code(409, response.status_code)
예제 #12
0
def test_get_current_user(app_client, client_auth_method, user1, user1_auth):
    response = app_client.get(utils.build_users_path('current'), headers=user1_auth)
    utils.assert_status_code(200, response.status_code)
    assert response.data, "Empty response"
    data = json.loads(response.data)
    logger.debug("Response %r", data)
    utils.assert_properties_exist(['username', 'id'], data)
예제 #13
0
def test_get_instance_error_not_found(m, request_context, mock_user):
    assert not auth.current_user.is_anonymous, "Unexpected user in session"
    assert auth.current_registry is not None, "Unexpected registry in session"
    m.get_test_instance.return_value = None
    response = controllers.instances_get_by_id("123456")
    m.get_test_instance.assert_called_once()
    assert_status_code(404, response.status_code)
예제 #14
0
def test_remove_instance(app_client, client_auth_method, user1, user1_auth,
                         random_valid_workflow, unmanaged_test_instance):
    w, workflow = utils.pick_and_register_workflow(user1,
                                                   random_valid_workflow)
    assert len(workflow.test_suites) > 0, "Unexpected number of test suites"
    suite = workflow.test_suites[0]
    logger.debug("The test suite: %r", suite)
    current_number_of_instances = len(suite.test_instances)
    assert current_number_of_instances > 0, "Unexpected number of test instances"

    delta = 5
    for i in range(1, delta + 1):
        suite.add_test_instance(user1['user'],
                                unmanaged_test_instance['managed'],
                                unmanaged_test_instance['name'],
                                unmanaged_test_instance['service']['type'],
                                unmanaged_test_instance['service']['url'],
                                unmanaged_test_instance['resource'])
        assert len(suite.test_instances) == current_number_of_instances + i, \
            "Unexpected number of test instances"
    count = 0
    current_number_of_instances += delta
    assert current_number_of_instances > 0, "Unexpected number of test instances"
    for instance in suite.test_instances:
        logger.debug("Removing instance: %r", instance)
        response = app_client.delete(
            f"{utils.build_instances_path(instance.uuid)}", headers=user1_auth)
        utils.assert_status_code(204, response.status_code)
        count += 1
        assert len(suite.test_instances) == current_number_of_instances - count
    assert len(suite.test_instances) == 0, "Unexpected number of instances"
예제 #15
0
def test_workflow_registration_check_default_name(app_client,
                                                  client_auth_method, user1,
                                                  user1_auth,
                                                  client_credentials_registry,
                                                  valid_workflow):
    logger.debug("User: %r", user1)
    logger.debug("headers: %r", user1_auth)
    workflow = utils.pick_workflow(user1, valid_workflow)
    logger.debug("Selected workflow: %r", workflow)
    logger.debug("Using oauth2 user: %r", user1)
    # prepare body
    body = {
        'identifier': workflow['external_id'],
        'version': workflow['version']
    }
    logger.debug("The BODY: %r", body)
    response = app_client.post(
        f'/registries/{client_credentials_registry.uuid}/workflows',
        json=body,
        headers=user1_auth)
    logger.debug("The actual response: %r", response.data)
    utils.assert_status_code(201, response.status_code)
    data = json.loads(response.data)
    logger.debug("Response data: %r", data)
    assert data['wf_uuid'] == workflow['uuid'] and data['wf_version'] == workflow['version'], \
        "Response should be equal to the workflow UUID"

    wf = utils.get_workflow_data(data['wf_uuid'])
    assert wf, "Unable to load workflow data"
    assert str(wf.uuid) == data['wf_uuid'], "Unexpected workflow uuid"
    assert wf.latest_version.version == data[
        'wf_version'], "Unexpected workflow uuid"
    assert wf.name == workflow['name'], "Unexpected workflow name"
예제 #16
0
def test_generic_workflow_registration_wo_uuid(app_client, client_auth_method,
                                               user1, user1_auth,
                                               client_credentials_registry,
                                               generic_workflow):
    logger.debug("User: %r", user1)
    logger.debug("headers: %r", user1_auth)
    workflow = generic_workflow
    logger.debug("Selected workflow: %r", workflow)
    logger.debug("Using oauth2 user: %r", user1)
    # prepare body
    body = {
        'roc_link': workflow['roc_link'],
        'version': workflow['version'],
        'authorization': workflow['authorization']
    }
    logger.debug("The BODY: %r", body)
    response = app_client.post('/users/current/workflows',
                               json=body,
                               headers=user1_auth)
    logger.debug("The actual response: %r", response.data)
    utils.assert_status_code(201, response.status_code)
    data = json.loads(response.data)
    logger.debug("Response data: %r", data)
    assert data['wf_version'] == workflow['version'], \
        "Response should be equal to the workflow UUID"
    assert data['wf_uuid'], "Workflow UUID was not generated or returned"
예제 #17
0
def test_get_registry_user_no_authorized(app_client, client_auth_method, user1,
                                         user1_auth):
    response = app_client.get(utils.build_registry_users_path(),
                              headers=user1_auth)
    if client_auth_method == ClientAuthenticationMethod.API_KEY:
        utils.assert_status_code(401, response.status_code)
    else:
        utils.assert_status_code(403, response.status_code)
예제 #18
0
def test_get_registry_user(app_client, admin_user,
                           user1, user1_auth):
    response = app_client.get(utils.build_users_path(user1['user'].id), headers=user1_auth)
    utils.assert_status_code(200, response.status_code)
    assert response.data, "Empty response"
    data = json.loads(response.data)
    logger.debug("Response %r", data)
    utils.assert_properties_exist(['username', 'id'], data)
예제 #19
0
def test_post_workflow_by_registry_error_registry_uri(m, request_context, mock_registry):
    assert auth.current_user.is_anonymous, "Unexpected user in session"
    assert auth.current_registry, "Unexpected registry in session"
    # add one fake workflow
    data = {"registry": "123456"}
    response = controllers.workflows_post(body=data)
    logger.debug("Response: %r, %r", response, str(response.data))
    assert_status_code(response.status_code, 400)
    assert messages.unexpected_registry_uri in response.data.decode(),\
        "Unexpected error message"
예제 #20
0
def test_post_workflow_by_registry_error_missing_submitter_id(m, request_context, mock_registry):
    assert auth.current_user.is_anonymous, "Unexpected user in session"
    assert auth.current_registry, "Unexpected registry in session"
    # add one fake workflow
    data = {}
    response = controllers.workflows_post(body=data)
    logger.debug("Response: %r, %r", response, str(response.data))
    assert_status_code(response.status_code, 400)
    assert messages.no_submitter_id_provided in response.data.decode(),\
        "Unexpected error message"
예제 #21
0
def test_workflow_registry_roc_not_found(app_client, client_auth_method, user1_auth):  # , valid_workflow)
    wf = {
        'uuid': uuid.uuid4(),
        'version': '1',
        'roc_link': "http://webserver:5000/download?file=I-do-not-exist.crate.zip",
        'name': 'Not a workflow',
        'authorization': app_client.application.config['WEB_SERVER_AUTH_TOKEN']
    }
    response = app_client.post('/users/current/workflows', json=wf, headers=user1_auth)
    utils.assert_status_code(400, response.status_code)
예제 #22
0
def test_get_registry_not_authorized_code_flow(app_client,
                                               client_credentials_registry,
                                               client_auth_method, user1,
                                               user1_auth):
    response = app_client.get(utils.build_registries_path('current'),
                              headers=user1_auth)
    data = json.loads(response.data)
    logger.debug("Response %r", data)
    assert "Provided token doesn't have the required scope" in data[
        "detail"], "Unexpected response"
    utils.assert_status_code(403, response.status_code)
예제 #23
0
def test_get_registry(app_client, client_credentials_registry,
                      client_auth_method, user1, user1_auth):
    response = app_client.get(utils.build_registries_path('current'),
                              headers=user1_auth)
    utils.assert_status_code(200, response.status_code)
    assert response.data, "Empty response"
    data = json.loads(response.data)
    logger.debug("Response %r", data)
    utils.assert_properties_exist(['uuid', 'name', 'uri'], data)
    assert data['uuid'] == str(client_credentials_registry.uuid), \
        "Unexpected workflow registry"
예제 #24
0
def test_get_workflow_status(app_client, client_auth_method, user1, user1_auth, valid_workflow):
    w, workflow = utils.pick_and_register_workflow(user1, valid_workflow)
    response = app_client.get(f"{utils.build_workflow_path(w, subpath='status')}", headers=user1_auth)
    logger.debug(response)
    utils.assert_status_code(200, response.status_code)
    data = json.loads(response.data)
    logger.debug("Response data: %r", data)
    assert data['uuid'] == w['uuid'], "Unexpected workflow ID"
    assert data['version']['version'] == w['version'], "Unexpected workflow version number: it should the latest (=2)"
    assert "aggregate_test_status" in data, "Missing required aggregate_test_status"
    assert "latest_builds" in data, "Missing required latest_builds"
예제 #25
0
def test_get_instance_build_by_user_error_not_found(m, request_context, mock_user):
    assert not auth.current_user.is_anonymous, "Unexpected user in session"
    assert auth.current_registry is not None, "Unexpected registry in session"
    instance = MagicMock()
    instance.get_test_build.side_effect = \
        lm_exceptions.EntityNotFoundException(models.TestBuild)
    m.get_test_instance.return_value = instance
    response = controllers.instances_builds_get_by_id('111', '12345')
    logger.debug("Response: %r", response)
    m.get_test_instance.assert_called_once()
    assert isinstance(response, Response), "Unexpected response type"
    assert_status_code(404, response.status_code)
예제 #26
0
def test_post_workflow_by_user_error_missing_input_data(m, request_context, mock_user):
    assert not auth.current_user.is_anonymous, "Unexpected user in session"
    assert auth.current_user == mock_user, "Unexpected user in session"
    assert not auth.current_registry, "Unexpected registry in session"
    # add one fake workflow
    data = {"registry": "123456"}
    m.get_workflow_registry_by_generic_reference.return_value = MagicMock()
    response = controllers.workflows_post(body=data)
    m.get_workflow_registry_by_generic_reference.assert_called_once_with(data["registry"]), \
        "get_workflow_registry_by_uri should be used"
    logger.debug("Response: %r, %r", response, str(response.data))
    assert_status_code(response.status_code, 400)
예제 #27
0
def test_post_workflow_by_registry_error_submitter_not_found(m, request_context, mock_registry):
    assert auth.current_user.is_anonymous, "Unexpected user in session"
    assert auth.current_registry, "Unexpected registry in session"
    # add one fake workflow
    data = {"submitter_id": 1}
    m.find_registry_user_identity.side_effect = OAuthIdentityNotFoundException()
    response = controllers.workflows_post(body=data)
    logger.debug("Response: %r, %r", response, str(response.data))
    assert_status_code(response.status_code, 401)
    assert messages.no_user_oauth_identity_on_registry \
        .format(data["submitter_id"], mock_registry.name) in response.data.decode(),\
        "Unexpected error message"
예제 #28
0
def test_get_workflow_suites(app_client, client_auth_method, user1, user1_auth, valid_workflow):
    w, workflow = utils.pick_and_register_workflow(user1, valid_workflow)
    response = app_client.get(f"{utils.build_workflow_path(w, subpath='suites')}", headers=user1_auth)
    logger.debug(response)
    utils.assert_status_code(200, response.status_code)
    data = json.loads(response.data)
    logger.debug("Response data: %r", data)
    assert "items" in data, "Missing items property"
    assert len(data['items']) == 1, "Unexpected number of suites"
    # redundant check: the validation is performed by the connexion framework
    suite = data['items'][0]
    assert suite['uuid'], "Invalid UUID"
    assert "roc_suite" in suite, "Missing required roc_suite"
    assert "definition" in suite, "Missing required definition"
    assert "instances" in suite, "Missing required instances"
예제 #29
0
def test_get_suite_instances(app_client, client_auth_method, user1, user1_auth, valid_workflow):
    w, workflow = utils.pick_and_register_workflow(user1, valid_workflow)
    assert len(workflow.test_suites) > 0, "Unexpected number of test suites"
    suite = workflow.test_suites[0]
    logger.debug("The test suite: %r", suite)

    response = app_client.get(f"{utils.build_suites_path(suite.uuid)}/instances",
                              headers=user1_auth)
    logger.debug(response)
    utils.assert_status_code(200, response.status_code)
    data = json.loads(response.data)
    logger.debug("Response data: %r", data)
    # redundant check: the validation is performed by the connexion framework
    for p in ["items"]:
        assert p in data, f"Missing required property {p}"
예제 #30
0
def test_get_workflow_by_id_error_not_found(m, request_context, mock_registry):
    assert auth.current_user.is_anonymous, "Unexpected user in session"
    assert auth.current_registry, "Unexpected registry in session"
    m.get_registry_workflow_version.side_effect = lm_exceptions.EntityNotFoundException(models.WorkflowVersion)
    response = controllers.workflows_get_by_id(wf_uuid="12345", wf_version="1")
    logger.debug("Response: %r", response)
    assert_status_code(response.status_code, 404)
    assert messages.workflow_not_found\
        .format("12345", "1") in response.data.decode()
    # test when the service return None
    m.get_registry_workflow_version.return_value = None
    response = controllers.workflows_get_by_id(wf_uuid="12345", wf_version="1")
    logger.debug("Response: %r", response)
    assert_status_code(response.status_code, 404)
    assert messages.workflow_not_found\
        .format("12345", "1") in response.data.decode()