Ejemplo n.º 1
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)
Ejemplo n.º 2
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"
Ejemplo n.º 3
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"
Ejemplo n.º 4
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"
Ejemplo n.º 5
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"
Ejemplo n.º 6
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"
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
def test_workflow_registration_not_allowed_user(app_client, user1, user2):

    # not shared workflows
    logger.info("SET 1: %r", user1["workflows"])
    logger.info("SET 2: %r", user2["workflows"])
    # pick one workflow of user1 which is not visible to user2
    workflow = utils.pick_workflow(user1,
                                   'sort-and-change-case-invalid-service-url')
    assert workflow, "Workflow not found"
    assert workflow['name'] not in [_['name'] for _ in user2['workflows']], \
        f"The workflow '{workflow['name']}' should not be visible to user2"
    # user2 should not be allowed to register the workflow
    with pytest.raises(lm_exceptions.NotAuthorizedException):
        w, workflow = utils.register_workflow(user2, workflow)
Ejemplo n.º 9
0
def test_preserve_registry_workflow_identity(app_client, user1, user2,
                                             valid_workflow):
    workflow = utils.pick_workflow(user1, "sort-and-change-case")
    wv1 = workflow.copy()
    wv2 = workflow.copy()

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

    workflows = models.Workflow.all()
    assert len(workflows) == 1, "Invalid number of workflows"
    w = workflows[0]
    assert len(w.versions) == 2, "Invalid number of workflow versions"
Ejemplo n.º 10
0
def test_workflow_latest_version(app_client, user1, random_valid_uuid):
    workflow = utils.pick_workflow(user1, "sort-and-change-case")
    wv1 = workflow.copy()
    wv2 = workflow.copy()

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

    u = user1['user']
    logger.debug("The User: %r", u)
    workflows = LifeMonitor.get_instance().get_user_workflows(u)
    w = LifeMonitor.get_instance().get_user_workflow_version(
        u, workflow['uuid'])
    logger.debug(w)
    logger.debug(workflows)
    logger.debug("Previous versions: %r", w.previous_versions)
    assert w.version == "2", "Unexpected version number"
    assert "1" in w.previous_versions, "Version '1' not found as previous version"
Ejemplo n.º 11
0
def test_workflow_registration_without_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)
    del workflow['roc_link']
    workflow['registry'] = workflow['registry_uri']
    logger.debug("The BODY: %r", workflow)
    response = app_client.post(utils.build_workflow_path(),
                               json=workflow,
                               headers=user1_auth)
    # if the client is not a registry client
    # the roc_link MUST be provided to register the workflow
    logger.debug("The actual response: %r", response.data)
    utils.assert_status_code(500, response.status_code)
    data = json.loads(response.data)
    logger.debug("Response data: %r", data)
Ejemplo n.º 12
0
def test_workflow_registration_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)
    # 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
    del workflow['name']
    assert not hasattr(workflow,
                       'name'), "Name should not be defined by the user"

    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"
    # check name
    response = app_client.get(utils.build_workflow_path(workflow),
                              headers=user1_auth)
    utils.assert_status_code(200, response.status_code)
    data = json.loads(response.data)
    assert data['name'] == valid_workflow, "Invalid workflow name"
Ejemplo n.º 13
0
def test_workflow_registration_by_registry_uuid(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)
    # Set the registry reference
    workflow['registry'] = client_credentials_registry.uuid
    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"
Ejemplo n.º 14
0
def test_registry_user_workflow_registration_by_identifier(
        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"/users/{user1['user_info']['id']}/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"
Ejemplo n.º 15
0
def test_workflow_registration_by_roc_link(app_client, client_auth_method,
                                           user1, user1_auth,
                                           client_credentials_registry):
    logger.debug("User: %r", user1)
    logger.debug("headers: %r", user1_auth)
    workflow = utils.pick_workflow(user1, 'sort-and-change-case')
    logger.debug("Selected workflow: %r", workflow)
    logger.debug("Using oauth2 user: %r", user1)
    # prepare body
    body = {
        'roc_link': workflow['roc_link'],
        'version': workflow['version'],
        'uuid': workflow['uuid']
    }
    logger.debug("The BODY: %r", body)
    response = app_client.post('/registries/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_uuid'] == workflow['uuid'] and data['wf_version'] == workflow['version'], \
        "Response should be equal to the workflow UUID"
Ejemplo n.º 16
0
def test_workflow_registration_same_workflow_by_different_users(
        app_client, user1, user2):  # , valid_workflow):

    lm = LifeMonitor.get_instance()

    # pick the test with a valid specification and one test instance
    count = 1
    for user in [user1, user2]:
        count = count + 1
        w = utils.pick_workflow(user, "sort-and-change-case")
        w['name'] = f"{user['user'].username}_Workflow"
        w['version'] = str(count)
        logger.debug("Registering workflow: %r", w['uuid'])
        _, workflow = utils.register_workflow(user, w)
        assert workflow is not None, "workflow must be not None"
        assert isinstance(workflow, models.WorkflowVersion
                          ), "Object is not an instance of WorkflowVersion"
        # FIXME: using an ID for version
        # assert (str(workflow.uuid), workflow.version) == (w['uuid'], w['version']), "Unexpected workflow ID"
        # assert workflow.external_id is not None, "External ID must be computed if not provided"
        # assert workflow.external_id == w["external_id"], "Invalid external ID"
        assert workflow.submitter == user["user"], "Inavalid submitter user"
        assert str(
            workflow.workflow.uuid) == w['uuid'], "Invalid workflow UUID"
        # inspect the suite/test type
        assert len(
            workflow.test_suites) == 1, "Expected number of test suites 1"
        suite = workflow.test_suites[0]
        assert len(
            suite.test_instances) == 1, "Expected number of test instances 1"
        conf = suite.test_instances[0]
        service = conf.testing_service
        testing_service_type = getattr(
            models,
            "{}TestingService".format(w['testing_service_type'].capitalize()))
        assert isinstance(service,
                          testing_service_type), "Unexpected type for service"

        r = lm.get_workflow_registries()[0]
        logger.debug("Registry: %r", r)
        registry_workflows = lm.get_registry_workflows(r)
        assert len(registry_workflows) == 1, "Unexpected number of workflows"
        assert len(r.registered_workflow_versions) == (
            count - 1), "Unexpected number of workflows versions"
        logger.debug(r.registered_workflow_versions)

    workflows_user1 = lm.get_user_workflows(user1['user'])
    workflows_user2 = lm.get_user_workflows(user2['user'])
    assert len(workflows_user1) > 0, "User1 should have one workflow"
    assert len(workflows_user1) == len(
        workflows_user2), "User1 and User2 should have the same workflows"
    assert workflows_user1[0].uuid == workflows_user2[
        0].uuid, "Unexpected workflow UUID"
    logger.debug("WV1: %r",
                 workflows_user1[0].get_user_versions(user1['user']))
    logger.debug("WV1 (all): %r", workflows_user1[0].versions)
    logger.debug("WV2: %r",
                 workflows_user2[0].get_user_versions(user2['user']))
    logger.debug("WV2 (all): %r", workflows_user2[0].versions)

    r = lm.get_workflow_registries()[0]
    logger.debug("Registry: %r", r)
    registry_workflows = lm.get_registry_workflows(r)
    assert len(registry_workflows) == 1, "Unexpected number of workflows"
    assert len(registry_workflows[0].versions.items()
               ) == 2, "Unexpected number of workflow versions"
    logger.debug("Registry workflows: %r", registry_workflows)
    logger.debug(
        "Registry workflow versions: %r",
        lm.get_registry_workflow_versions(r, registry_workflows[0].uuid))
    for v in lm.get_registry_workflow_versions(r, registry_workflows[0].uuid):
        logger.debug("%r (v%s) - submitter: %r", v.uuid, v.version,
                     v.submitter.username)
Ejemplo n.º 17
0
def test_get_workflow_not_authorized(app_client, client_auth_method, user1,
                                     user1_auth):
    workflow = utils.pick_workflow(user1)
    response = app_client.get(utils.build_workflow_path(workflow))
    logger.debug(response.data)
    utils.assert_status_code(401, response.status_code)