예제 #1
0
def test_get_instance_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_test_instance.return_value = None
    response = controllers.instances_get_by_id("123456")
    m.get_test_instance.assert_called_once()
    assert_status_code(404, response.status_code)
예제 #2
0
def test_get_instance_by_registry_error_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"
    workflow = {"uuid": "1111-222"}
    instance = MagicMock()
    instance.uuid = '12345'
    instance.test_suite.workflow = workflow
    m.get_test_instance.return_value = instance
    mock_registry.registered_workflow_versions = [workflow]
    response = controllers.instances_get_by_id(instance['uuid'])
    m.get_test_instance.assert_called_once()
    assert isinstance(response, dict), "Unexpected response type"
예제 #3
0
def test_get_instance_by_registry_error_forbidden(m, request_context, mock_registry):
    assert auth.current_user.is_anonymous, "Unexpected user in session"
    assert auth.current_registry, "Unexpected registry in session"
    workflow = MagicMock()
    workflow.uuid = "1111-222"
    instance = MagicMock()
    instance.uuid = '12345'
    instance.suite = MagicMock()
    instance.suite.uuid = '1111'
    instance.test_suite.workflow = workflow
    m.get_test_instance.return_value = instance
    m.get_user_workflows.return_value = []
    m.get_suite.return_value = instance.suite
    m.get_registry_workflow_version = Mock(side_effect=lm_exceptions.NotAuthorizedException)
    response = controllers.instances_get_by_id(instance['uuid'])
    m.get_test_instance.assert_called_once()
    assert isinstance(response, Response), "Unexpected response type"
    assert_status_code(403, response.status_code)
예제 #4
0
def test_get_instance_by_user(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"
    workflow = MagicMock()
    workflow.uuid = "1111-222"
    instance = MagicMock()
    instance.uuid = '12345'
    instance.suite = MagicMock()
    instance.suite.uuid = '1111'
    instance.test_suite.workflow = workflow
    m.get_test_instance.return_value = instance
    m.get_user_workflows.return_value = []
    m.get_suite.return_value = instance.suite
    m.get_user_workflow_version = workflow
    response = controllers.instances_get_by_id(instance['uuid'])
    m.get_test_instance.assert_called_once()
    m.get_suite.assert_called_once()
    m.get_user_workflow_version.assert_called_once()
    assert not isinstance(response, Response), "Unexpected response type"
    assert isinstance(response, dict), "Unexpected response type"
예제 #5
0
def test_get_instance_by_user_error_forbidden(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"
    # Mock instance
    workflow = MagicMock()
    workflow.uuid = "1111-222"
    instance = MagicMock()
    instance.uuid = '12345'
    instance.suite = MagicMock()
    instance.suite.uuid = '1111'
    instance.test_suite.workflow = workflow
    m.get_test_instance.return_value = instance
    m.get_user_workflows.return_value = []
    m.get_suite.return_value = instance.suite
    m.get_user_workflow_version = Mock(side_effect=lm_exceptions.NotAuthorizedException)
    # m.get_registry_workflow_version = workflow
    response = controllers.instances_get_by_id(instance['uuid'])
    logger.debug("Response: %r", response.data)
    m.get_test_instance.assert_called_once()
    m.get_suite.assert_called_once()
    m.get_user_workflow_version.assert_called_once()
    assert_status_code(403, response.status_code)
예제 #6
0
def test_get_instances_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.instances_get_by_id("1234")