Apply black on test map views file
This commit is contained in:
parent
725feb8d01
commit
bf4a84de99
1 changed files with 129 additions and 130 deletions
|
@ -17,49 +17,45 @@ User = get_user_model()
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def post_data():
|
def post_data():
|
||||||
return {
|
return {
|
||||||
'name': 'name',
|
"name": "name",
|
||||||
'center': '{"type":"Point","coordinates":[13.447265624999998,48.94415123418794]}', # noqa
|
"center": '{"type":"Point","coordinates":[13.447265624999998,48.94415123418794]}', # noqa
|
||||||
'settings': '{"type":"Feature","geometry":{"type":"Point","coordinates":[5.0592041015625,52.05924589011585]},"properties":{"tilelayer":{"maxZoom":20,"url_template":"http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png","minZoom":0,"attribution":"HOT and friends"},"licence":"","description":"","name":"test enrhûmé","tilelayersControl":true,"displayDataBrowserOnLoad":false,"displayPopupFooter":true,"displayCaptionOnLoad":false,"miniMap":true,"moreControl":true,"scaleControl":true,"zoomControl":true,"datalayersControl":true,"zoom":8}}' # noqa
|
"settings": '{"type":"Feature","geometry":{"type":"Point","coordinates":[5.0592041015625,52.05924589011585]},"properties":{"tilelayer":{"maxZoom":20,"url_template":"http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png","minZoom":0,"attribution":"HOT and friends"},"licence":"","description":"","name":"test enrhûmé","tilelayersControl":true,"displayDataBrowserOnLoad":false,"displayPopupFooter":true,"displayCaptionOnLoad":false,"miniMap":true,"moreControl":true,"scaleControl":true,"zoomControl":true,"datalayersControl":true,"zoom":8}}', # noqa
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_create(client, user, post_data):
|
def test_create(client, user, post_data):
|
||||||
url = reverse('map_create')
|
url = reverse("map_create")
|
||||||
# POST only mendatory fields
|
# POST only mendatory fields
|
||||||
name = 'test-map-with-new-name'
|
name = "test-map-with-new-name"
|
||||||
post_data['name'] = name
|
post_data["name"] = name
|
||||||
client.login(username=user.username, password="123123")
|
client.login(username=user.username, password="123123")
|
||||||
response = client.post(url, post_data)
|
response = client.post(url, post_data)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
j = json.loads(response.content.decode())
|
j = json.loads(response.content.decode())
|
||||||
created_map = Map.objects.latest('pk')
|
created_map = Map.objects.latest("pk")
|
||||||
assert j['id'] == created_map.pk
|
assert j["id"] == created_map.pk
|
||||||
assert created_map.name == name
|
assert created_map.name == name
|
||||||
assert created_map.center.x == 13.447265624999998
|
assert created_map.center.x == 13.447265624999998
|
||||||
assert created_map.center.y == 48.94415123418794
|
assert created_map.center.y == 48.94415123418794
|
||||||
assert j['permissions'] == {
|
assert j["permissions"] == {
|
||||||
'edit_status': 3,
|
"edit_status": 3,
|
||||||
'share_status': 1,
|
"share_status": 1,
|
||||||
'owner': {
|
"owner": {"id": user.pk, "name": "Joe", "url": "/en/user/Joe/"},
|
||||||
'id': user.pk,
|
"editors": [],
|
||||||
'name': 'Joe',
|
"anonymous_edit_url": created_map.get_anonymous_edit_url(),
|
||||||
'url': '/en/user/Joe/'
|
|
||||||
},
|
|
||||||
'editors': [],
|
|
||||||
'anonymous_edit_url': created_map.get_anonymous_edit_url()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_map_create_permissions(client, settings):
|
def test_map_create_permissions(client, settings):
|
||||||
settings.UMAP_ALLOW_ANONYMOUS = False
|
settings.UMAP_ALLOW_ANONYMOUS = False
|
||||||
url = reverse('map_create')
|
url = reverse("map_create")
|
||||||
# POST anonymous
|
# POST anonymous
|
||||||
response = client.post(url, {})
|
response = client.post(url, {})
|
||||||
assert login_required(response)
|
assert login_required(response)
|
||||||
|
|
||||||
|
|
||||||
def test_map_update_access(client, map, user):
|
def test_map_update_access(client, map, user):
|
||||||
url = reverse('map_update', kwargs={'map_id': map.pk})
|
url = reverse("map_update", kwargs={"map_id": map.pk})
|
||||||
# GET anonymous
|
# GET anonymous
|
||||||
response = client.get(url)
|
response = client.get(url)
|
||||||
assert login_required(response)
|
assert login_required(response)
|
||||||
|
@ -77,7 +73,7 @@ def test_map_update_access(client, map, user):
|
||||||
|
|
||||||
|
|
||||||
def test_map_update_permissions_access(client, map, user):
|
def test_map_update_permissions_access(client, map, user):
|
||||||
url = reverse('map_update_permissions', kwargs={'map_id': map.pk})
|
url = reverse("map_update_permissions", kwargs={"map_id": map.pk})
|
||||||
# GET anonymous
|
# GET anonymous
|
||||||
response = client.get(url)
|
response = client.get(url)
|
||||||
assert login_required(response)
|
assert login_required(response)
|
||||||
|
@ -95,22 +91,22 @@ def test_map_update_permissions_access(client, map, user):
|
||||||
|
|
||||||
|
|
||||||
def test_update(client, map, post_data):
|
def test_update(client, map, post_data):
|
||||||
url = reverse('map_update', kwargs={'map_id': map.pk})
|
url = reverse("map_update", kwargs={"map_id": map.pk})
|
||||||
# POST only mendatory fields
|
# POST only mendatory fields
|
||||||
name = 'new map name'
|
name = "new map name"
|
||||||
post_data['name'] = name
|
post_data["name"] = name
|
||||||
client.login(username=map.owner.username, password="123123")
|
client.login(username=map.owner.username, password="123123")
|
||||||
response = client.post(url, post_data)
|
response = client.post(url, post_data)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
j = json.loads(response.content.decode())
|
j = json.loads(response.content.decode())
|
||||||
assert 'html' not in j
|
assert "html" not in j
|
||||||
updated_map = Map.objects.get(pk=map.pk)
|
updated_map = Map.objects.get(pk=map.pk)
|
||||||
assert j['id'] == updated_map.pk
|
assert j["id"] == updated_map.pk
|
||||||
assert updated_map.name == name
|
assert updated_map.name == name
|
||||||
|
|
||||||
|
|
||||||
def test_delete(client, map, datalayer):
|
def test_delete(client, map, datalayer):
|
||||||
url = reverse('map_delete', args=(map.pk, ))
|
url = reverse("map_delete", args=(map.pk,))
|
||||||
client.login(username=map.owner.username, password="123123")
|
client.login(username=map.owner.username, password="123123")
|
||||||
response = client.post(url, {}, follow=True)
|
response = client.post(url, {}, follow=True)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -120,61 +116,58 @@ def test_delete(client, map, datalayer):
|
||||||
assert User.objects.filter(pk=map.owner.pk).exists()
|
assert User.objects.filter(pk=map.owner.pk).exists()
|
||||||
# Test response is a json
|
# Test response is a json
|
||||||
j = json.loads(response.content.decode())
|
j = json.loads(response.content.decode())
|
||||||
assert 'redirect' in j
|
assert "redirect" in j
|
||||||
|
|
||||||
|
|
||||||
def test_wrong_slug_should_redirect_to_canonical(client, map):
|
def test_wrong_slug_should_redirect_to_canonical(client, map):
|
||||||
url = reverse('map', kwargs={'pk': map.pk, 'slug': 'wrong-slug'})
|
url = reverse("map", kwargs={"pk": map.pk, "slug": "wrong-slug"})
|
||||||
canonical = reverse('map', kwargs={'pk': map.pk,
|
canonical = reverse("map", kwargs={"pk": map.pk, "slug": map.slug})
|
||||||
'slug': map.slug})
|
|
||||||
response = client.get(url)
|
response = client.get(url)
|
||||||
assert response.status_code == 301
|
assert response.status_code == 301
|
||||||
assert response['Location'] == canonical
|
assert response["Location"] == canonical
|
||||||
|
|
||||||
|
|
||||||
def test_wrong_slug_should_redirect_with_query_string(client, map):
|
def test_wrong_slug_should_redirect_with_query_string(client, map):
|
||||||
url = reverse('map', kwargs={'pk': map.pk, 'slug': 'wrong-slug'})
|
url = reverse("map", kwargs={"pk": map.pk, "slug": "wrong-slug"})
|
||||||
url = "{}?allowEdit=0".format(url)
|
url = "{}?allowEdit=0".format(url)
|
||||||
canonical = reverse('map', kwargs={'pk': map.pk,
|
canonical = reverse("map", kwargs={"pk": map.pk, "slug": map.slug})
|
||||||
'slug': map.slug})
|
|
||||||
canonical = "{}?allowEdit=0".format(canonical)
|
canonical = "{}?allowEdit=0".format(canonical)
|
||||||
response = client.get(url)
|
response = client.get(url)
|
||||||
assert response.status_code == 301
|
assert response.status_code == 301
|
||||||
assert response['Location'] == canonical
|
assert response["Location"] == canonical
|
||||||
|
|
||||||
|
|
||||||
def test_should_not_consider_the_query_string_for_canonical_check(client, map):
|
def test_should_not_consider_the_query_string_for_canonical_check(client, map):
|
||||||
url = reverse('map', kwargs={'pk': map.pk, 'slug': map.slug})
|
url = reverse("map", kwargs={"pk": map.pk, "slug": map.slug})
|
||||||
url = "{}?allowEdit=0".format(url)
|
url = "{}?allowEdit=0".format(url)
|
||||||
response = client.get(url)
|
response = client.get(url)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_short_url_should_redirect_to_canonical(client, map):
|
def test_short_url_should_redirect_to_canonical(client, map):
|
||||||
url = reverse('map_short_url', kwargs={'pk': map.pk})
|
url = reverse("map_short_url", kwargs={"pk": map.pk})
|
||||||
canonical = reverse('map', kwargs={'pk': map.pk,
|
canonical = reverse("map", kwargs={"pk": map.pk, "slug": map.slug})
|
||||||
'slug': map.slug})
|
|
||||||
response = client.get(url)
|
response = client.get(url)
|
||||||
assert response.status_code == 301
|
assert response.status_code == 301
|
||||||
assert response['Location'] == canonical
|
assert response["Location"] == canonical
|
||||||
|
|
||||||
|
|
||||||
def test_clone_map_should_create_a_new_instance(client, map):
|
def test_clone_map_should_create_a_new_instance(client, map):
|
||||||
assert Map.objects.count() == 1
|
assert Map.objects.count() == 1
|
||||||
url = reverse('map_clone', kwargs={'map_id': map.pk})
|
url = reverse("map_clone", kwargs={"map_id": map.pk})
|
||||||
client.login(username=map.owner.username, password="123123")
|
client.login(username=map.owner.username, password="123123")
|
||||||
response = client.post(url)
|
response = client.post(url)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert Map.objects.count() == 2
|
assert Map.objects.count() == 2
|
||||||
clone = Map.objects.latest('pk')
|
clone = Map.objects.latest("pk")
|
||||||
assert clone.pk != map.pk
|
assert clone.pk != map.pk
|
||||||
assert clone.name == u"Clone of " + map.name
|
assert clone.name == "Clone of " + map.name
|
||||||
|
|
||||||
|
|
||||||
def test_user_not_allowed_should_not_clone_map(client, map, user, settings):
|
def test_user_not_allowed_should_not_clone_map(client, map, user, settings):
|
||||||
settings.UMAP_ALLOW_ANONYMOUS = False
|
settings.UMAP_ALLOW_ANONYMOUS = False
|
||||||
assert Map.objects.count() == 1
|
assert Map.objects.count() == 1
|
||||||
url = reverse('map_clone', kwargs={'map_id': map.pk})
|
url = reverse("map_clone", kwargs={"map_id": map.pk})
|
||||||
map.edit_status = map.OWNER
|
map.edit_status = map.OWNER
|
||||||
map.save()
|
map.save()
|
||||||
response = client.post(url)
|
response = client.post(url)
|
||||||
|
@ -191,7 +184,7 @@ def test_user_not_allowed_should_not_clone_map(client, map, user, settings):
|
||||||
|
|
||||||
|
|
||||||
def test_clone_should_set_cloner_as_owner(client, map, user):
|
def test_clone_should_set_cloner_as_owner(client, map, user):
|
||||||
url = reverse('map_clone', kwargs={'map_id': map.pk})
|
url = reverse("map_clone", kwargs={"map_id": map.pk})
|
||||||
map.edit_status = map.EDITORS
|
map.edit_status = map.EDITORS
|
||||||
map.editors.add(user)
|
map.editors.add(user)
|
||||||
map.save()
|
map.save()
|
||||||
|
@ -199,32 +192,32 @@ def test_clone_should_set_cloner_as_owner(client, map, user):
|
||||||
response = client.post(url)
|
response = client.post(url)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert Map.objects.count() == 2
|
assert Map.objects.count() == 2
|
||||||
clone = Map.objects.latest('pk')
|
clone = Map.objects.latest("pk")
|
||||||
assert clone.pk != map.pk
|
assert clone.pk != map.pk
|
||||||
assert clone.name == u"Clone of " + map.name
|
assert clone.name == "Clone of " + map.name
|
||||||
assert clone.owner == user
|
assert clone.owner == user
|
||||||
|
|
||||||
|
|
||||||
def test_map_creation_should_allow_unicode_names(client, map, post_data):
|
def test_map_creation_should_allow_unicode_names(client, map, post_data):
|
||||||
url = reverse('map_create')
|
url = reverse("map_create")
|
||||||
# POST only mendatory fields
|
# POST only mendatory fields
|
||||||
name = u'Академический'
|
name = "Академический"
|
||||||
post_data['name'] = name
|
post_data["name"] = name
|
||||||
client.login(username=map.owner.username, password="123123")
|
client.login(username=map.owner.username, password="123123")
|
||||||
response = client.post(url, post_data)
|
response = client.post(url, post_data)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
j = json.loads(response.content.decode())
|
j = json.loads(response.content.decode())
|
||||||
created_map = Map.objects.latest('pk')
|
created_map = Map.objects.latest("pk")
|
||||||
assert j['id'] == created_map.pk
|
assert j["id"] == created_map.pk
|
||||||
assert created_map.name == name
|
assert created_map.name == name
|
||||||
# Lower case of the russian original name
|
# Lower case of the russian original name
|
||||||
# self.assertEqual(created_map.slug, u"академический")
|
# self.assertEqual(created_map.slug, u"академический")
|
||||||
# for now we fallback to "map", see unicode_name branch
|
# for now we fallback to "map", see unicode_name branch
|
||||||
assert created_map.slug == 'map'
|
assert created_map.slug == "map"
|
||||||
|
|
||||||
|
|
||||||
def test_anonymous_can_access_map_with_share_status_public(client, map):
|
def test_anonymous_can_access_map_with_share_status_public(client, map):
|
||||||
url = reverse('map', args=(map.slug, map.pk))
|
url = reverse("map", args=(map.slug, map.pk))
|
||||||
map.share_status = map.PUBLIC
|
map.share_status = map.PUBLIC
|
||||||
map.save()
|
map.save()
|
||||||
response = client.get(url)
|
response = client.get(url)
|
||||||
|
@ -232,7 +225,7 @@ def test_anonymous_can_access_map_with_share_status_public(client, map):
|
||||||
|
|
||||||
|
|
||||||
def test_anonymous_can_access_map_with_share_status_open(client, map):
|
def test_anonymous_can_access_map_with_share_status_open(client, map):
|
||||||
url = reverse('map', args=(map.slug, map.pk))
|
url = reverse("map", args=(map.slug, map.pk))
|
||||||
map.share_status = map.OPEN
|
map.share_status = map.OPEN
|
||||||
map.save()
|
map.save()
|
||||||
response = client.get(url)
|
response = client.get(url)
|
||||||
|
@ -240,7 +233,7 @@ def test_anonymous_can_access_map_with_share_status_open(client, map):
|
||||||
|
|
||||||
|
|
||||||
def test_anonymous_cannot_access_map_with_share_status_private(client, map):
|
def test_anonymous_cannot_access_map_with_share_status_private(client, map):
|
||||||
url = reverse('map', args=(map.slug, map.pk))
|
url = reverse("map", args=(map.slug, map.pk))
|
||||||
map.share_status = map.PRIVATE
|
map.share_status = map.PRIVATE
|
||||||
map.save()
|
map.save()
|
||||||
response = client.get(url)
|
response = client.get(url)
|
||||||
|
@ -248,7 +241,7 @@ def test_anonymous_cannot_access_map_with_share_status_private(client, map):
|
||||||
|
|
||||||
|
|
||||||
def test_owner_can_access_map_with_share_status_private(client, map):
|
def test_owner_can_access_map_with_share_status_private(client, map):
|
||||||
url = reverse('map', args=(map.slug, map.pk))
|
url = reverse("map", args=(map.slug, map.pk))
|
||||||
map.share_status = map.PRIVATE
|
map.share_status = map.PRIVATE
|
||||||
map.save()
|
map.save()
|
||||||
client.login(username=map.owner.username, password="123123")
|
client.login(username=map.owner.username, password="123123")
|
||||||
|
@ -257,7 +250,7 @@ def test_owner_can_access_map_with_share_status_private(client, map):
|
||||||
|
|
||||||
|
|
||||||
def test_editors_can_access_map_with_share_status_private(client, map, user):
|
def test_editors_can_access_map_with_share_status_private(client, map, user):
|
||||||
url = reverse('map', args=(map.slug, map.pk))
|
url = reverse("map", args=(map.slug, map.pk))
|
||||||
map.share_status = map.PRIVATE
|
map.share_status = map.PRIVATE
|
||||||
map.editors.add(user)
|
map.editors.add(user)
|
||||||
map.save()
|
map.save()
|
||||||
|
@ -267,7 +260,7 @@ def test_editors_can_access_map_with_share_status_private(client, map, user):
|
||||||
|
|
||||||
|
|
||||||
def test_anonymous_cannot_access_map_with_share_status_blocked(client, map):
|
def test_anonymous_cannot_access_map_with_share_status_blocked(client, map):
|
||||||
url = reverse('map', args=(map.slug, map.pk))
|
url = reverse("map", args=(map.slug, map.pk))
|
||||||
map.share_status = map.BLOCKED
|
map.share_status = map.BLOCKED
|
||||||
map.save()
|
map.save()
|
||||||
response = client.get(url)
|
response = client.get(url)
|
||||||
|
@ -275,7 +268,7 @@ def test_anonymous_cannot_access_map_with_share_status_blocked(client, map):
|
||||||
|
|
||||||
|
|
||||||
def test_owner_cannot_access_map_with_share_status_blocked(client, map):
|
def test_owner_cannot_access_map_with_share_status_blocked(client, map):
|
||||||
url = reverse('map', args=(map.slug, map.pk))
|
url = reverse("map", args=(map.slug, map.pk))
|
||||||
map.share_status = map.BLOCKED
|
map.share_status = map.BLOCKED
|
||||||
map.save()
|
map.save()
|
||||||
client.login(username=map.owner.username, password="123123")
|
client.login(username=map.owner.username, password="123123")
|
||||||
|
@ -283,8 +276,10 @@ def test_owner_cannot_access_map_with_share_status_blocked(client, map):
|
||||||
assert response.status_code == 403
|
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(
|
||||||
url = reverse('map', args=(map.slug, map.pk))
|
client, map, user
|
||||||
|
): # noqa
|
||||||
|
url = reverse("map", args=(map.slug, map.pk))
|
||||||
map.share_status = map.PRIVATE
|
map.share_status = map.PRIVATE
|
||||||
map.save()
|
map.save()
|
||||||
client.login(username=user.username, password="123123")
|
client.login(username=user.username, password="123123")
|
||||||
|
@ -293,16 +288,16 @@ def test_non_editor_cannot_access_map_if_share_status_private(client, map, user)
|
||||||
|
|
||||||
|
|
||||||
def test_map_geojson_view(client, map):
|
def test_map_geojson_view(client, map):
|
||||||
url = reverse('map_geojson', args=(map.pk, ))
|
url = reverse("map_geojson", args=(map.pk,))
|
||||||
response = client.get(url)
|
response = client.get(url)
|
||||||
j = json.loads(response.content.decode())
|
j = json.loads(response.content.decode())
|
||||||
assert 'json' in response['content-type']
|
assert "json" in response["content-type"]
|
||||||
assert 'type' in j
|
assert "type" in j
|
||||||
|
|
||||||
|
|
||||||
def test_only_owner_can_delete(client, map, user):
|
def test_only_owner_can_delete(client, map, user):
|
||||||
map.editors.add(user)
|
map.editors.add(user)
|
||||||
url = reverse('map_delete', kwargs={'map_id': map.pk})
|
url = reverse("map_delete", kwargs={"map_id": map.pk})
|
||||||
client.login(username=user.username, password="123123")
|
client.login(username=user.username, password="123123")
|
||||||
response = client.post(url, {}, follow=True)
|
response = client.post(url, {}, follow=True)
|
||||||
assert response.status_code == 403
|
assert response.status_code == 403
|
||||||
|
@ -312,10 +307,10 @@ def test_map_editors_do_not_see_owner_change_input(client, map, user):
|
||||||
map.editors.add(user)
|
map.editors.add(user)
|
||||||
map.edit_status = map.EDITORS
|
map.edit_status = map.EDITORS
|
||||||
map.save()
|
map.save()
|
||||||
url = reverse('map_update_permissions', kwargs={'map_id': map.pk})
|
url = reverse("map_update_permissions", kwargs={"map_id": map.pk})
|
||||||
client.login(username=user.username, password="123123")
|
client.login(username=user.username, password="123123")
|
||||||
response = client.get(url)
|
response = client.get(url)
|
||||||
assert 'id_owner' not in response
|
assert "id_owner" not in response
|
||||||
|
|
||||||
|
|
||||||
def test_logged_in_user_can_edit_map_editable_by_anonymous(client, map, user):
|
def test_logged_in_user_can_edit_map_editable_by_anonymous(client, map, user):
|
||||||
|
@ -323,114 +318,116 @@ def test_logged_in_user_can_edit_map_editable_by_anonymous(client, map, user):
|
||||||
map.edit_status = map.ANONYMOUS
|
map.edit_status = map.ANONYMOUS
|
||||||
map.save()
|
map.save()
|
||||||
client.login(username=user.username, password="123123")
|
client.login(username=user.username, password="123123")
|
||||||
url = reverse('map_update', kwargs={'map_id': map.pk})
|
url = reverse("map_update", kwargs={"map_id": map.pk})
|
||||||
new_name = 'this is my new name'
|
new_name = "this is my new name"
|
||||||
data = {
|
data = {
|
||||||
'center': '{"type":"Point","coordinates":[13.447265624999998,48.94415123418794]}', # noqa
|
"center": '{"type":"Point","coordinates":[13.447265624999998,48.94415123418794]}', # noqa
|
||||||
'name': new_name
|
"name": new_name,
|
||||||
}
|
}
|
||||||
response = client.post(url, data)
|
response = client.post(url, data)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert Map.objects.get(pk=map.pk).name == new_name
|
assert Map.objects.get(pk=map.pk).name == new_name
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('allow_anonymous')
|
@pytest.mark.usefixtures("allow_anonymous")
|
||||||
def test_anonymous_create(cookieclient, post_data):
|
def test_anonymous_create(cookieclient, post_data):
|
||||||
url = reverse('map_create')
|
url = reverse("map_create")
|
||||||
# POST only mendatory fields
|
# POST only mendatory fields
|
||||||
name = 'test-map-with-new-name'
|
name = "test-map-with-new-name"
|
||||||
post_data['name'] = name
|
post_data["name"] = name
|
||||||
response = cookieclient.post(url, post_data)
|
response = cookieclient.post(url, post_data)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
j = json.loads(response.content.decode())
|
j = json.loads(response.content.decode())
|
||||||
created_map = Map.objects.latest('pk')
|
created_map = Map.objects.latest("pk")
|
||||||
assert j['id'] == created_map.pk
|
assert j["id"] == created_map.pk
|
||||||
assert (created_map.get_anonymous_edit_url()
|
assert (
|
||||||
in j['permissions']['anonymous_edit_url'])
|
created_map.get_anonymous_edit_url() in j["permissions"]["anonymous_edit_url"]
|
||||||
|
)
|
||||||
assert created_map.name == name
|
assert created_map.name == name
|
||||||
key, value = created_map.signed_cookie_elements
|
key, value = created_map.signed_cookie_elements
|
||||||
assert key in cookieclient.cookies
|
assert key in cookieclient.cookies
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('allow_anonymous')
|
@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): # noqa
|
||||||
url = reverse('map_update', kwargs={'map_id': anonymap.pk})
|
url = reverse("map_update", kwargs={"map_id": anonymap.pk})
|
||||||
response = client.post(url, post_data)
|
response = client.post(url, post_data)
|
||||||
assert response.status_code == 403
|
assert response.status_code == 403
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('allow_anonymous')
|
@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(
|
||||||
url = reverse('map_update', kwargs={'map_id': anonymap.pk})
|
cookieclient, anonymap, post_data
|
||||||
|
): # noqa
|
||||||
|
url = reverse("map_update", kwargs={"map_id": anonymap.pk})
|
||||||
# POST only mendatory fields
|
# POST only mendatory fields
|
||||||
name = 'new map name'
|
name = "new map name"
|
||||||
post_data['name'] = name
|
post_data["name"] = name
|
||||||
response = cookieclient.post(url, post_data)
|
response = cookieclient.post(url, post_data)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
j = json.loads(response.content.decode())
|
j = json.loads(response.content.decode())
|
||||||
updated_map = Map.objects.get(pk=anonymap.pk)
|
updated_map = Map.objects.get(pk=anonymap.pk)
|
||||||
assert j['id'] == updated_map.pk
|
assert j["id"] == updated_map.pk
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('allow_anonymous')
|
@pytest.mark.usefixtures("allow_anonymous")
|
||||||
def test_anonymous_delete(cookieclient, anonymap):
|
def test_anonymous_delete(cookieclient, anonymap):
|
||||||
url = reverse('map_delete', args=(anonymap.pk, ))
|
url = reverse("map_delete", args=(anonymap.pk,))
|
||||||
response = cookieclient.post(url, {}, follow=True)
|
response = cookieclient.post(url, {}, follow=True)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert not Map.objects.filter(pk=anonymap.pk).count()
|
assert not Map.objects.filter(pk=anonymap.pk).count()
|
||||||
# Test response is a json
|
# Test response is a json
|
||||||
j = json.loads(response.content.decode())
|
j = json.loads(response.content.decode())
|
||||||
assert 'redirect' in j
|
assert "redirect" in j
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('allow_anonymous')
|
@pytest.mark.usefixtures("allow_anonymous")
|
||||||
def test_no_cookie_cant_delete(client, anonymap):
|
def test_no_cookie_cant_delete(client, anonymap):
|
||||||
url = reverse('map_delete', args=(anonymap.pk, ))
|
url = reverse("map_delete", args=(anonymap.pk,))
|
||||||
response = client.post(url, {}, follow=True)
|
response = client.post(url, {}, follow=True)
|
||||||
assert response.status_code == 403
|
assert response.status_code == 403
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('allow_anonymous')
|
@pytest.mark.usefixtures("allow_anonymous")
|
||||||
def test_anonymous_edit_url(cookieclient, anonymap):
|
def test_anonymous_edit_url(cookieclient, anonymap):
|
||||||
url = anonymap.get_anonymous_edit_url()
|
url = anonymap.get_anonymous_edit_url()
|
||||||
canonical = reverse('map', kwargs={'pk': anonymap.pk,
|
canonical = reverse("map", kwargs={"pk": anonymap.pk, "slug": anonymap.slug})
|
||||||
'slug': anonymap.slug})
|
|
||||||
response = cookieclient.get(url)
|
response = cookieclient.get(url)
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response['Location'] == canonical
|
assert response["Location"] == canonical
|
||||||
key, value = anonymap.signed_cookie_elements
|
key, value = anonymap.signed_cookie_elements
|
||||||
assert key in cookieclient.cookies
|
assert key in cookieclient.cookies
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('allow_anonymous')
|
@pytest.mark.usefixtures("allow_anonymous")
|
||||||
def test_sha1_anonymous_edit_url(cookieclient, anonymap):
|
def test_sha1_anonymous_edit_url(cookieclient, anonymap):
|
||||||
signer = Signer(algorithm='sha1')
|
signer = Signer(algorithm="sha1")
|
||||||
signature = signer.sign(anonymap.pk)
|
signature = signer.sign(anonymap.pk)
|
||||||
url = reverse('map_anonymous_edit_url', kwargs={'signature': signature})
|
url = reverse("map_anonymous_edit_url", kwargs={"signature": signature})
|
||||||
canonical = reverse('map', kwargs={'pk': anonymap.pk,
|
canonical = reverse("map", kwargs={"pk": anonymap.pk, "slug": anonymap.slug})
|
||||||
'slug': anonymap.slug})
|
|
||||||
response = cookieclient.get(url)
|
response = cookieclient.get(url)
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response['Location'] == canonical
|
assert response["Location"] == canonical
|
||||||
key, value = anonymap.signed_cookie_elements
|
key, value = anonymap.signed_cookie_elements
|
||||||
assert key in cookieclient.cookies
|
assert key in cookieclient.cookies
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('allow_anonymous')
|
@pytest.mark.usefixtures("allow_anonymous")
|
||||||
def test_bad_anonymous_edit_url_should_return_403(cookieclient, anonymap):
|
def test_bad_anonymous_edit_url_should_return_403(cookieclient, anonymap):
|
||||||
url = anonymap.get_anonymous_edit_url()
|
url = anonymap.get_anonymous_edit_url()
|
||||||
url = reverse(
|
url = reverse(
|
||||||
'map_anonymous_edit_url',
|
"map_anonymous_edit_url", kwargs={"signature": "%s:badsignature" % anonymap.pk}
|
||||||
kwargs={'signature': "%s:badsignature" % anonymap.pk}
|
|
||||||
)
|
)
|
||||||
response = cookieclient.get(url)
|
response = cookieclient.get(url)
|
||||||
assert response.status_code == 403
|
assert response.status_code == 403
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('allow_anonymous')
|
@pytest.mark.usefixtures("allow_anonymous")
|
||||||
def test_clone_anonymous_map_should_not_be_possible_if_user_is_not_allowed(client, anonymap, user): # noqa
|
def test_clone_anonymous_map_should_not_be_possible_if_user_is_not_allowed(
|
||||||
|
client, anonymap, user
|
||||||
|
): # noqa
|
||||||
assert Map.objects.count() == 1
|
assert Map.objects.count() == 1
|
||||||
url = reverse('map_clone', kwargs={'map_id': anonymap.pk})
|
url = reverse("map_clone", kwargs={"map_id": anonymap.pk})
|
||||||
anonymap.edit_status = anonymap.OWNER
|
anonymap.edit_status = anonymap.OWNER
|
||||||
anonymap.save()
|
anonymap.save()
|
||||||
response = client.post(url)
|
response = client.post(url)
|
||||||
|
@ -441,24 +438,26 @@ def test_clone_anonymous_map_should_not_be_possible_if_user_is_not_allowed(clien
|
||||||
assert Map.objects.count() == 1
|
assert Map.objects.count() == 1
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('allow_anonymous')
|
@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
|
||||||
|
): # noqa
|
||||||
assert Map.objects.count() == 1
|
assert Map.objects.count() == 1
|
||||||
url = reverse('map_clone', kwargs={'map_id': anonymap.pk})
|
url = reverse("map_clone", kwargs={"map_id": anonymap.pk})
|
||||||
anonymap.edit_status = anonymap.ANONYMOUS
|
anonymap.edit_status = anonymap.ANONYMOUS
|
||||||
anonymap.save()
|
anonymap.save()
|
||||||
response = client.post(url)
|
response = client.post(url)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert Map.objects.count() == 2
|
assert Map.objects.count() == 2
|
||||||
clone = Map.objects.latest('pk')
|
clone = Map.objects.latest("pk")
|
||||||
assert clone.pk != anonymap.pk
|
assert clone.pk != anonymap.pk
|
||||||
assert clone.name == 'Clone of ' + anonymap.name
|
assert clone.name == "Clone of " + anonymap.name
|
||||||
assert clone.owner is None
|
assert clone.owner is None
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('allow_anonymous')
|
@pytest.mark.usefixtures("allow_anonymous")
|
||||||
def test_anyone_can_access_anonymous_map(cookieclient, anonymap):
|
def test_anyone_can_access_anonymous_map(cookieclient, anonymap):
|
||||||
url = reverse('map', args=(anonymap.slug, anonymap.pk))
|
url = reverse("map", args=(anonymap.slug, anonymap.pk))
|
||||||
anonymap.share_status = anonymap.PUBLIC
|
anonymap.share_status = anonymap.PUBLIC
|
||||||
response = cookieclient.get(url)
|
response = cookieclient.get(url)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -470,9 +469,9 @@ def test_anyone_can_access_anonymous_map(cookieclient, anonymap):
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('allow_anonymous')
|
@pytest.mark.usefixtures("allow_anonymous")
|
||||||
def test_map_attach_owner(cookieclient, anonymap, user):
|
def test_map_attach_owner(cookieclient, anonymap, user):
|
||||||
url = reverse('map_attach_owner', kwargs={'map_id': anonymap.pk})
|
url = reverse("map_attach_owner", kwargs={"map_id": anonymap.pk})
|
||||||
cookieclient.login(username=user.username, password="123123")
|
cookieclient.login(username=user.username, password="123123")
|
||||||
assert anonymap.owner is None
|
assert anonymap.owner is None
|
||||||
response = cookieclient.post(url)
|
response = cookieclient.post(url)
|
||||||
|
@ -481,17 +480,17 @@ def test_map_attach_owner(cookieclient, anonymap, user):
|
||||||
assert map.owner == user
|
assert map.owner == user
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('allow_anonymous')
|
@pytest.mark.usefixtures("allow_anonymous")
|
||||||
def test_map_attach_owner_not_logged_in(cookieclient, anonymap, user):
|
def test_map_attach_owner_not_logged_in(cookieclient, anonymap, user):
|
||||||
url = reverse('map_attach_owner', kwargs={'map_id': anonymap.pk})
|
url = reverse("map_attach_owner", kwargs={"map_id": anonymap.pk})
|
||||||
assert anonymap.owner is None
|
assert anonymap.owner is None
|
||||||
response = cookieclient.post(url)
|
response = cookieclient.post(url)
|
||||||
assert response.status_code == 403
|
assert response.status_code == 403
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('allow_anonymous')
|
@pytest.mark.usefixtures("allow_anonymous")
|
||||||
def test_map_attach_owner_with_already_an_owner(cookieclient, map, user):
|
def test_map_attach_owner_with_already_an_owner(cookieclient, map, user):
|
||||||
url = reverse('map_attach_owner', kwargs={'map_id': map.pk})
|
url = reverse("map_attach_owner", kwargs={"map_id": map.pk})
|
||||||
cookieclient.login(username=user.username, password="123123")
|
cookieclient.login(username=user.username, password="123123")
|
||||||
assert map.owner
|
assert map.owner
|
||||||
assert map.owner != user
|
assert map.owner != user
|
||||||
|
@ -500,7 +499,7 @@ def test_map_attach_owner_with_already_an_owner(cookieclient, map, user):
|
||||||
|
|
||||||
|
|
||||||
def test_map_attach_owner_anonymous_not_allowed(cookieclient, anonymap, user):
|
def test_map_attach_owner_anonymous_not_allowed(cookieclient, anonymap, user):
|
||||||
url = reverse('map_attach_owner', kwargs={'map_id': anonymap.pk})
|
url = reverse("map_attach_owner", kwargs={"map_id": anonymap.pk})
|
||||||
cookieclient.login(username=user.username, password="123123")
|
cookieclient.login(username=user.username, password="123123")
|
||||||
assert anonymap.owner is None
|
assert anonymap.owner is None
|
||||||
response = cookieclient.post(url)
|
response = cookieclient.post(url)
|
||||||
|
@ -524,11 +523,11 @@ def test_map_attach_owner_anonymous_not_allowed(cookieclient, anonymap, user):
|
||||||
|
|
||||||
def test_create_readonly(client, user, post_data, settings):
|
def test_create_readonly(client, user, post_data, settings):
|
||||||
settings.UMAP_READONLY = True
|
settings.UMAP_READONLY = True
|
||||||
url = reverse('map_create')
|
url = reverse("map_create")
|
||||||
client.login(username=user.username, password="123123")
|
client.login(username=user.username, password="123123")
|
||||||
response = client.post(url, post_data)
|
response = client.post(url, post_data)
|
||||||
assert response.status_code == 403
|
assert response.status_code == 403
|
||||||
assert response.content == b'Site is readonly for maintenance'
|
assert response.content == b"Site is readonly for maintenance"
|
||||||
|
|
||||||
|
|
||||||
def test_search(client, map):
|
def test_search(client, map):
|
||||||
|
@ -542,7 +541,7 @@ def test_search(client, map):
|
||||||
|
|
||||||
|
|
||||||
def test_authenticated_user_can_star_map(client, map, user):
|
def test_authenticated_user_can_star_map(client, map, user):
|
||||||
url = reverse('map_star', args=(map.pk,))
|
url = reverse("map_star", args=(map.pk,))
|
||||||
client.login(username=user.username, password="123123")
|
client.login(username=user.username, password="123123")
|
||||||
assert Star.objects.filter(by=user).count() == 0
|
assert Star.objects.filter(by=user).count() == 0
|
||||||
response = client.post(url)
|
response = client.post(url)
|
||||||
|
@ -551,7 +550,7 @@ def test_authenticated_user_can_star_map(client, map, user):
|
||||||
|
|
||||||
|
|
||||||
def test_anonymous_cannot_star_map(client, map):
|
def test_anonymous_cannot_star_map(client, map):
|
||||||
url = reverse('map_star', args=(map.pk,))
|
url = reverse("map_star", args=(map.pk,))
|
||||||
assert Star.objects.count() == 0
|
assert Star.objects.count() == 0
|
||||||
response = client.post(url)
|
response = client.post(url)
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
|
@ -560,12 +559,12 @@ def test_anonymous_cannot_star_map(client, map):
|
||||||
|
|
||||||
|
|
||||||
def test_user_can_see_their_star(client, map, user):
|
def test_user_can_see_their_star(client, map, user):
|
||||||
url = reverse('map_star', args=(map.pk,))
|
url = reverse("map_star", args=(map.pk,))
|
||||||
client.login(username=user.username, password="123123")
|
client.login(username=user.username, password="123123")
|
||||||
assert Star.objects.filter(by=user).count() == 0
|
assert Star.objects.filter(by=user).count() == 0
|
||||||
response = client.post(url)
|
response = client.post(url)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
url = reverse('user_stars', args=(user.username,))
|
url = reverse("user_stars", args=(user.username,))
|
||||||
response = client.get(url)
|
response = client.get(url)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert map.name in response.content.decode()
|
assert map.name in response.content.decode()
|
||||||
|
|
Loading…
Reference in a new issue