diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 67e1f0ee..73e3badc 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -121,13 +121,9 @@ class ErasureListView(DeviceListMixin): return flask.render_template(self.template_name, **self.context) def get_devices(self): - erasure = EraseBasic.query.filter_by(author=g.user) - # ids = [ac.device.id for ac in actions] - # devices = Device.query.filter(Device.owner_id == g.user.id).filter( - # Device.id.in_(ids) - # # Device.binding == None # noqa: E711 - # ) - # self.context['devices'] = devices + erasure = EraseBasic.query.filter_by(author=g.user).order_by( + EraseBasic.created.desc() + ) self.context['erasure'] = erasure diff --git a/ereuse_devicehub/templates/inventory/erasure_list.html b/ereuse_devicehub/templates/inventory/erasure_list.html index 40f4b89d..2e9802a3 100644 --- a/ereuse_devicehub/templates/inventory/erasure_list.html +++ b/ereuse_devicehub/templates/inventory/erasure_list.html @@ -90,7 +90,7 @@ {{ ac.severity }} - {{ ac.date_str }} + {{ ac.created.strftime('%Y-%m-%d %H:%M:%S')}} diff --git a/tests/files/erase-sectors-2-hdd.snapshot.yaml b/tests/files/erase-sectors-2-hdd.snapshot.yaml index 67cea324..8a89c61c 100644 --- a/tests/files/erase-sectors-2-hdd.snapshot.yaml +++ b/tests/files/erase-sectors-2-hdd.snapshot.yaml @@ -1,9 +1,9 @@ { "version": "11.0a3", "device": { - "serialNumber": 'foo', - "manufacturer": 'bar', - "model": 'baz', + "serialNumber": "foo", + "manufacturer": "bar", + "model": "baz", "type": "Desktop", "actions": [], "chassis": "Tower" diff --git a/tests/test_render_2_0.py b/tests/test_render_2_0.py index aaa60707..227db4cc 100644 --- a/tests/test_render_2_0.py +++ b/tests/test_render_2_0.py @@ -2295,3 +2295,32 @@ def test_upload_snapshot_smartphone(user3: UserClientFlask): assert dev.binding.device.serial_number == 'abcdef' assert dev.placeholder is None assert len(dev.actions) == 2 + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_list_erasures(user3: UserClientFlask): + uri = '/inventory/upload-snapshot/' + file_name = 'erase-sectors-2-hdd.snapshot.yaml' + body, status = user3.get(uri) + + assert status == '200 OK' + assert "Select a Snapshot file" in body + + snapshot = conftest.yaml2json(file_name.split(".yaml")[0]) + b_snapshot = bytes(json.dumps(snapshot), 'utf-8') + file_snap = (BytesIO(b_snapshot), file_name) + + data = { + 'snapshot': file_snap, + 'csrf_token': generate_csrf(), + } + + user3.post(uri, data=data, content_type="multipart/form-data") + + uri = '/inventory/device/erasure/' + body, status = user3.get(uri) + + txt = "WD-WCAV27984668" + assert status == '200 OK' + assert txt in body