diff --git a/umap/templates/umap/map_detail.html b/umap/templates/umap/map_detail.html index 25f927e7..8efc7c96 100644 --- a/umap/templates/umap/map_detail.html +++ b/umap/templates/umap/map_detail.html @@ -12,6 +12,9 @@ {% endcompress %} {% umap_js locale=locale %} {% if object.share_status != object.PUBLIC %}{% endif %} + {% endblock extra_head %} {% block content %} {% block map_init %} diff --git a/umap/tests/test_map_views.py b/umap/tests/test_map_views.py index 6ef798e2..b8595900 100644 --- a/umap/tests/test_map_views.py +++ b/umap/tests/test_map_views.py @@ -275,7 +275,7 @@ def test_owner_cannot_access_map_with_share_status_blocked(client, map): assert response.status_code == 403 -def test_non_editor_cannot_access_map_if_share_status_private(client, map, user): # noqa +def test_non_editor_cannot_access_map_if_share_status_private(client, map, user): url = reverse("map", args=(map.slug, map.pk)) map.share_status = map.PRIVATE map.save() @@ -346,14 +346,14 @@ def test_anonymous_create(cookieclient, post_data): @pytest.mark.usefixtures("allow_anonymous") -def test_anonymous_update_without_cookie_fails(client, anonymap, post_data): # noqa +def test_anonymous_update_without_cookie_fails(client, anonymap, post_data): url = reverse("map_update", kwargs={"map_id": anonymap.pk}) response = client.post(url, post_data) assert response.status_code == 403 @pytest.mark.usefixtures("allow_anonymous") -def test_anonymous_update_with_cookie_should_work(cookieclient, anonymap, post_data): # noqa +def test_anonymous_update_with_cookie_should_work(cookieclient, anonymap, post_data): url = reverse("map_update", kwargs={"map_id": anonymap.pk}) # POST only mendatory fields name = "new map name" @@ -420,7 +420,7 @@ def test_bad_anonymous_edit_url_should_return_403(cookieclient, anonymap): @pytest.mark.usefixtures("allow_anonymous") def test_clone_anonymous_map_should_not_be_possible_if_user_is_not_allowed( client, anonymap, user -): # noqa +): assert Map.objects.count() == 1 url = reverse("map_clone", kwargs={"map_id": anonymap.pk}) anonymap.edit_status = anonymap.OWNER @@ -434,7 +434,7 @@ def test_clone_anonymous_map_should_not_be_possible_if_user_is_not_allowed( @pytest.mark.usefixtures("allow_anonymous") -def test_clone_map_should_be_possible_if_edit_status_is_anonymous(client, anonymap): # noqa +def test_clone_map_should_be_possible_if_edit_status_is_anonymous(client, anonymap): assert Map.objects.count() == 1 url = reverse("map_clone", kwargs={"map_id": anonymap.pk}) anonymap.edit_status = anonymap.ANONYMOUS @@ -675,3 +675,63 @@ def test_download_my_map(client, map, datalayer): # Test response is a json j = json.loads(response.content.decode()) assert j["type"] == "umap" + + +@pytest.mark.parametrize("share_status", [Map.PRIVATE, Map.BLOCKED, Map.OPEN]) +def test_oembed_shared_status_map(client, map, datalayer, share_status): + map.share_status = share_status + map.save() + url = f"{reverse('map_oembed')}?url=http://testserver{map.get_absolute_url()}" + response = client.get(url) + assert response.status_code == 403 + + +def test_oembed_no_url_map(client, map, datalayer): + url = reverse("map_oembed") + response = client.get(url) + assert response.status_code == 404 + + +def test_oembed_wrong_format_map(client, map, datalayer): + url = ( + f"{reverse('map_oembed')}" + f"?url=http://testserver{map.get_absolute_url()}&format=xml" + ) + response = client.get(url) + assert response.status_code == 501 + + +def test_oembed_wrong_domain_map(client, map, datalayer): + url = f"{reverse('map_oembed')}?url=http://BADserver{map.get_absolute_url()}" + response = client.get(url) + assert response.status_code == 404 + + +def test_oembed_map(client, map, datalayer): + url = f"{reverse('map_oembed')}?url=http://testserver{map.get_absolute_url()}" + response = client.get(url) + assert response.status_code == 200 + j = json.loads(response.content.decode()) + assert j["type"] == "rich" + assert j["version"] == "1.0" + assert j["width"] == 800 + assert j["height"] == 300 + assert j["html"] == ( + '' + f'
' + ) + + +def test_oembed_link(client, map, datalayer): + response = client.get(map.get_absolute_url()) + assert response.status_code == 200 + assert ( + '' in response.content.decode() diff --git a/umap/tests/test_views.py b/umap/tests/test_views.py index 1c865357..5686500c 100644 --- a/umap/tests/test_views.py +++ b/umap/tests/test_views.py @@ -1,6 +1,6 @@ import json import socket -from datetime import date, datetime, timedelta +from datetime import datetime, timedelta import pytest from django.conf import settings diff --git a/umap/urls.py b/umap/urls.py index f2905025..53893748 100644 --- a/umap/urls.py +++ b/umap/urls.py @@ -41,6 +41,7 @@ urlpatterns = [ ), re_path(r"^i18n/", include("django.conf.urls.i18n")), re_path(r"^agnocomplete/", include("agnocomplete.urls")), + re_path(r"^map/oembed/", views.MapOEmbed.as_view(), name="map_oembed"), re_path( r"^map/(?P