Black on test_datalayer_views
This commit is contained in:
parent
849e50abc7
commit
90607c7581
1 changed files with 72 additions and 58 deletions
|
@ -14,32 +14,32 @@ pytestmark = pytest.mark.django_db
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def post_data():
|
def post_data():
|
||||||
return {
|
return {
|
||||||
"name": 'name',
|
"name": "name",
|
||||||
"display_on_load": True,
|
"display_on_load": True,
|
||||||
"rank": 0,
|
"rank": 0,
|
||||||
"geojson": '{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-3.1640625,53.014783245859235],[-3.1640625,51.86292391360244],[-0.50537109375,51.385495069223204],[1.16455078125,52.38901106223456],[-0.41748046875,53.91728101547621],[-2.109375,53.85252660044951],[-3.1640625,53.014783245859235]]]},"properties":{"_umap_options":{},"name":"Ho god, sounds like a polygouine"}},{"type":"Feature","geometry":{"type":"LineString","coordinates":[[1.8017578124999998,51.16556659836182],[-0.48339843749999994,49.710272582105695],[-3.1640625,50.0923932109388],[-5.60302734375,51.998410382390325]]},"properties":{"_umap_options":{},"name":"Light line"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[0.63720703125,51.15178610143037]},"properties":{"_umap_options":{},"name":"marker he"}}],"_umap_options":{"displayOnLoad":true,"name":"new name","id":1668,"remoteData":{},"color":"LightSeaGreen","description":"test"}}' # noqa
|
"geojson": '{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-3.1640625,53.014783245859235],[-3.1640625,51.86292391360244],[-0.50537109375,51.385495069223204],[1.16455078125,52.38901106223456],[-0.41748046875,53.91728101547621],[-2.109375,53.85252660044951],[-3.1640625,53.014783245859235]]]},"properties":{"_umap_options":{},"name":"Ho god, sounds like a polygouine"}},{"type":"Feature","geometry":{"type":"LineString","coordinates":[[1.8017578124999998,51.16556659836182],[-0.48339843749999994,49.710272582105695],[-3.1640625,50.0923932109388],[-5.60302734375,51.998410382390325]]},"properties":{"_umap_options":{},"name":"Light line"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[0.63720703125,51.15178610143037]},"properties":{"_umap_options":{},"name":"marker he"}}],"_umap_options":{"displayOnLoad":true,"name":"new name","id":1668,"remoteData":{},"color":"LightSeaGreen","description":"test"}}',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_get(client, settings, datalayer):
|
def test_get(client, settings, datalayer):
|
||||||
url = reverse('datalayer_view', args=(datalayer.pk, ))
|
url = reverse("datalayer_view", args=(datalayer.pk,))
|
||||||
response = client.get(url)
|
response = client.get(url)
|
||||||
assert response['Last-Modified'] is not None
|
assert response["Last-Modified"] is not None
|
||||||
assert response['Cache-Control'] is not None
|
assert response["Cache-Control"] is not None
|
||||||
assert 'Content-Encoding' not in response
|
assert "Content-Encoding" not in response
|
||||||
j = json.loads(response.content.decode())
|
j = json.loads(response.content.decode())
|
||||||
assert '_umap_options' in j
|
assert "_umap_options" in j
|
||||||
assert 'features' in j
|
assert "features" in j
|
||||||
assert j['type'] == 'FeatureCollection'
|
assert j["type"] == "FeatureCollection"
|
||||||
|
|
||||||
|
|
||||||
def test_update(client, datalayer, map, post_data):
|
def test_update(client, datalayer, map, post_data):
|
||||||
url = reverse('datalayer_update', args=(map.pk, datalayer.pk))
|
url = reverse("datalayer_update", args=(map.pk, datalayer.pk))
|
||||||
client.login(username=map.owner.username, password="123123")
|
client.login(username=map.owner.username, password="123123")
|
||||||
name = 'new name'
|
name = "new name"
|
||||||
rank = 2
|
rank = 2
|
||||||
post_data['name'] = name
|
post_data["name"] = name
|
||||||
post_data['rank'] = rank
|
post_data["rank"] = rank
|
||||||
response = client.post(url, post_data, follow=True)
|
response = client.post(url, post_data, follow=True)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
modified_datalayer = DataLayer.objects.get(pk=datalayer.pk)
|
modified_datalayer = DataLayer.objects.get(pk=datalayer.pk)
|
||||||
|
@ -48,15 +48,17 @@ def test_update(client, datalayer, map, post_data):
|
||||||
# Test response is a json
|
# Test response is a json
|
||||||
j = json.loads(response.content.decode())
|
j = json.loads(response.content.decode())
|
||||||
assert "id" in j
|
assert "id" in j
|
||||||
assert datalayer.pk == j['id']
|
assert datalayer.pk == j["id"]
|
||||||
|
|
||||||
|
|
||||||
def test_should_not_be_possible_to_update_with_wrong_map_id_in_url(client, datalayer, map, post_data): # noqa
|
def test_should_not_be_possible_to_update_with_wrong_map_id_in_url(
|
||||||
|
client, datalayer, map, post_data
|
||||||
|
):
|
||||||
other_map = MapFactory(owner=map.owner)
|
other_map = MapFactory(owner=map.owner)
|
||||||
url = reverse('datalayer_update', args=(other_map.pk, datalayer.pk))
|
url = reverse("datalayer_update", args=(other_map.pk, datalayer.pk))
|
||||||
client.login(username=map.owner.username, password="123123")
|
client.login(username=map.owner.username, password="123123")
|
||||||
name = 'new name'
|
name = "new name"
|
||||||
post_data['name'] = name
|
post_data["name"] = name
|
||||||
response = client.post(url, post_data, follow=True)
|
response = client.post(url, post_data, follow=True)
|
||||||
assert response.status_code == 403
|
assert response.status_code == 403
|
||||||
modified_datalayer = DataLayer.objects.get(pk=datalayer.pk)
|
modified_datalayer = DataLayer.objects.get(pk=datalayer.pk)
|
||||||
|
@ -64,8 +66,8 @@ def test_should_not_be_possible_to_update_with_wrong_map_id_in_url(client, datal
|
||||||
|
|
||||||
|
|
||||||
def test_delete(client, datalayer, map):
|
def test_delete(client, datalayer, map):
|
||||||
url = reverse('datalayer_delete', args=(map.pk, datalayer.pk))
|
url = reverse("datalayer_delete", args=(map.pk, datalayer.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
|
||||||
assert not DataLayer.objects.filter(pk=datalayer.pk).count()
|
assert not DataLayer.objects.filter(pk=datalayer.pk).count()
|
||||||
|
@ -73,50 +75,59 @@ def test_delete(client, datalayer, map):
|
||||||
assert Map.objects.filter(pk=map.pk).exists()
|
assert Map.objects.filter(pk=map.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 'info' in j
|
assert "info" in j
|
||||||
|
|
||||||
|
|
||||||
def test_should_not_be_possible_to_delete_with_wrong_map_id_in_url(client, datalayer, map): # noqa
|
def test_should_not_be_possible_to_delete_with_wrong_map_id_in_url(
|
||||||
|
client, datalayer, map
|
||||||
|
):
|
||||||
other_map = MapFactory(owner=map.owner)
|
other_map = MapFactory(owner=map.owner)
|
||||||
url = reverse('datalayer_delete', args=(other_map.pk, datalayer.pk))
|
url = reverse("datalayer_delete", args=(other_map.pk, datalayer.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 == 403
|
assert response.status_code == 403
|
||||||
assert DataLayer.objects.filter(pk=datalayer.pk).exists()
|
assert DataLayer.objects.filter(pk=datalayer.pk).exists()
|
||||||
|
|
||||||
|
|
||||||
def test_optimistic_concurrency_control_with_good_last_modified(client, datalayer, map, post_data): # noqa
|
def test_optimistic_concurrency_control_with_good_last_modified(
|
||||||
|
client, datalayer, map, post_data
|
||||||
|
):
|
||||||
# Get Last-Modified
|
# Get Last-Modified
|
||||||
url = reverse('datalayer_view', args=(datalayer.pk, ))
|
url = reverse("datalayer_view", args=(datalayer.pk,))
|
||||||
response = client.get(url)
|
response = client.get(url)
|
||||||
last_modified = response['Last-Modified']
|
last_modified = response["Last-Modified"]
|
||||||
url = reverse('datalayer_update',
|
url = reverse("datalayer_update", args=(map.pk, datalayer.pk))
|
||||||
args=(map.pk, datalayer.pk))
|
|
||||||
client.login(username=map.owner.username, password="123123")
|
client.login(username=map.owner.username, password="123123")
|
||||||
name = 'new name'
|
name = "new name"
|
||||||
post_data['name'] = 'new name'
|
post_data["name"] = "new name"
|
||||||
response = client.post(url, post_data, follow=True, HTTP_IF_UNMODIFIED_SINCE=last_modified)
|
response = client.post(
|
||||||
|
url, post_data, follow=True, HTTP_IF_UNMODIFIED_SINCE=last_modified
|
||||||
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
modified_datalayer = DataLayer.objects.get(pk=datalayer.pk)
|
modified_datalayer = DataLayer.objects.get(pk=datalayer.pk)
|
||||||
assert modified_datalayer.name == name
|
assert modified_datalayer.name == name
|
||||||
|
|
||||||
|
|
||||||
def test_optimistic_concurrency_control_with_bad_last_modified(client, datalayer, map, post_data): # noqa
|
def test_optimistic_concurrency_control_with_bad_last_modified(
|
||||||
url = reverse('datalayer_update', args=(map.pk, datalayer.pk))
|
client, datalayer, map, post_data
|
||||||
client.login(username=map.owner.username, password='123123')
|
):
|
||||||
name = 'new name'
|
url = reverse("datalayer_update", args=(map.pk, datalayer.pk))
|
||||||
post_data['name'] = name
|
client.login(username=map.owner.username, password="123123")
|
||||||
response = client.post(url, post_data, follow=True, HTTP_IF_UNMODIFIED_SINCE='xxx')
|
name = "new name"
|
||||||
|
post_data["name"] = name
|
||||||
|
response = client.post(url, post_data, follow=True, HTTP_IF_UNMODIFIED_SINCE="xxx")
|
||||||
assert response.status_code == 412
|
assert response.status_code == 412
|
||||||
modified_datalayer = DataLayer.objects.get(pk=datalayer.pk)
|
modified_datalayer = DataLayer.objects.get(pk=datalayer.pk)
|
||||||
assert modified_datalayer.name != name
|
assert modified_datalayer.name != name
|
||||||
|
|
||||||
|
|
||||||
def test_optimistic_concurrency_control_with_empty_last_modified(client, datalayer, map, post_data): # noqa
|
def test_optimistic_concurrency_control_with_empty_last_modified(
|
||||||
url = reverse('datalayer_update', args=(map.pk, datalayer.pk))
|
client, datalayer, map, post_data
|
||||||
client.login(username=map.owner.username, password='123123')
|
):
|
||||||
name = 'new name'
|
url = reverse("datalayer_update", args=(map.pk, datalayer.pk))
|
||||||
post_data['name'] = name
|
client.login(username=map.owner.username, password="123123")
|
||||||
|
name = "new name"
|
||||||
|
post_data["name"] = name
|
||||||
response = client.post(url, post_data, follow=True, HTTP_IF_UNMODIFIED_SINCE=None)
|
response = client.post(url, post_data, follow=True, HTTP_IF_UNMODIFIED_SINCE=None)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
modified_datalayer = DataLayer.objects.get(pk=datalayer.pk)
|
modified_datalayer = DataLayer.objects.get(pk=datalayer.pk)
|
||||||
|
@ -126,33 +137,36 @@ def test_optimistic_concurrency_control_with_empty_last_modified(client, datalay
|
||||||
def test_versions_should_return_versions(client, datalayer, map, settings):
|
def test_versions_should_return_versions(client, datalayer, map, settings):
|
||||||
root = datalayer.storage_root()
|
root = datalayer.storage_root()
|
||||||
datalayer.geojson.storage.save(
|
datalayer.geojson.storage.save(
|
||||||
'%s/%s_1440924889.geojson' % (root, datalayer.pk),
|
"%s/%s_1440924889.geojson" % (root, datalayer.pk), ContentFile("{}")
|
||||||
ContentFile("{}"))
|
)
|
||||||
datalayer.geojson.storage.save(
|
datalayer.geojson.storage.save(
|
||||||
'%s/%s_1440923687.geojson' % (root, datalayer.pk),
|
"%s/%s_1440923687.geojson" % (root, datalayer.pk), ContentFile("{}")
|
||||||
ContentFile("{}"))
|
)
|
||||||
datalayer.geojson.storage.save(
|
datalayer.geojson.storage.save(
|
||||||
'%s/%s_1440918637.geojson' % (root, datalayer.pk),
|
"%s/%s_1440918637.geojson" % (root, datalayer.pk), ContentFile("{}")
|
||||||
ContentFile("{}"))
|
)
|
||||||
url = reverse('datalayer_versions', args=(datalayer.pk, ))
|
url = reverse("datalayer_versions", args=(datalayer.pk,))
|
||||||
versions = json.loads(client.get(url).content.decode())
|
versions = json.loads(client.get(url).content.decode())
|
||||||
assert len(versions['versions']) == 4
|
assert len(versions["versions"]) == 4
|
||||||
version = {'name': '%s_1440918637.geojson' % datalayer.pk, 'size': 2,
|
version = {
|
||||||
'at': '1440918637'}
|
"name": "%s_1440918637.geojson" % datalayer.pk,
|
||||||
assert version in versions['versions']
|
"size": 2,
|
||||||
|
"at": "1440918637",
|
||||||
|
}
|
||||||
|
assert version in versions["versions"]
|
||||||
|
|
||||||
|
|
||||||
def test_version_should_return_one_version_geojson(client, datalayer, map):
|
def test_version_should_return_one_version_geojson(client, datalayer, map):
|
||||||
root = datalayer.storage_root()
|
root = datalayer.storage_root()
|
||||||
name = '%s_1440924889.geojson' % datalayer.pk
|
name = "%s_1440924889.geojson" % datalayer.pk
|
||||||
datalayer.geojson.storage.save('%s/%s' % (root, name), ContentFile("{}"))
|
datalayer.geojson.storage.save("%s/%s" % (root, name), ContentFile("{}"))
|
||||||
url = reverse('datalayer_version', args=(datalayer.pk, name))
|
url = reverse("datalayer_version", args=(datalayer.pk, name))
|
||||||
assert client.get(url).content.decode() == "{}"
|
assert client.get(url).content.decode() == "{}"
|
||||||
|
|
||||||
|
|
||||||
def test_update_readonly(client, datalayer, map, post_data, settings):
|
def test_update_readonly(client, datalayer, map, post_data, settings):
|
||||||
settings.UMAP_READONLY = True
|
settings.UMAP_READONLY = True
|
||||||
url = reverse('datalayer_update', args=(map.pk, datalayer.pk))
|
url = reverse("datalayer_update", args=(map.pk, datalayer.pk))
|
||||||
client.login(username=map.owner.username, password="123123")
|
client.login(username=map.owner.username, password="123123")
|
||||||
response = client.post(url, post_data, follow=True)
|
response = client.post(url, post_data, follow=True)
|
||||||
assert response.status_code == 403
|
assert response.status_code == 403
|
||||||
|
|
Loading…
Reference in a new issue