Esempio n. 1
0
    def test_shows_links_to_visualisations(self, client):
        vis = VisualisationCatalogueItemFactory.create(
            visualisation_template__host_basename='visualisation'
        )
        link1 = VisualisationLinkFactory.create(
            visualisation_type='DATASTUDIO',
            visualisation_catalogue_item=vis,
            name='Visualisation datastudio',
            identifier='https://www.data.studio.test',
        )
        link2 = VisualisationLinkFactory.create(
            visualisation_type='QUICKSIGHT',
            visualisation_catalogue_item=vis,
            name='Visualisation quicksight',
            identifier='5d75e131-20f4-48f8-b0eb-f4ebf36434f4',
        )
        link3 = VisualisationLinkFactory.create(
            visualisation_type='METABASE',
            visualisation_catalogue_item=vis,
            name='Visualisation metabase',
            identifier='123456789',
        )

        response = client.get(vis.get_absolute_url())
        body = response.content.decode(response.charset)

        assert response.status_code == 200
        assert '//visualisation.dataworkspace.test:8000/' in body
        assert f'/visualisations/link/{link1.id}' in body
        assert f'/visualisations/link/{link2.id}' in body
        assert f'/visualisations/link/{link3.id}' in body
Esempio n. 2
0
def test_request_non_gitlab_visualisation_access(client, user, mocker):
    owner = factories.UserFactory()
    secondary_contact = factories.UserFactory()
    create_zendesk_ticket = mocker.patch(
        'dataworkspace.apps.datasets.views.create_zendesk_ticket'
    )
    create_zendesk_ticket.return_value = 999

    ds = factories.VisualisationCatalogueItemFactory.create(
        published=True,
        enquiries_contact=owner,
        secondary_enquiries_contact=secondary_contact,
        user_access_type='REQUIRES_AUTHORIZATION',
        visualisation_template=None,
    )
    VisualisationLinkFactory.create(
        visualisation_type='DATASTUDIO',
        visualisation_catalogue_item=ds,
        name='Visualisation datastudio',
        identifier='https://www.data.studio.test',
    )

    response = client.post(
        reverse('datasets:request_access', kwargs={'dataset_uuid': ds.id}),
        data={"email": "*****@*****.**", "goal": "My goal"},
        follow=True,
    )

    assert response.status_code == 200

    create_zendesk_ticket.assert_called_once_with(
        "*****@*****.**", mock.ANY, "My goal", mock.ANY, ds.name, mock.ANY, None, None
    )
Esempio n. 3
0
    def test_quicksight_link(self, mocker):
        user = UserFactory.create()
        vis = VisualisationCatalogueItemFactory.create(
            user_access_type='REQUIRES_AUTHENTICATION'
        )
        link = VisualisationLinkFactory.create(
            visualisation_type='QUICKSIGHT',
            identifier='5d75e131-20f4-48f8-b0eb-f4ebf36434f4',
            visualisation_catalogue_item=vis,
        )

        quicksight = mocker.patch(
            'dataworkspace.apps.applications.views.get_quicksight_dashboard_name_url'
        )
        quicksight.return_value = (
            'my-dashboard',
            'https://my.dashboard.quicksight.amazonaws.com',
        )

        client = Client(**get_http_sso_data(user))
        response = client.get(link.get_absolute_url())

        assert response.status_code == 200
        assert (
            'https://my.dashboard.quicksight.amazonaws.com'
            in response.content.decode(response.charset)
        )
        assert (
            'frame-src https://eu-west-2.quicksight.aws.amazon.com'
            in response['content-security-policy']
        )
Esempio n. 4
0
    def test_metabase_link(self, mocker):
        user = UserFactory.create()
        vis = VisualisationCatalogueItemFactory.create(
            user_access_type='REQUIRES_AUTHENTICATION'
        )
        link = VisualisationLinkFactory.create(
            visualisation_type='METABASE',
            identifier='123456789',
            visualisation_catalogue_item=vis,
        )

        jwt_encode = mocker.patch('dataworkspace.apps.applications.views.jwt.encode')
        jwt_encode.return_value = b'my-token'

        client = Client(**get_http_sso_data(user))
        response = client.get(link.get_absolute_url())

        assert response.status_code == 200
        assert (
            '//metabase.dataworkspace.test:8000/embed/dashboard/my-token#bordered=false&titled=false'
            in response.content.decode(response.charset)
        )
        assert (
            'frame-src metabase.dataworkspace.test'
            in response['content-security-policy']
        )
Esempio n. 5
0
    def test_user_needs_access_via_catalogue_item(self, mocker):
        user = UserFactory.create()
        vis = VisualisationCatalogueItemFactory.create(
            user_access_type='REQUIRES_AUTHORIZATION')
        link = VisualisationLinkFactory.create(
            visualisation_type='QUICKSIGHT',
            identifier=str(uuid4()),
            visualisation_catalogue_item=vis,
        )
        quicksight = mocker.patch(
            'dataworkspace.apps.applications.views.get_quicksight_dashboard_name_url'
        )
        quicksight.return_value = (
            'my-dashboard',
            'https://my.dashboard.quicksight.amazonaws.com',
        )

        client = Client(**get_http_sso_data(user))
        response = client.get(link.get_absolute_url())
        assert response.status_code == 403

        VisualisationUserPermissionFactory.create(visualisation=vis, user=user)

        response = client.get(link.get_absolute_url())
        assert response.status_code == 200
Esempio n. 6
0
    def test_datastudio_link(self):
        user = UserFactory.create()
        vis = VisualisationCatalogueItemFactory.create(
            user_access_type='REQUIRES_AUTHENTICATION')
        link = VisualisationLinkFactory.create(
            visualisation_type='DATASTUDIO',
            identifier='https://www.data.studio',
            visualisation_catalogue_item=vis,
        )

        client = Client(**get_http_sso_data(user))
        response = client.get(link.get_absolute_url())

        assert response.status_code == 302
        assert response['location'] == 'https://www.data.studio'
Esempio n. 7
0
    def test_visualisation_view(self, unauthenticated_client):
        vis_link = VisualisationLinkFactory.create(
            visualisation_type="QUICKSIGHT",
            visualisation_catalogue_item__name="my quicksight vis",
        )
        EventLogFactory.create(
            event_type=EventLog.TYPE_VIEW_QUICKSIGHT_VISUALISATION,
            related_object=vis_link,
        )

        response = unauthenticated_client.get(self.url)

        assert response.status_code == status.HTTP_200_OK
        assert response.json()["results"][0]["event_type"] == "View AWS QuickSight visualisation"
        assert response.json()["results"][0]["related_object"]["id"] == str(vis_link.id)
        assert response.json()["results"][0]["related_object"]["name"] == str(vis_link.name)
        assert response.json()["results"][0]["related_object"]["type"] == "QUICKSIGHT"
Esempio n. 8
0
    def test_user_needs_access_via_catalogue_item(self):
        user = UserFactory.create()
        vis = VisualisationCatalogueItemFactory.create(
            user_access_type='REQUIRES_AUTHORIZATION')
        link = VisualisationLinkFactory.create(
            visualisation_type='METABASE',
            identifier='123',
            visualisation_catalogue_item=vis,
        )

        client = Client(**get_http_sso_data(user))
        response = client.get(link.get_absolute_url())
        assert response.status_code == 403

        VisualisationUserPermissionFactory.create(visualisation=vis, user=user)

        response = client.get(link.get_absolute_url())
        assert response.status_code == 200
Esempio n. 9
0
    def test_visualisation_view(self, unauthenticated_client):
        vis_link = VisualisationLinkFactory.create(
            visualisation_type='QUICKSIGHT',
            visualisation_catalogue_item__name='my quicksight vis',
        )
        EventLogFactory.create(
            event_type=EventLog.TYPE_VIEW_QUICKSIGHT_VISUALISATION,
            related_object=vis_link,
        )

        response = unauthenticated_client.get(self.url)

        assert response.status_code == status.HTTP_200_OK
        assert (response.json()['results'][0]['event_type'] ==
                'View AWS QuickSight visualisation')
        assert response.json()['results'][0]['related_object']['id'] == str(
            vis_link.id)
        assert response.json()['results'][0]['related_object']['name'] == str(
            vis_link.name)
        assert response.json(
        )['results'][0]['related_object']['type'] == 'QUICKSIGHT'