Beispiel #1
0
def test_post_workflow_by_user_empty_request_body(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"
    # Post a request with an empty body.  Must result in validation error and a
    # BadRequest status (400)
    response = controllers.workflows_post(body={})
    logger.debug("Response: %r, %r", response, str(response.data))
    assert response.status_code == 400
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"
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"
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)
def test_post_workflow_by_user_error_invalid_registry_uri(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.side_effect = lm_exceptions.EntityNotFoundException(models.WorkflowRegistry)
    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 response.status_code == 404, "Unexpected Workflow registry"
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"
def test_post_workflow_by_registry_invalid_rocrate(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 = {
        "uuid": "1212121212121212",
        "version": "1.0",
        "submitter_id": "1",
        "roc_link": "https://registry.org/roc_crate/download"
    }
    w = MagicMock()
    w.uuid = data['uuid']
    w.version = data['version']
    m.register_workflow.side_effect = lm_exceptions.NotValidROCrateException()
    response = controllers.workflows_post(body=data)
    logger.debug("Response: %r", response)
    assert_status_code(response.status_code, 400)
    assert messages.invalid_ro_crate in response.data.decode()
def test_post_workflow_by_registry(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 = {
        "uuid": "1212121212121212",
        "version": "1.0",
        "submitter_id": "1",
        "roc_link": "https://registry.org/roc_crate/download"
    }
    w = MagicMock()
    w.uuid = data['uuid']
    w.version = data['version']
    w.workflow = MagicMock()
    w.workflow.uuid = data['uuid']
    m.register_workflow.return_value = w
    response = controllers.workflows_post(body=data)
    logger.debug("Response: %r", response)
    assert_status_code(response[1], 201)
    assert response[0]["wf_uuid"] == data['uuid'] and \
        response[0]["wf_version"] == data['version']
def test_post_workflow_by_user(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",
        "uuid": "1212121212121212",
        "version": "1.0",
        "roc_link": "https://registry.org/roc_crate/download"
    }
    m.get_workflow_registry_by_generic_reference.return_value = MagicMock()
    w = MagicMock()
    w.uuid = data['uuid']
    w.version = data['version']
    w.workflow = MagicMock()
    w.workflow.uuid = data['uuid']
    m.register_workflow.return_value = w
    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"
    assert_status_code(response[1], 201)
    assert response[0]["wf_uuid"] == data['uuid'] and \
        response[0]["wf_version"] == data['version']
def test_post_workflows_no_authorization(m, request_context):
    assert auth.current_user.is_anonymous, "Unexpected user in session"
    assert not auth.current_registry, "Unexpected registry in session"
    with pytest.raises(auth.NotAuthorizedException):
        controllers.workflows_post(body={})