Merge pull request #397 from eReuse/feature/4023-obada

add obada standard
This commit is contained in:
cayop 2022-11-04 15:27:34 +01:00 committed by GitHub
commit 375a2de5c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 2 deletions

View File

@ -829,6 +829,7 @@ class ExportsView(View):
'certificates': self.erasure, 'certificates': self.erasure,
'lots': self.lots_export, 'lots': self.lots_export,
'devices_lots': self.devices_lots_export, 'devices_lots': self.devices_lots_export,
'obada_standard': self.obada_standard_export,
'snapshot': self.snapshot, 'snapshot': self.snapshot,
} }
@ -872,6 +873,34 @@ class ExportsView(View):
return self.response_csv(data, "export.csv") return self.response_csv(data, "export.csv")
def obada_standard_export(self):
"""Get device information for Obada Standard."""
data = StringIO()
cw = csv.writer(
data,
delimiter=';',
lineterminator="\n",
quotechar='"',
quoting=csv.QUOTE_ALL,
)
cw.writerow(['Manufacturer', 'Model', 'Serial Number'])
for device in self.find_devices():
if device.placeholder:
if not device.placeholder.binding:
continue
device = device.placeholder.binding
d = [
device.manufacturer,
device.model,
device.serial_number,
]
cw.writerow(d)
return self.response_csv(data, "obada_standard.csv")
def metrics(self): def metrics(self):
"""Get device query and put information in csv format.""" """Get device query and put information in csv format."""
data = StringIO() data = StringIO()

View File

@ -242,6 +242,12 @@
</a> </a>
{% endif %} {% endif %}
</li> </li>
<li>
<a href="javascript:export_file('obada_standard')" class="dropdown-item">
<i class="bi bi-file-spreadsheet"></i>
Obada Standard Spreadsheet
</a>
</li>
<li> <li>
<a href="javascript:export_file('certificates')" class="dropdown-item"> <a href="javascript:export_file('certificates')" class="dropdown-item">
<i class="bi bi-eraser-fill"></i> <i class="bi bi-eraser-fill"></i>

View File

@ -0,0 +1,2 @@
"Manufacturer";"Model";"Serial Number"
"asustek computer inc.";"1001pxd";"b8oaas048285"
1 Manufacturer Model Serial Number
2 asustek computer inc. 1001pxd b8oaas048285

View File

@ -1,11 +1,10 @@
import datetime import datetime
import pytest
import json import json
from io import BytesIO from io import BytesIO
from pathlib import Path from pathlib import Path
from uuid import UUID from uuid import UUID
import pytest
from flask import g from flask import g
from flask.testing import FlaskClient from flask.testing import FlaskClient
from flask_wtf.csrf import generate_csrf from flask_wtf.csrf import generate_csrf
@ -279,6 +278,28 @@ def test_export_devices(user3: UserClientFlask):
), 'Computer information are not equal' ), 'Computer information are not equal'
@pytest.mark.mvp
@pytest.mark.usefixtures(conftest.app_context.__name__)
def test_export_obada_standard(user3: UserClientFlask):
snap = create_device(user3, 'real-eee-1001pxd.snapshot.12.json')
uri = "/inventory/export/obada_standard/?ids={id}".format(
id=snap.device.devicehub_id
)
body, status = user3.get(uri)
assert status == '200 OK'
export_csv = [line.split(";") for line in body.split("\n")]
with Path(__file__).parent.joinpath('files').joinpath(
'export_obada_standard.csv'
).open() as csv_file:
fixture_csv = [line.split(";") for line in csv_file.read().split("\n")]
assert fixture_csv[0] == export_csv[0], 'Headers are not equal'
assert fixture_csv[1] == export_csv[1], 'body are not equal'
@pytest.mark.mvp @pytest.mark.mvp
@pytest.mark.usefixtures(conftest.app_context.__name__) @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_export_metrics(user3: UserClientFlask): def test_export_metrics(user3: UserClientFlask):