Esempio n. 1
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)
Esempio n. 2
0
def test_workflow_serialization_no_instances(app_client, user1):
    _, workflow = utils.pick_and_register_workflow(user1, "basefreqsum")
    assert isinstance(
        workflow, models.WorkflowVersion), "Workflow not properly initialized"
    data = workflow.to_dict(test_suite=True, test_build=True, test_output=True)
    assert isinstance(data, dict), "Invalid serialization output type"
    logger.debug(data)
Esempio n. 3
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)
Esempio n. 4
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"
Esempio n. 5
0
def test_suite_without_instances(app_client, user1):
    # pick the test with a valid specification and one test instance
    w, workflow = utils.pick_and_register_workflow(user1, "basefreqsum")
    assert workflow is not None, "workflow must be not None"
    assert len(workflow.test_suites) == 1, "Expected number of test suites 1"
    assert len(workflow.test_suites[0].test_instances) == 0, \
        "Unexpected number of test instances"
Esempio n. 6
0
def test_workflow_registration(app_client, user1, valid_workflow):
    # pick the test with a valid specification and one test instance
    w, workflow = utils.pick_and_register_workflow(user1, valid_workflow)
    logger.debug("Registered workflow: %r", workflow)
    assert workflow is not None, "workflow must be not None"
    assert isinstance(
        workflow,
        models.WorkflowVersion), "Object is not an instance of WorkflowVersion"
    assert (str(workflow.workflow.uuid), workflow.version) == (w['uuid'], w['version']),\
        "Unexpected workflow ID"
    assert len(models.Workflow.all()) == 1, "Unexpected number of workflows"
    assert len(models.WorkflowVersion.all()
               ) == 1, "Unexpected number of workflow_versions"
    assert len(models.Workflow.find_by_uuid(
        w['uuid']).versions) == 1, "Unexpected number of workflow_versions"
    # 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"
Esempio n. 7
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)
Esempio n. 8
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"
Esempio n. 9
0
def test_suite_invalid_service_url(app_client, user1):
    with pytest.raises(lm_exceptions.TestingServiceException):
        w, workflow = utils.pick_and_register_workflow(
            user1, "sort-and-change-case-invalid-service-url")
        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]
        conf.testing_service.check_connection(
        )  # this should raise the exception
Esempio n. 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)
Esempio n. 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"
Esempio n. 12
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}"
Esempio n. 13
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"
Esempio n. 14
0
def test_get_instance(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)

    response = app_client.get(f"{utils.build_instances_path(instance.uuid)}",
                              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
    utils.assert_properties_exist(["name", "service"], data)
    assert data['uuid'] == str(instance.uuid), "Invalid UUID"
Esempio n. 15
0
def test_add_managed_instance(app_client, client_auth_method, user1,
                              user1_auth, random_valid_workflow,
                              managed_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)
    # get/check number of instances before
    num_of_instances = len(suite.test_instances)
    assert num_of_instances > 0, "Unexpected number of test instances"
    # post new unmanaged instance
    response = app_client.post(
        f"{utils.build_suites_path(suite.uuid)}/instances",
        headers=user1_auth,
        json=managed_test_instance)
    logger.debug(response)
    utils.assert_status_code(501, response.status_code)
    # check number of instances after
    assert len(suite.test_instances
               ) == num_of_instances, "Unexpected number of instances"
Esempio n. 16
0
def test_get_instance_build_logs(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)
    assert len(
        instance.get_test_builds()) > 0, "Unexpected number of test builds"
    build = instance.get_test_builds()[0]

    response = app_client.get(
        f"{utils.build_instances_path(instance.uuid)}/builds/{build.id}/logs",
        headers=user1_auth)
    logger.debug(response.data)
    utils.assert_status_code(response.status_code, 200)
    data = json.loads(response.data)
    logger.debug("Response data: %r", data)
    # redundant check: the validation is performed by the connexion framework
    assert isinstance(data, str), "Unexpected result type"
Esempio n. 17
0
def test_suite_invalid_service_type(app_client, user1):
    with pytest.raises(lm_exceptions.TestingServiceNotSupportedException):
        utils.pick_and_register_workflow(
            user1, "sort-and-change-case-invalid-service-type")