Exemplo n.º 1
0
def test_bad_upload_slide(slide, view_url, verbose, session):
    if not slide:
        slide_dict = {
            'scene': {
                'plots': [],
                'lights': [],
                'camera': {
                    'mode': 'perspective',
                    'target': 'zero',
                    'radius': 1.,
                    'zoom': 1.,
                    'rotation': [0., 0., 0., 0.],
                }
            },
            'annotation_plane': {
                'origin': 'zero',
                'axis_u': 'east',
                'axis_v': 'up',
            },
            'annotations': [],
            'uid': 'some_slide',
        }
        slide = scene.Slide(**slide_dict)
    with pytest.raises(ValueError):
        session.upload_slide(slide, view=view_url, verbose=verbose)
Exemplo n.º 2
0
def test_slide():
    r = random_float_generator()
    slide = scene.Slide(
        scene=random_scene(),
        name='a' * 200,
        description='a' * 2000,
        annotation_plane={
            'origin': [next(r), next(r), next(r)],
            'axis_u': [next(r), next(r), next(r)],
            'axis_v': [next(r), next(r), next(r)],
        },
        annotations=[
            scene.AnnotationInk(
                uid=str(next(r)),
                position=[next(r), next(r)],
                color='r',
                path=[[next(r), next(r)] for i in range(500)],
            ) for i in range(10)
        ] + [
            scene.AnnotationText(
                uid=str(next(r)),
                position=[next(r), next(r)],
                color='r',
                comment=str(next(r)),
            ) for i in range(10)
        ],
    )
    assert slide.validate()
    s = slide.serialize()
    assert [isinstance(s[key], string_types) for key in s]
Exemplo n.º 3
0
def test_upload_slide(mock_executor_class, mock_extra_validation,
                      mock_download, mock_upload, view_url, verbose, session):
    mock_executor = mock.MagicMock()
    mock_executor_class.return_value = mock_executor
    mock_extra_validation.return_value = True
    mock_view = manifests.View()
    mock_view._links = {
        'self': 'https://example.com/api/v1/view/org1/proj1/view1',
        'slides': 'https://example.com/api/v1/view/org1/proj1/view1/slides',
    }
    mock_download.return_value = mock_view
    slide_dict = {
        'scene': {
            'plots': [],
            'lights': [],
            'camera': {
                'mode': 'perspective',
                'target': [0., 0., 0.],
                'radius': 1.,
                'zoom': 1.,
                'rotation': [0., 0., 0., 0.],
                'up_direction': [0., 0., 1.],
            }
        },
        'annotation_plane': {
            'origin': [0., 0., 0.],
            'axis_u': [1., 0., 0.],
            'axis_v': [0., 1., 0.],
        },
        'annotations': [],
        'uid': 'some_slide',
    }
    slide = scene.Slide(**slide_dict)
    if not view_url:
        slide._links = {
            'self':
            'https://example.com/api/v1/view/org1/proj1/view1/slides/slide1',
            'view': 'https://example.com/api/v1/view/org1/proj1/view1',
        }
    expected_json_dict = slide_dict.copy()
    expected_json_dict.pop('uid')
    expected_post_url = (
        'https://example.com/api/v1/view/org1/proj1/view1/slides'
        if view_url else None)
    session.upload_slide(slide, view=view_url, verbose=verbose)
    mock_upload.assert_called_once_with(
        resource=slide,
        verbose=verbose,
        chunk_size=CHUNK_SIZE,
        json_dict=expected_json_dict,
        post_url=expected_post_url,
        executor=mock_executor,
    )
    mock_extra_validation.assert_called_once_with(slide, [])
Exemplo n.º 4
0
def test_extra_slide_validation():
    element_list = [
        'https://example.com/api/v1/view/org1/proj1/view1/elements/pointset/abc123',
        'https://example.com/api/v1/view/org1/proj1/view1/elements/surface/def456',
    ]
    slide = scene.Slide(scene=scene.Scene())
    slide.scene.plots[0].views = [
        scene.PointSet(element=spatial.ElementPointSet())
    ]
    with pytest.raises(properties.ValidationError):
        utils.extra_slide_validation(slide, element_list)
    slide.scene.plots[0].views = [
        scene.PointSet(
            element=
            'https://example.com/api/v1/view/org1/proj1/view1/elements/pointset/abc123',
        )
    ]
    with pytest.raises(properties.ValidationError):
        utils.extra_slide_validation(slide, element_list)
    slide.scene.plots[0].views = [
        scene.PointSet(
            element=
            'https://example.com/api/v1/view/org1/proj1/view1/elements/pointset/abc123',
        ),
        scene.Surface(
            element=
            'https://example.com/api/v1/view/org1/proj1/view1/elements/surface/def456',
        )
    ]
    utils.extra_slide_validation(slide, element_list)
    slide.scene.plots[0].views[
        0].color.mapping = 'https://example.com/api/v1/view/org1/proj1/view1/mappings/continuous/def456'
    slide.scene.plots[0].views[0].color.data = spatial.DataBasic()
    with pytest.raises(properties.ValidationError):
        utils.extra_slide_validation(slide, element_list)
    slide.scene.plots[0].views[0].color.mapping = properties.undefined
    slide.scene.plots[0].views[0].color.data = properties.undefined
    slide.scene.plots[0].views[1].textures = [{
        'data':
        spatial.TextureProjection(),
    }]
    with pytest.raises(properties.ValidationError):
        utils.extra_slide_validation(slide, element_list)
Exemplo n.º 5
0
def test_upload_feedback(mock_executor_class, mock_download, mock_upload,
                         feedback, slide_url, verbose, session):
    mock_executor = mock.MagicMock()
    mock_executor_class.return_value = mock_executor
    mock_slide = scene.Slide()
    mock_slide._links = {
        'self':
        'https://example.com/api/v1/view/org1/proj1/view1/slides/slide1',
        'view':
        'https://example.com/api/v1/view/org1/proj1/view1',
        'feedback':
        'https://example.com/api/v1/view/org1/proj1/view1/slides/slide1/feedback',
    }
    mock_download.return_value = mock_slide
    if isinstance(feedback, scene.Feedback) and not slide_url:
        feedback._links = {
            'self':
            'https://example.com/api/v1/view/org1/proj1/view1/slides/slide1/feedback/fb1',
        }
    expected_json_dict = {
        'comment': 'Some comment',
    }
    expected_post_url = (
        'https://example.com/api/v1/view/org1/proj1/view1/slides/slide1/feedback'
        if slide_url else None)
    session.upload_feedback(feedback, slide=slide_url, verbose=verbose)
    if isinstance(feedback, scene.Feedback):
        mock_upload.assert_called_once_with(
            resource=feedback,
            verbose=verbose,
            chunk_size=None,
            json_dict=expected_json_dict,
            post_url=expected_post_url,
            executor=mock_executor,
        )
    else:
        mock_upload.assert_called_once()