From d1cff3e44e5b6992220bbdee7d31dca4c5d4bf23 Mon Sep 17 00:00:00 2001 From: "jordi.nadeu" Date: Mon, 9 Dec 2019 17:24:24 +0100 Subject: [PATCH] first iteration integration with blockchain --- ereuse_devicehub/resources/action/models.py | 26 +++ ereuse_devicehub/resources/action/models.pyi | 4 + ereuse_devicehub/resources/action/schemas.py | 9 ++ ereuse_devicehub/resources/device/models.py | 3 +- .../documents/templates/documents/layout.html | 2 +- ereuse_devicehub/resources/lot/dag.sql | 3 - ereuse_devicehub/resources/lot/models.py | 12 ++ ereuse_devicehub/resources/lot/models.pyi | 12 ++ tests/files/acer.happy.battery.snapshot.yaml | 151 ++++++++++++++++++ tests/test_rate.py | 1 + tests/test_snapshot.py | 11 +- 11 files changed, 227 insertions(+), 7 deletions(-) create mode 100644 tests/files/acer.happy.battery.snapshot.yaml diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index c81f29b9..2302983f 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -1448,6 +1448,32 @@ class Receive(JoinedTableMixin, ActionWithMultipleDevices): default=ReceiverRole.Intermediary) +class ShareDeliveryNote(JoinedTableMixin, ActionWithMultipleDevices): + """To share a DeliveryNote to between owners.""" + # New variables for DeliveryNote + supplier = db.Column() # String, nullable, ... + supplier.comment = """Name of the organization/agent that create DeliveryNote.""" + date_delivery_note = db.Column() + date_delivery_note.comment = """Date of note creation.""" + # Is the same of lot id?? + id_delivery_note = db.Column(UUID(as_uuid=True)) + id_delivery_note.comment = """Unique id of lot and delivery note.""" + deposit = db.Column() + deposit.comment = """Total amount of deposit devices in Lot.""" + address_note = db.Column(UUID(as_uuid=True)) + address_note.comment = """Address identifier in the blockchain.""" + + agent_id = Column(UUID(as_uuid=True), + ForeignKey(Agent.id), + nullable=False, + default=lambda: g.user.individual.id) + + +class ConfirmDeliveryNote(JoinedTableMixin, ActionWithMultipleDevices): + """To confirm a DeliveryNote that has been shared.""" + pass + + class Migrate(JoinedTableMixin, ActionWithMultipleDevices): """Moves the devices to a new database/inventory. Devices cannot be modified anymore at the previous database. diff --git a/ereuse_devicehub/resources/action/models.pyi b/ereuse_devicehub/resources/action/models.pyi index 032fcd61..3293b46a 100644 --- a/ereuse_devicehub/resources/action/models.pyi +++ b/ereuse_devicehub/resources/action/models.pyi @@ -533,6 +533,10 @@ class Receive(ActionWithMultipleDevices): self.role = ... # type: ReceiverRole +class ShareDeliveryNote(ActionWithMultipleDevices): + pass + + class Migrate(ActionWithMultipleDevices): other = ... # type: Column diff --git a/ereuse_devicehub/resources/action/schemas.py b/ereuse_devicehub/resources/action/schemas.py index 7ef82dd4..34108633 100644 --- a/ereuse_devicehub/resources/action/schemas.py +++ b/ereuse_devicehub/resources/action/schemas.py @@ -438,6 +438,15 @@ class Receive(ActionWithMultipleDevices): role = EnumField(ReceiverRole) +class ShareDeliveryNote(ActionWithMultipleDevices): + __doc__ = m.ShareDeliveryNote.__doc__ + supplier = SanitizedStr(validate=Length(max=STR_SIZE), data_key='supplierName') + date_delivery_note = DateTime(data_key='dateDeliveryNote') + deposit = Integer(data_key='depositValue') + address_note = UUID(dump_only=True) + id_delivery_note = UUID(dump_only=True) + + class Migrate(ActionWithMultipleDevices): __doc__ = m.Migrate.__doc__ other = URL() diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 0e2f07e7..96fc459b 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -95,8 +95,7 @@ class Device(Thing): color.comment = """The predominant color of the device.""" production_date = Column(db.DateTime) production_date.comment = """The date of production of the device. - This is timezone naive, as Workbench cannot report this data - with timezone information. + This is timezone naive, as Workbench cannot report this data with timezone information. """ variant = Column(db.CIText()) variant.comment = """A variant or sub-model of the device.""" diff --git a/ereuse_devicehub/resources/documents/templates/documents/layout.html b/ereuse_devicehub/resources/documents/templates/documents/layout.html index 45f16861..3794f343 100644 --- a/ereuse_devicehub/resources/documents/templates/documents/layout.html +++ b/ereuse_devicehub/resources/documents/templates/documents/layout.html @@ -11,7 +11,7 @@ - Devicehub | {{ title }} + USOdy | {{ title }}
diff --git a/ereuse_devicehub/resources/lot/dag.sql b/ereuse_devicehub/resources/lot/dag.sql index dd4a94c8..c1eef99c 100644 --- a/ereuse_devicehub/resources/lot/dag.sql +++ b/ereuse_devicehub/resources/lot/dag.sql @@ -110,6 +110,3 @@ BEGIN END $$ LANGUAGE plpgsql; - - - diff --git a/ereuse_devicehub/resources/lot/models.py b/ereuse_devicehub/resources/lot/models.py index a26bbd53..53b634b4 100644 --- a/ereuse_devicehub/resources/lot/models.py +++ b/ereuse_devicehub/resources/lot/models.py @@ -26,6 +26,18 @@ class Lot(Thing): description.comment = """A comment about the lot.""" closed = db.Column(db.Boolean, default=False, nullable=False) closed.comment = """A closed lot cannot be modified anymore.""" + + # New variables for DeliveryNote + supplier = db.Column() # String, nullable, ... + supplier.comment = """Name of the organization/agent that create DeliveryNote.""" + date_delivery_note = db.Column() + date_delivery_note.comment = """Date of note creation.""" + # Is the same of lot id?? + id_delivery_note = db.Column(UUID(as_uuid=True)) + id_delivery_note.comment = """Unique id of lot and delivery note""" + # deposit = db.Column() + # deposit.comment = """Total amount of deposit devices in Lot.""" + devices = db.relationship(Device, backref=db.backref('lots', lazy=True, collection_class=set), secondary=lambda: LotDevice.__table__, diff --git a/ereuse_devicehub/resources/lot/models.pyi b/ereuse_devicehub/resources/lot/models.pyi index e552bbf4..4103c495 100644 --- a/ereuse_devicehub/resources/lot/models.pyi +++ b/ereuse_devicehub/resources/lot/models.pyi @@ -88,6 +88,18 @@ class Path: self.path = ... # type: Ltree self.created = ... # type: datetime + @classmethod + def has_lot(cls, id, id1): + pass + + @classmethod + def delete(cls, id, id1): + pass + + @classmethod + def add(cls, id, id1): + pass + class LotDeviceDescendants(db.Model): device_id = ... # type: Column diff --git a/tests/files/acer.happy.battery.snapshot.yaml b/tests/files/acer.happy.battery.snapshot.yaml new file mode 100644 index 00000000..7d164b53 --- /dev/null +++ b/tests/files/acer.happy.battery.snapshot.yaml @@ -0,0 +1,151 @@ +--- +components: + - size: 10.030411318500475 + technology: LCD + resolutionWidth: 1024 + model: AUO LCD Monitor + actions: [] + type: Display + refreshRate: 60 + productionDate: '2009-01-04T00:00:00' + manufacturer: AUO "AUO" + serialNumber: + resolutionHeight: 600 + - generation: + actions: + - rate: 164.4981 + type: BenchmarkProcessorSysbench + elapsed: 165 + - rate: 6650.48 + type: BenchmarkProcessor + elapsed: 0 + speed: 1 + cores: 1 + model: Intel Atom CPU N450 @ 1.66GHz + address: 64 + type: Processor + threads: 2 + manufacturer: Intel Corp. + serialNumber: + brand: Atom + - memory: + model: Atom Processor D4xx/D5xx/N4xx/N5xx Integrated Graphics Controller + actions: [] + type: GraphicCard + manufacturer: Intel Corporation + serialNumber: + - size: 2200 + technology: LiIon + actions: + - size: 641 + type: MeasureBattery + voltage: 12608 + cycleCount: + severity: Info + model: AL10A31 + type: Battery + manufacturer: SANYO + serialNumber: + - type: SoundCard + actions: [] + manufacturer: Intel Corporation + serialNumber: + model: NM10/ICH7 Family High Definition Audio Controller + - type: SoundCard + actions: [] + manufacturer: XPA970VW0 + serialNumber: + model: 1.3M WebCam + - size: 1024 + actions: [] + format: SODIMM + model: 48594D503131325336344350362D53362020 + interface: DDR2 + type: RamModule + manufacturer: Hynix Semiconductor + serialNumber: 4F43487B + speed: 667 + - size: 160041.88569599998 + variant: 1A01 + actions: + - type: EraseBasic + steps: + - type: StepRandom + endTime: '2019-10-23T08:35:31.400587+00:00' + severity: Info + startTime: '2019-10-23T07:49:54.410830+00:00' + endTime: '2019-10-23T08:35:31.400988+00:00' + severity: Info + startTime: '2019-10-23T07:49:54.410193+00:00' + - elapsed: 22 + writeSpeed: 17.3 + readSpeed: 41.6 + type: BenchmarkDataStorage + - status: Completed without error + reallocatedSectorCount: 0 + currentPendingSectorCount: 0 + assessment: true + severity: Info + offlineUncorrectable: 0 + lifetime: 4692 + type: TestDataStorage + length: Short + elapsed: 118 + powerCycleCount: 5293 + model: WDC WD1600BEVT-2 + interface: ATA + type: HardDrive + manufacturer: Western Digital + serialNumber: WD-WX11A80W7430 + - variant: c1 + actions: [] + speed: 100 + model: AR8152 v1.1 Fast Ethernet + wireless: false + type: NetworkAdapter + serialNumber: 88:ae:1d:a6:f3:d0 + manufacturer: Qualcomm Atheros + - variant: '00' + actions: [] + speed: + model: Centrino Wireless-N 1000 Condor Peak + wireless: true + type: NetworkAdapter + serialNumber: 00:26:c7:8e:cb:8c + manufacturer: Intel Corporation + - ramMaxSize: 4 + slots: 1 + model: AOHAPPY + pcmcia: 0 + type: Motherboard + version: V3.05(DDR2) + ramSlots: 2 + serialNumber: Base Board Serial Number + manufacturer: Acer + serial: 1 + actions: [] + biosDate: '2010-08-12T00:00:00' + firewire: 0 + usb: 5 +software: Workbench +device: + sku: + chassis: Netbook + actions: + - type: StressTest + elapsed: 60 + severity: Info + - rate: 19.2726 + type: BenchmarkRamSysbench + elapsed: 19 + model: AOHAPPY + type: Laptop + version: V3.05 + manufacturer: Acer + serialNumber: LUSEA0D010038879A01601 +uuid: 490fb8c0-81a1-42e9-95e0-5e7db7038ec2 +type: Snapshot +version: 11.0b9 +endTime: '2019-10-23T07:43:13.625104+00:00' +elapsed: 3138 +closed: true \ No newline at end of file diff --git a/tests/test_rate.py b/tests/test_rate.py index 9a092fe4..7a37dca3 100644 --- a/tests/test_rate.py +++ b/tests/test_rate.py @@ -139,6 +139,7 @@ def test_multiple_rates(user: UserClient): This ensures that rates only takes all the correct actions and components rates in case device have new tests/benchmarks. """ + pc = Desktop(chassis=ComputerChassis.Tower) hdd = HardDrive(size=476940) hdd.actions_one.add(BenchmarkDataStorage(read_speed=126, write_speed=29.8)) diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index fc5045e7..c3c211d7 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -12,7 +12,8 @@ from ereuse_devicehub.client import UserClient from ereuse_devicehub.db import db from ereuse_devicehub.devicehub import Devicehub from ereuse_devicehub.resources.action.models import Action, BenchmarkDataStorage, \ - BenchmarkProcessor, EraseSectors, RateComputer, Snapshot, SnapshotRequest, VisualTest + BenchmarkProcessor, EraseSectors, RateComputer, Snapshot, SnapshotRequest, VisualTest, \ + MeasureBattery, BenchmarkRamSysbench, StressTest from ereuse_devicehub.resources.device import models as m from ereuse_devicehub.resources.device.exceptions import NeedsId from ereuse_devicehub.resources.device.models import SolidStateDrive @@ -492,3 +493,11 @@ def test_pc_rating_rate_none(user: UserClient): def test_pc_2(user: UserClient): s = file('laptop-hp_255_g3_notebook-hewlett-packard-cnd52270fw.snapshot') snapshot, _ = user.post(res=Snapshot, data=s) + + +@pytest.mark.xfail(reason='Add battery component assets') +def test_snapshot_pc_with_battery_component(user: UserClient): + pc1 = file('acer.happy.battery.snapshot') + snapshot = snapshot_and_check(user, pc1, + action_types=(StressTest.t, BenchmarkRamSysbench.t), + perform_second_snapshot=False)