add obada standard

This commit is contained in:
Cayo Puigdefabregas 2022-11-04 10:37:56 +01:00
parent c784fb7499
commit b2205c56f9
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):