Обновил структуру проекта
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
|
||||
from test_web import env, login
|
||||
from test_admin_http import headers
|
||||
from parser_lab.views import default_view
|
||||
|
||||
|
||||
def test_detail_configuration_preview_and_publication(env):
|
||||
app, c = env
|
||||
login(c)
|
||||
h = headers(app, c)
|
||||
repo = app.state.repo
|
||||
d = repo.create('Study', b'[]', 'study.json', [{'name': 'Alice', 'bio': 'BIOGRAPHY', 'secret': 'HIDDEN'}])
|
||||
view = default_view('table', ['/name'])
|
||||
view['detail_columns'] = [{'pointer': '/bio', 'label': 'Biography'}]
|
||||
payload = {'revision': d['revision'], 'views': {'table': view}}
|
||||
endpoint = f"/api/admin/datasets/{d['id']}"
|
||||
preview = c.post(endpoint + '/preview?kind=table&detail=1', json=payload, headers=h).json()
|
||||
assert 'BIOGRAPHY' in preview['html'] and 'HIDDEN' not in preview['html']
|
||||
saved = c.put(endpoint, json=payload, headers=h).json()
|
||||
assert c.post(endpoint + '/publish', json=saved, headers=h).status_code == 200
|
||||
for base in (f"/preview/{d['id']}/table", f"/dynamic-preview/{d['id']}/table",
|
||||
f"/html/{d['slug']}/v/1/table", f"/interactive/{d['slug']}/v/1/table"):
|
||||
assert 'BIOGRAPHY' not in c.get(base).text
|
||||
detail = c.get(base + '/records/1')
|
||||
assert detail.status_code == 200
|
||||
assert 'BIOGRAPHY' in detail.text and 'HIDDEN' not in detail.text
|
||||
# Editing the draft cannot change a published snapshot.
|
||||
payload.update(revision=saved['revision'])
|
||||
payload['views']['table']['detail_columns'] = [{'pointer': '/name', 'label': 'Name'}]
|
||||
assert c.put(endpoint, json=payload, headers=h).status_code == 200
|
||||
assert 'BIOGRAPHY' in c.get(f"/html/{d['slug']}/v/1/table/records/1").text
|
||||
|
||||
|
||||
def test_delete_requires_auth_csrf_and_current_revision(env):
|
||||
app, c = env
|
||||
repo = app.state.repo
|
||||
d = repo.create('Delete', b'[]', 'study.json', [{'name': 'Alice'}])
|
||||
d['views'] = {'table': default_view('table', ['/name'])}
|
||||
d = repo.save(d, d['revision'])
|
||||
repo.publish(d['id'], d['revision'])
|
||||
endpoint = f"/api/admin/datasets/{d['id']}"
|
||||
assert c.request('DELETE', endpoint, headers={'origin': 'http://testserver'}, json={'revision': d['revision']}).status_code == 401
|
||||
login(c)
|
||||
h = headers(app, c)
|
||||
assert c.request('DELETE', endpoint, headers={'origin': 'http://testserver'}, json={'revision': d['revision']}).status_code == 403
|
||||
for payload in ([], {'revision': True}, {'revision': '2'}):
|
||||
assert c.request('DELETE', endpoint, headers=h, json=payload).status_code == 400
|
||||
assert c.request('DELETE', endpoint, headers=h, json={'revision': 1}).status_code == 409
|
||||
assert c.request('DELETE', endpoint, headers=h, json={'revision': d['revision']}).status_code == 200
|
||||
assert c.get(f"/html/{d['slug']}/v/1/table").status_code == 404
|
||||
assert c.get(f"/admin/datasets/{d['id']}").status_code == 404
|
||||
assert not list((repo.root / 'sources').iterdir())
|
||||
Reference in New Issue
Block a user