Example #1
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"
Example #2
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"
Example #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"
Example #4
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"
Example #5
0
def test_workflow_registry_generic_link(app_client,
                                        user1):  # , valid_workflow)
    w = {
        'uuid': 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']
    }

    # pick the test with a valid specification and one test instance
    _, workflow = utils.register_workflow(user1, w)
    assert workflow is not None, "workflow must be not None"
    assert isinstance(
        workflow,
        models.WorkflowVersion), "Object is not an instance of WorkflowVersion"
    assert (workflow.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 == user1["user"], "Inavalid submitter user"
    # 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"
Example #6
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"
Example #7
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)
Example #8
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)