Merge pull request #360 from eReuse/bugfix/3819-snapshot-in-lot

add placeholder device in lot instead of snapshot device
This commit is contained in:
cayop 2022-09-22 12:35:41 +02:00 committed by GitHub
commit 9ac3781f82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 1 deletions

View File

@ -299,7 +299,7 @@ class UploadSnapshotForm(SnapshotMixin, FlaskForm):
response = self.build(snapshot_json) response = self.build(snapshot_json)
db.session.add(response) db.session.add(response)
devices.append(response.device) devices.append(response.device.binding.device)
if hasattr(response, 'type'): if hasattr(response, 'type'):
self.result[filename] = 'Ok' self.result[filename] = 'Ok'

View File

@ -181,6 +181,48 @@ def test_upload_snapshot(user3: UserClientFlask):
assert len(dev.components) == 9 assert len(dev.components) == 9
@pytest.mark.mvp
@pytest.mark.usefixtures(conftest.app_context.__name__)
def test_upload_snapshot_to_lot(user3: UserClientFlask):
# TODO
user3.get('/inventory/lot/add/')
lot_name = 'lot1'
data = {
'name': lot_name,
'csrf_token': generate_csrf(),
}
user3.post('/inventory/lot/add/', data=data)
lot = Lot.query.filter_by(name=lot_name).one()
lot_id = lot.id
uri = f'/inventory/lot/{lot_id}/upload-snapshot/'
file_name = 'real-eee-1001pxd.snapshot.12.json'
user3.get(uri)
snapshot = conftest.yaml2json(file_name.split(".json")[0])
b_snapshot = bytes(json.dumps(snapshot), 'utf-8')
file_snap = (BytesIO(b_snapshot), file_name)
data = {
'snapshot': file_snap,
'csrf_token': generate_csrf(),
}
body, status = user3.post(uri, data=data, content_type="multipart/form-data")
txt = f"{file_name}: Ok"
assert status == '200 OK'
assert txt in body
db_snapthot = Snapshot.query.one()
dev = db_snapthot.device
assert dev not in lot.devices
assert dev.binding.device in lot.devices
uri = f'/inventory/lot/{lot_id}/device/'
body, status = user3.get(uri)
assert dev.binding.device.devicehub_id in body
assert dev.binding.phid in body
@pytest.mark.mvp @pytest.mark.mvp
@pytest.mark.usefixtures(conftest.app_context.__name__) @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_inventory_with_device(user3: UserClientFlask): def test_inventory_with_device(user3: UserClientFlask):