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,
'lots': self.lots_export,
'devices_lots': self.devices_lots_export,
'obada_standard': self.obada_standard_export,
'snapshot': self.snapshot,
}
@ -872,6 +873,34 @@ class ExportsView(View):
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):
"""Get device query and put information in csv format."""
data = StringIO()

View file

@ -242,6 +242,12 @@
</a>
{% endif %}
</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>
<a href="javascript:export_file('certificates')" class="dropdown-item">
<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 pytest
import json
from io import BytesIO
from pathlib import Path
from uuid import UUID
import pytest
from flask import g
from flask.testing import FlaskClient
from flask_wtf.csrf import generate_csrf
@ -279,6 +278,28 @@ def test_export_devices(user3: UserClientFlask):
), '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.usefixtures(conftest.app_context.__name__)
def test_export_metrics(user3: UserClientFlask):