Пример #1
0
def test_workflow_registry_update(app_client, provider_type, random_string,
                                  fake_uri):
    registry = LifeMonitor.get_instance().add_workflow_registry(
        provider_type.value,
        random_string,
        random_string,
        random_string,
        api_base_url=fake_uri,
        client_auth_method="client_secret_post")

    assert isinstance(registry, WorkflowRegistry), "Unexpected object instance"
    logger.debug("Create registry: %r", registry)

    new_random_string = f"{random_string}_updated"
    new_fake_uri = f"{fake_uri}_updated"
    new_redirect_uris = f"{fake_uri},{fake_uri}/updated"
    updated_registry = LifeMonitor.get_instance()\
        .update_workflow_registry(registry.uuid,
                                  name=new_random_string,
                                  client_id=new_random_string, client_secret=new_random_string,
                                  api_base_url=new_fake_uri, redirect_uris=new_redirect_uris)

    assert updated_registry.uuid is not None, "Invalid registry identifier"
    assert updated_registry.name == new_random_string, "Unexpected registry name"
    assert updated_registry.uri == new_fake_uri, "Unexpected registry URI"
    assert updated_registry.client_credentials.redirect_uris == new_redirect_uris.split(','), \
        "Unexpected redirect_uri URI"
Пример #2
0
def test_suite_registration_invalid_specification_exception(
        app_client, user1, invalid_test_suite_metadata):
    w, workflow = utils.pick_and_register_workflow(user1)
    assert isinstance(
        workflow, models.WorkflowVersion), "Workflow not properly initialized"
    with pytest.raises(lm_exceptions.SpecificationNotValidException):
        LifeMonitor.get_instance().register_test_suite(
            w['uuid'], w['version'], user1["user"],
            invalid_test_suite_metadata)
Пример #3
0
def create_client_credentials_registry(_app_settings, _admin_user, name='seek'):
    lm = LifeMonitor.get_instance()
    try:
        return lm.get_workflow_registry_by_name(name)
    except Exception:
        return LifeMonitor.get_instance().add_workflow_registry(
            "seek", name,
            _app_settings.get('SEEK_CLIENT_ID'),
            _app_settings.get('SEEK_CLIENT_SECRET'),
            api_base_url=_app_settings.get('SEEK_API_BASE_URL'),
            redirect_uris=_fake_callback_uri())
Пример #4
0
def test_workflow_registry_registration_error_exists(app_client, provider_type,
                                                     random_string, fake_uri):
    registry = LifeMonitor.get_instance().add_workflow_registry(
        provider_type.value,
        random_string,
        random_string,
        random_string,
        api_base_url=fake_uri)

    assert isinstance(registry, WorkflowRegistry), "Unexpected object instance"
    with pytest.raises(sql_exceptions.IntegrityError):
        LifeMonitor.get_instance().add_workflow_registry(provider_type.value,
                                                         random_string,
                                                         random_string,
                                                         random_string,
                                                         api_base_url=fake_uri)
Пример #5
0
def fake_registry(app_settings, admin_user, random_string, fake_uri):
    return LifeMonitor.get_instance().add_workflow_registry(
        "seek",
        random_string,
        random_string,
        random_string,
        api_base_url=fake_uri)
Пример #6
0
def test_suite_registration(app_client, user1, test_suite_metadata,
                            valid_workflow):
    # register a new workflow
    lm = LifeMonitor.get_instance()
    wf_data, workflow = utils.pick_and_register_workflow(user1, valid_workflow)
    # try to add a new test suite instance
    logger.debug("TestDefinition: %r", test_suite_metadata)
    current_number_of_suites = len(workflow.test_suites)
    suite = lm.register_test_suite(wf_data['uuid'], wf_data['version'],
                                   user1['user'], test_suite_metadata)
    logger.debug("Number of suites: %r",
                 len(suite.workflow_version.test_suites))
    assert len(suite.workflow_version.test_suites) == current_number_of_suites + 1, \
        "Unexpected number of test_suites for the workflow {}".format(suite.workflow_version.uuid)
    logger.debug("Project: %r", suite)
    assert len(
        suite.tests
    ) == 1, "Unexpected number of tests for the testing project {}".format(
        suite)
    for t in suite.tests:
        logger.debug("- test: %r", t)
    assert len(suite.test_instances) == 1, "Unexpected number of test_instances " \
        "for the testing project {}".format(suite)
    for t in suite.test_instances:
        logger.debug("- test instance: %r --> Service: %r,%s", t,
                     t.testing_service, t.testing_service.url)
Пример #7
0
def test_workflow_registry_two_users(app_client, user1_auth, user2_auth,
                                     provider_type, random_string, fake_uri):
    registry = LifeMonitor.get_instance().get_workflow_registry_by_name('seek')
    assert isinstance(registry, WorkflowRegistry), "Unexpected object instance"
    assert isinstance(registry, WorkflowRegistry), "Unexpected object instance"
    logger.debug("Create registry: %r", registry)
    assert len(registry.get_users()) == 2, "Unexpected number of users"
Пример #8
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"
Пример #9
0
def test_registry_list(cli_runner, provider_type,
                       random_string, fake_uri):

    reg = LifeMonitor.get_instance().add_workflow_registry(
        provider_type.value, random_string, random_string, random_string,
        api_base_url=fake_uri)
    assert isinstance(reg, WorkflowRegistry), "Unexpected object instance"
    result = cli_runner.invoke(registry.list_registries, [])
    logger.debug(result.output)
    assert 'Workflow Registries' in result.output, "Missing header"
    assert str(reg.uuid) in result.output, f"Missing workflow registry '{reg.uuid}'"
Пример #10
0
def test_suite_deregistration(app_client, user1, valid_workflow):
    # register a new workflow
    lm = LifeMonitor.get_instance()
    wf_data, workflow = utils.pick_and_register_workflow(user1, valid_workflow)

    # pick the first suite
    current_number_of_suites = len(workflow.test_suites)
    assert current_number_of_suites > 0, "Unexpected number or suites"
    suite = workflow.test_suites[0]
    logger.debug("The test suite to delete: %r", suite)
    # delete test suite
    lm.deregister_test_suite(suite.uuid)
    assert len(workflow.test_suites) == current_number_of_suites - 1, \
        "Unexpected number of test_suites for the workflow {}".format(workflow.uuid)
Пример #11
0
def test_workflow_deregistration(app_client, user1, valid_workflow):
    lm = LifeMonitor.get_instance()
    # pick and register one workflow
    wf_data, workflow = utils.pick_and_register_workflow(user1, valid_workflow)
    # current number of workflows
    number_of_workflows = len(models.WorkflowVersion.all())
    lm.deregister_user_workflow(wf_data['uuid'], wf_data['version'],
                                user1["user"])
    assert len(models.WorkflowVersion.all()
               ) == number_of_workflows - 1, "Unexpected number of workflows"
    # try to find
    w = models.WorkflowVersion.get_user_workflow_version(
        user1["user"], wf_data['uuid'], wf_data['version'])
    assert w is None, "Workflow must not be in the DB"
Пример #12
0
def register_workflow(app_user, w):
    # get the registry
    registry = None
    if 'registry_uri' in w:
        registry = models.WorkflowRegistry.find_by_uri(w["registry_uri"])
    # register
    lm = LifeMonitor.get_instance()
    workflow = lm.register_workflow(w['roc_link'],
                                    app_user["user"],
                                    w['version'],
                                    workflow_uuid=w['uuid'],
                                    workflow_registry=registry,
                                    name=w['name'],
                                    authorization=w.get("authorization", None))
    return w, workflow
Пример #13
0
def test_workflow_registry_registration(app_client, provider_type,
                                        random_string, fake_uri):
    redirect_uris = f"{fake_uri},{fake_uri}"
    registry = LifeMonitor.get_instance().add_workflow_registry(
        provider_type.value,
        random_string,
        random_string,
        random_string,
        api_base_url=fake_uri,
        redirect_uris=redirect_uris)

    assert isinstance(registry, WorkflowRegistry), "Unexpected object instance"
    logger.debug("Create registry: %r", registry)
    assert registry.uuid is not None, "Invalid registry identifier"
    assert registry.name == random_string, "Unexpected registry name"
    assert registry.uri == fake_uri, "Unexpected registry URI"
    assert registry.client_credentials.redirect_uris == redirect_uris.split(','), \
        "Unexpected redirect_uri URI"
Пример #14
0
def test_registry_update(cli_runner, provider_type,
                         random_string, fake_uri):
    reg = LifeMonitor.get_instance().add_workflow_registry(
        provider_type.value, random_string, random_string, random_string,
        api_base_url=fake_uri, redirect_uris=fake_uri)
    assert isinstance(reg, WorkflowRegistry), "Unexpected object instance"
    result = cli_runner.invoke(registry.update_registry, [
        str(reg.uuid),
        "--name", f"{random_string}_",
        "--client-id", f"{random_string}_x1",
        "--client-secret", f"{random_string}_x2",
        "--api-url", fake_uri,
        "--redirect-uris", f"{fake_uri}",
        "--client-auth-method", 'client_secret_basic'
    ])
    logger.info(result.output)
    assert len(result.output) > 0, "No output"
    assert 'Error' not in result.output, "Invalid CLI options"
    assert 'ERROR' not in result.output, "Update error"
Пример #15
0
def test_get_workflows_scope(user1, user2):

    logger.debug("The first user: %r", user1['user'])
    logger.debug("Number of workflows user1: %r", len(user1['workflows']))

    logger.debug("The second user: %r", user2['user'])
    logger.debug("Number of workflows user1: %r", len(user2['workflows']))

    assert len(user1['workflows']) > len(user2['workflows'])

    registry = models.WorkflowRegistry.all()[0]
    assert registry is not None, "Registry not found"

    lm = LifeMonitor.get_instance()
    user1_workflows = lm.get_user_workflows(user1["user"])
    user2_workflows = lm.get_user_workflows(user2["user"])

    assert len(user2_workflows) == 2, "Unexpected number of workflows"
    assert len(user2_workflows) < len(
        user1_workflows), "Unexpected number of workflows"
Пример #16
0
def test_workflow_registry_registration_error_invalid_type(
        app_client, random_string, fake_uri):
    with pytest.raises(WorkflowRegistryNotSupportedException):
        LifeMonitor.get_instance().add_workflow_registry(
            "jenkins", random_string, random_string, random_string, fake_uri)
Пример #17
0
def test_workflow_registry_no_user(app_client, provider_type, random_string,
                                   fake_uri):
    registry = LifeMonitor.get_instance().get_workflow_registry_by_name('seek')
    assert isinstance(registry, WorkflowRegistry), "Unexpected object instance"
    assert len(registry.get_users()) == 0, "Unexpected number of users"
Пример #18
0
def get_workflow_data(wf_uuid):
    return LifeMonitor.get_instance().get_workflow(wf_uuid)
Пример #19
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)
Пример #20
0
def test_suite_registration_unauthorized_user_exception(
        app_client, user1, random_workflow_id, test_suite_metadata):
    with pytest.raises(lm_exceptions.EntityNotFoundException):
        LifeMonitor.get_instance().register_test_suite(
            random_workflow_id['uuid'], random_workflow_id['version'],
            user1['user'], test_suite_metadata)
Пример #21
0
def test_workflow_deregistration_exception(app_client, user1,
                                           random_workflow_id):
    with pytest.raises(lm_exceptions.EntityNotFoundException):
        LifeMonitor.get_instance().deregister_user_workflow(
            random_workflow_id['uuid'], random_workflow_id['version'],
            user1['user'])
Пример #22
0
import re
import sys

import click
from flask import Blueprint
from flask.cli import with_appcontext
from lifemonitor.api.services import LifeMonitor

# set module level logger
logger = logging.getLogger(__name__)

# define the blueprint for DB commands
blueprint = Blueprint('registry', __name__)

# instance of LifeMonitor service
lm = LifeMonitor.get_instance()

supported_registries = ["seek"]


def print_registry_info(registry):
    output = f"""\n
{'*'*100}
Workflow Registry '{registry.name}' (uuid: {registry.uuid}, type: {registry.type}) registered!
{'*'*100}\n\n
OAuth2 settings to connect to LifeMonitor:
{'-'*100}
REGISTRY NAME: {registry.name}
REGISTRY API URL: {registry.uri}
REGISTRY CLIENT ID: {registry.client_credentials.client_id}
REGISTRY CLIENT SECRET: {registry.client_credentials.client_secret}
Пример #23
0
def test_suite_deregistration_exception(app_client, user1, random_valid_uuid):
    with pytest.raises(lm_exceptions.EntityNotFoundException):
        LifeMonitor.get_instance().deregister_test_suite(random_valid_uuid)