示例#1
0
def test_get_suite_error_not_found(m, request_context, mock_user):
    assert not auth.current_user.is_anonymous, "Unexpected user in session"
    assert auth.current_registry is not None, "Unexpected registry in session"
    m.get_suite.return_value = None
    response = controllers.suites_get_by_uuid("123456")
    m.get_suite.assert_called_once()
    assert_status_code(404, response.status_code), "Unexpected status code"
示例#2
0
def test_get_suite_by_user(m, request_context, mock_user):
    # add one user to the current session
    assert not auth.current_user.is_anonymous, "Unexpected user in session"
    assert auth.current_user == mock_user, "Unexpected user in session"
    logger.debug("Current registry: %r", auth.current_registry)
    assert not auth.current_registry, "Unexpected registry in session"
    # add one fake workflow
    workflow = MagicMock()
    workflow.uuid = "1111-222"
    workflow.version = "1"
    suite = MagicMock()
    suite.uuid = '111111'
    suite.workflow = workflow
    m.get_suite.return_value = suite
    response = controllers.suites_get_by_uuid(suite.uuid)
    m.get_suite.assert_called_once()
    assert isinstance(response, dict), "Unexpected result type"
示例#3
0
def test_get_suite_by_user_without_auth_access_to_workflow(
        m, request_context, mock_user):
    # add one user to the current session
    assert not auth.current_user.is_anonymous, "Unexpected user in session"
    assert auth.current_user == mock_user, "Unexpected user in session"
    logger.debug("Current registry: %r", auth.current_registry)
    assert not auth.current_registry, "Unexpected registry in session"
    workflow = MagicMock()
    workflow.uuid = "1111-222"
    suite = MagicMock()
    suite.uuid = '1111'
    suite.workflow = workflow
    m.get_suite.return_value = suite
    m.get_user_workflow_version.side_effect = lm_exceptions.NotAuthorizedException
    response = controllers.suites_get_by_uuid(suite.uuid)
    m.get_suite.assert_called_once()
    m.get_user_workflow_version.assert_called_once()
    assert response.status_code == 403, "The user should not be able to access"
    assert messages.unauthorized_user_suite_access\
        .format(mock_user.username, suite.uuid) in response.data.decode()
示例#4
0
def test_get_suite_by_registry_without_auth_access_to_workflow(
        m, request_context, mock_registry):
    # add one user to the current session
    assert auth.current_user.is_anonymous, "Unexpected user in session"
    logger.debug("Current registry: %r", auth.current_registry)
    assert auth.current_registry, "Unexpected registry in session"
    # add one fake workflow
    mock_registry.name = "MockRegsitry"
    workflow = MagicMock()
    workflow.uuid = "1111-222"
    workflow.version = "1"
    suite = MagicMock()
    suite.uuid = '111111'
    suite.workflow = workflow
    m.get_suite.return_value = suite
    # the worklow exists but it is not linked to the registry
    m.get_registry_workflow_version.side_effect = lm_exceptions.NotAuthorizedException
    response = controllers.suites_get_by_uuid(suite.uuid)
    logger.debug("Response: %r", response.data.decode())
    m.get_suite.assert_called_once()
    m.get_registry_workflow_version.assert_called_once()
    assert response.status_code == 403, "The registry should not be able to access"
    assert messages.unauthorized_registry_suite_access.format(
        mock_registry.name, suite.uuid) in response.data.decode()
示例#5
0
def test_get_suites_no_authorization(m, request_context):
    assert auth.current_user.is_anonymous, "Unexpected user in session"
    assert auth.current_registry is not None, "Unexpected registry in session"
    with pytest.raises(auth.NotAuthorizedException):
        controllers.suites_get_by_uuid()