return to put anonymous access to erasures documents
This commit is contained in:
parent
27ab4cf2ef
commit
d973b479cf
|
@ -20,6 +20,7 @@ from ereuse_devicehub.resources.device import models as devs
|
||||||
from ereuse_devicehub.resources.device.views import DeviceView
|
from ereuse_devicehub.resources.device.views import DeviceView
|
||||||
from ereuse_devicehub.resources.documents.device_row import DeviceRow
|
from ereuse_devicehub.resources.documents.device_row import DeviceRow
|
||||||
|
|
||||||
|
from flask import g, request
|
||||||
|
|
||||||
class Format(enum.Enum):
|
class Format(enum.Enum):
|
||||||
HTML = 'HTML'
|
HTML = 'HTML'
|
||||||
|
@ -153,7 +154,7 @@ class DocumentDef(Resource):
|
||||||
__type__ = 'Document'
|
__type__ = 'Document'
|
||||||
SCHEMA = None
|
SCHEMA = None
|
||||||
VIEW = None # We do not want to create default / documents endpoint
|
VIEW = None # We do not want to create default / documents endpoint
|
||||||
|
AUTH = False
|
||||||
def __init__(self, app,
|
def __init__(self, app,
|
||||||
import_name=__name__,
|
import_name=__name__,
|
||||||
static_folder='static',
|
static_folder='static',
|
||||||
|
@ -171,16 +172,21 @@ class DocumentDef(Resource):
|
||||||
|
|
||||||
view = DocumentView.as_view('main', definition=self, auth=app.auth)
|
view = DocumentView.as_view('main', definition=self, auth=app.auth)
|
||||||
|
|
||||||
|
# TODO @cayop This two lines never pass
|
||||||
|
if self.AUTH:
|
||||||
view = app.auth.requires_auth(view)
|
view = app.auth.requires_auth(view)
|
||||||
|
|
||||||
self.add_url_rule('/erasures/', defaults=d, view_func=view, methods=get)
|
self.add_url_rule('/erasures/', defaults=d, view_func=view, methods=get)
|
||||||
self.add_url_rule('/erasures/<{}:{}>'.format(self.ID_CONVERTER.value, self.ID_NAME),
|
self.add_url_rule('/erasures/<{}:{}>'.format(self.ID_CONVERTER.value, self.ID_NAME),
|
||||||
view_func=view, methods=get)
|
view_func=view, methods=get)
|
||||||
|
|
||||||
devices_view = DevicesDocumentView.as_view('devicesDocumentView',
|
devices_view = DevicesDocumentView.as_view('devicesDocumentView',
|
||||||
definition=self,
|
definition=self,
|
||||||
auth=app.auth)
|
auth=app.auth)
|
||||||
|
|
||||||
devices_view = app.auth.requires_auth(devices_view)
|
devices_view = app.auth.requires_auth(devices_view)
|
||||||
|
|
||||||
stock_view = StockDocumentView.as_view('stockDocumentView', definition=self)
|
|
||||||
|
|
||||||
self.add_url_rule('/devices/', defaults=d, view_func=devices_view, methods=get)
|
self.add_url_rule('/devices/', defaults=d, view_func=devices_view, methods=get)
|
||||||
|
|
||||||
|
stock_view = StockDocumentView.as_view('stockDocumentView', definition=self, auth=app.auth)
|
||||||
|
stock_view = app.auth.requires_auth(stock_view)
|
||||||
self.add_url_rule('/stock/', defaults=d, view_func=stock_view, methods=get)
|
self.add_url_rule('/stock/', defaults=d, view_func=stock_view, methods=get)
|
||||||
|
|
|
@ -13,7 +13,7 @@ from tests.conftest import file
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.mvp
|
@pytest.mark.mvp
|
||||||
def test_erasure_certificate_public_one(user: UserClient):
|
def test_erasure_certificate_public_one(user: UserClient, client: Client):
|
||||||
"""Public user can get certificate from one device as HTML or PDF."""
|
"""Public user can get certificate from one device as HTML or PDF."""
|
||||||
s = file('erase-sectors.snapshot')
|
s = file('erase-sectors.snapshot')
|
||||||
snapshot, _ = user.post(s, res=Snapshot)
|
snapshot, _ = user.post(s, res=Snapshot)
|
||||||
|
@ -25,7 +25,7 @@ def test_erasure_certificate_public_one(user: UserClient):
|
||||||
assert '<html' in doc
|
assert '<html' in doc
|
||||||
assert '2018' in doc
|
assert '2018' in doc
|
||||||
|
|
||||||
doc, response = user.get(res=documents.DocumentDef.t,
|
doc, response = client.get(res=documents.DocumentDef.t,
|
||||||
item='erasures/{}'.format(snapshot['device']['id']),
|
item='erasures/{}'.format(snapshot['device']['id']),
|
||||||
query=[('format', 'PDF')],
|
query=[('format', 'PDF')],
|
||||||
accept='application/pdf')
|
accept='application/pdf')
|
||||||
|
@ -33,7 +33,7 @@ def test_erasure_certificate_public_one(user: UserClient):
|
||||||
|
|
||||||
erasure = next(e for e in snapshot['actions'] if e['type'] == 'EraseSectors')
|
erasure = next(e for e in snapshot['actions'] if e['type'] == 'EraseSectors')
|
||||||
|
|
||||||
doc, response = user.get(res=documents.DocumentDef.t,
|
doc, response = client.get(res=documents.DocumentDef.t,
|
||||||
item='erasures/{}'.format(erasure['id']),
|
item='erasures/{}'.format(erasure['id']),
|
||||||
accept=ANY)
|
accept=ANY)
|
||||||
assert 'html' in response.content_type
|
assert 'html' in response.content_type
|
||||||
|
@ -68,8 +68,8 @@ def test_erasure_certificate_private_query(user: UserClient):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.mvp
|
@pytest.mark.mvp
|
||||||
def test_erasure_certificate_wrong_id(user: UserClient):
|
def test_erasure_certificate_wrong_id(client: Client):
|
||||||
user.get(res=documents.DocumentDef.t, item='erasures/this-is-not-an-id',
|
client.get(res=documents.DocumentDef.t, item='erasures/this-is-not-an-id',
|
||||||
status=teal.marshmallow.ValidationError)
|
status=teal.marshmallow.ValidationError)
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue