From 7a88d9d730217f5f031594f1f467bf23982cb811 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 3 Feb 2021 22:06:27 +0100 Subject: [PATCH 01/14] change the name of lot with documentId --- ereuse_devicehub/resources/deliverynote/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/deliverynote/views.py b/ereuse_devicehub/resources/deliverynote/views.py index b22e999e..b9650b98 100644 --- a/ereuse_devicehub/resources/deliverynote/views.py +++ b/ereuse_devicehub/resources/deliverynote/views.py @@ -16,7 +16,7 @@ class DeliverynoteView(View): dn = request.get_json() dlvnote = Deliverynote(**dn) # Create a lot - lot_name = dlvnote.supplier_email + "_" + datetime.datetime.utcnow().strftime("%B-%d-%Y") + lot_name = dlvnote.document_id + "_" + datetime.datetime.utcnow().strftime("%B-%d-%Y") new_lot = Lot(name=lot_name) dlvnote.lot_id = new_lot.id db.session.add(new_lot) From b9f3d5976b69e09c200ae2df3e4e16ed0dd918dc Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 3 Feb 2021 22:28:04 +0100 Subject: [PATCH 02/14] drop ethereum_address of deliverynote --- .../eca457d8b2a4_change_deliverynote.py | 34 +++++++++++++++++++ .../resources/deliverynote/models.py | 1 - .../resources/deliverynote/schemas.py | 1 - .../resources/deliverynote/views.py | 3 +- 4 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py diff --git a/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py b/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py new file mode 100644 index 00000000..6cd89970 --- /dev/null +++ b/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py @@ -0,0 +1,34 @@ +"""change deliverynote + +Revision ID: eca457d8b2a4 +Revises: 0cbd839b09ef +Create Date: 2021-02-03 22:12:41.033661 + +""" +from alembic import context +from alembic import op +import sqlalchemy as sa +import sqlalchemy_utils +import citext +import teal + + +# revision identifiers, used by Alembic. +revision = 'eca457d8b2a4' +down_revision = '0cbd839b09ef' +branch_labels = None +depends_on = None + + +def get_inv(): + INV = context.get_x_argument(as_dictionary=True).get('inventory') + if not INV: + raise ValueError("Inventory value is not specified") + return INV + +def upgrade(): + op.drop_column('deliverynote', 'ethereum_address', schema=f'{get_inv()}') + + +def downgrade(): + op.add_column('deliverynote', sa.Column('ethereum_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') diff --git a/ereuse_devicehub/resources/deliverynote/models.py b/ereuse_devicehub/resources/deliverynote/models.py index 9896ab50..e791f450 100644 --- a/ereuse_devicehub/resources/deliverynote/models.py +++ b/ereuse_devicehub/resources/deliverynote/models.py @@ -46,7 +46,6 @@ class Deliverynote(Thing): transferred_devices = db.Column(db.ARRAY(db.Integer, dimensions=1), nullable=True) transfer_state = db.Column(IntEnum(TransferState), default=TransferState.Initial, nullable=False) transfer_state.comment = TransferState.__doc__ - ethereum_address = db.Column(CIText(), unique=True, default=None) lot_id = db.Column(UUID(as_uuid=True), db.ForeignKey(Lot.id), nullable=False) diff --git a/ereuse_devicehub/resources/deliverynote/schemas.py b/ereuse_devicehub/resources/deliverynote/schemas.py index 58808f6d..60854991 100644 --- a/ereuse_devicehub/resources/deliverynote/schemas.py +++ b/ereuse_devicehub/resources/deliverynote/schemas.py @@ -21,7 +21,6 @@ class Deliverynote(Thing): date = f.DateTime('iso', required=True) deposit = f.Integer(validate=f.validate.Range(min=0, max=100), description=m.Deliverynote.deposit.__doc__) - ethereum_address = f.String(description='User identifier address inside the Blockchain') expected_devices = f.List(f.Dict, required=True, data_key='expectedDevices') transferred_devices = f.List(f.Integer(), required=False, data_key='transferredDevices') transfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment) diff --git a/ereuse_devicehub/resources/deliverynote/views.py b/ereuse_devicehub/resources/deliverynote/views.py index b9650b98..6d895259 100644 --- a/ereuse_devicehub/resources/deliverynote/views.py +++ b/ereuse_devicehub/resources/deliverynote/views.py @@ -28,8 +28,7 @@ class DeliverynoteView(View): return ret def patch(self, id): - patch_schema = self.resource_def.SCHEMA(only=('transfer_state', - 'ethereum_address'), partial=True) + patch_schema = self.resource_def.SCHEMA(only=('transfer_state'), partial=True) d = request.get_json(schema=patch_schema) dlvnote = Deliverynote.query.filter_by(id=id).one() # device_fields = ['transfer_state', 'deliverynote_address'] From ee4bf45c72152f823d9f8a7cf807ceb0f8ce515d Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 4 Feb 2021 11:13:55 +0100 Subject: [PATCH 03/14] restart name of lot --- ereuse_devicehub/resources/deliverynote/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/deliverynote/views.py b/ereuse_devicehub/resources/deliverynote/views.py index 6d895259..321f7ad9 100644 --- a/ereuse_devicehub/resources/deliverynote/views.py +++ b/ereuse_devicehub/resources/deliverynote/views.py @@ -16,7 +16,7 @@ class DeliverynoteView(View): dn = request.get_json() dlvnote = Deliverynote(**dn) # Create a lot - lot_name = dlvnote.document_id + "_" + datetime.datetime.utcnow().strftime("%B-%d-%Y") + lot_name = dlvnote.supplier_email + "_" + datetime.datetime.utcnow().strftime("%B-%d-%Y") new_lot = Lot(name=lot_name) dlvnote.lot_id = new_lot.id db.session.add(new_lot) From a716e9579238cf253a5920b4315e8c9c77eb33bf Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 4 Feb 2021 12:23:28 +0100 Subject: [PATCH 04/14] fixing problem in live test --- tests/test_action.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_action.py b/tests/test_action.py index e1361efd..d1990a0c 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -580,7 +580,7 @@ def test_save_live_json(app: Devicehub, user: UserClient, client: Client): snapshot = {'debug': ''} if files: - path_snapshot = os.path.join(path_dir_base, files[0]) + path_snapshot = os.path.join(path_dir_base, files[-1]) with open(path_snapshot) as file_snapshot: snapshot = json.loads(file_snapshot.read()) From 95f04094c7b5e88bf5fc575084b97b380c2cb2b4 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 4 Feb 2021 12:51:51 +0100 Subject: [PATCH 05/14] fixing problem in live test2 --- tests/test_action.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/test_action.py b/tests/test_action.py index d1990a0c..421a5c80 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -279,6 +279,8 @@ def test_live(user: UserClient, client: Client, app: Devicehub): assert action_live[0].serial_number == 'wd-wx11a80w7430' assert action_live[0].licence_version == '1.0' assert str(action_live[0].snapshot_uuid) == acer['uuid'] + tmp_snapshots = app.config['TMP_LIVES'] + shutil.rmtree(tmp_snapshots) @pytest.mark.mvp @@ -303,6 +305,8 @@ def test_live_example(user: UserClient, client: Client, app: Devicehub): action_live = [a for a in db_device.actions if a.type == 'Live'] assert len(action_live) == 1 assert str(action_live[0].snapshot_uuid) == acer['uuid'] + tmp_snapshots = app.config['TMP_LIVES'] + shutil.rmtree(tmp_snapshots) @pytest.mark.mvp @@ -330,6 +334,8 @@ def test_live_two_users(user: UserClient, user2: UserClient, client: Client, app action_live = [a for a in db_device.actions if a.type == 'Live'] assert len(action_live) == 1 assert str(action_live[0].snapshot_uuid) == acer['uuid'] + tmp_snapshots = app.config['TMP_LIVES'] + shutil.rmtree(tmp_snapshots) @pytest.mark.mvp @@ -363,6 +369,8 @@ def test_live_two_allocated(user: UserClient, user2: UserClient, client: Client, live, _ = client.post(acer, res=models.Live, status=422) message = 'Expected only one Device but multiple where found' assert live['message'] == message + tmp_snapshots = app.config['TMP_LIVES'] + shutil.rmtree(tmp_snapshots) @pytest.mark.mvp @@ -394,6 +402,8 @@ def test_live_without_TestDataStorage(user: UserClient, client: Client, app: Dev assert live['description'] == description db_live = models.Live.query.filter_by(id=live['id']).one() assert db_live.usage_time_hdd is None + tmp_snapshots = app.config['TMP_LIVES'] + shutil.rmtree(tmp_snapshots) @pytest.mark.mvp @@ -421,6 +431,8 @@ def test_live_without_hdd_1(user: UserClient, client: Client, app: Devicehub): acer['licence_version'] = '1.0.0' response, _ = client.post(acer, res=models.Live, status=404) assert "The There aren't any disk in this device" in response['message'] + tmp_snapshots = app.config['TMP_LIVES'] + shutil.rmtree(tmp_snapshots) @pytest.mark.mvp @@ -448,6 +460,8 @@ def test_live_without_hdd_2(user: UserClient, client: Client, app: Devicehub): acer['licence_version'] = '1.0.0' response, _ = client.post(acer, res=models.Live, status=404) assert "The There aren't any disk in this device" in response['message'] + tmp_snapshots = app.config['TMP_LIVES'] + shutil.rmtree(tmp_snapshots) @pytest.mark.mvp @@ -482,6 +496,8 @@ def test_live_without_hdd_3(user: UserClient, client: Client, app: Devicehub): db_live = models.Live.query.filter_by(id=live['id']).one() assert str(db_live.usage_time_hdd) == '195 days, 12:00:00' assert str(db_live.usage_time_allocate) == '0:00:00' + tmp_snapshots = app.config['TMP_LIVES'] + shutil.rmtree(tmp_snapshots) @pytest.mark.mvp @@ -516,6 +532,8 @@ def test_live_with_hdd_with_old_time(user: UserClient, client: Client, app: Devi db_live = models.Live.query.filter_by(id=live['id']).one() assert str(db_live.usage_time_hdd) == '191 days, 8:00:00' assert str(db_live.usage_time_allocate) == '0:00:00' + tmp_snapshots = app.config['TMP_LIVES'] + shutil.rmtree(tmp_snapshots) @pytest.mark.mvp @@ -546,6 +564,8 @@ def test_live_search_last_allocate(user: UserClient, client: Client, app: Device acer['components'][7]['actions'] = actions live, _ = client.post(acer, res=models.Live) assert live['usageTimeAllocate'] == 1000 + tmp_snapshots = app.config['TMP_LIVES'] + shutil.rmtree(tmp_snapshots) @pytest.mark.mvp @@ -584,7 +604,7 @@ def test_save_live_json(app: Devicehub, user: UserClient, client: Client): with open(path_snapshot) as file_snapshot: snapshot = json.loads(file_snapshot.read()) - shutil.rmtree(tmp_snapshots) + shutil.rmtree(tmp_snapshots) assert snapshot['debug'] == debug From fe824cc4fa11246890ac813adc56c265f84520e2 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 4 Feb 2021 13:06:51 +0100 Subject: [PATCH 06/14] drop deliverynote_address --- .../migrations/versions/eca457d8b2a4_change_deliverynote.py | 4 ++++ ereuse_devicehub/resources/deliverynote/models.pyi | 2 -- ereuse_devicehub/resources/device/models.py | 1 - ereuse_devicehub/resources/device/models.pyi | 2 -- ereuse_devicehub/resources/device/schemas.py | 1 - ereuse_devicehub/resources/device/views.py | 2 +- ereuse_devicehub/resources/lot/models.py | 1 - ereuse_devicehub/resources/lot/models.pyi | 2 -- ereuse_devicehub/resources/lot/views.py | 4 ++-- tests/test_device.py | 1 - 10 files changed, 7 insertions(+), 13 deletions(-) diff --git a/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py b/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py index 6cd89970..e35d87e7 100644 --- a/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py +++ b/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py @@ -28,7 +28,11 @@ def get_inv(): def upgrade(): op.drop_column('deliverynote', 'ethereum_address', schema=f'{get_inv()}') + op.drop_column('computer', 'deliverynote_address', schema=f'{get_inv()}') + op.drop_column('lot', 'deliverynote_address', schema=f'{get_inv()}') def downgrade(): op.add_column('deliverynote', sa.Column('ethereum_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') + op.add_column('computer', sa.Column('deliverynote_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') + op.add_column('lot', sa.Column('deliverynote_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') diff --git a/ereuse_devicehub/resources/deliverynote/models.pyi b/ereuse_devicehub/resources/deliverynote/models.pyi index 3ed6be5c..d428a7cd 100644 --- a/ereuse_devicehub/resources/deliverynote/models.pyi +++ b/ereuse_devicehub/resources/deliverynote/models.pyi @@ -30,7 +30,6 @@ class Lot(Thing): transfer_state = ... # type: Column receiver_address = ... # type: Column receiver = ... # type: relationship - deliverynote_address = ... # type: Column def __init__(self, name: str, closed: bool = closed.default.arg) -> None: super().__init__() @@ -46,7 +45,6 @@ class Lot(Thing): self.owner_address = ... # type: UUID self.transfer_state = ... self.receiver_address = ... # type: str - self.deliverynote_address = ... # type: str def add_children(self, *children: Union[Lot, uuid.UUID]): pass diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index a91beb5f..da1c0888 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -484,7 +484,6 @@ class Computer(Device): db.ForeignKey(User.id), nullable=True) receiver = db.relationship(User, primaryjoin=receiver_id == User.id) - deliverynote_address = db.Column(CIText(), nullable=True) def __init__(self, *args, **kwargs) -> None: if args: diff --git a/ereuse_devicehub/resources/device/models.pyi b/ereuse_devicehub/resources/device/models.pyi index 9fa9665b..6b3b8dc4 100644 --- a/ereuse_devicehub/resources/device/models.pyi +++ b/ereuse_devicehub/resources/device/models.pyi @@ -145,7 +145,6 @@ class Computer(DisplayMixin, Device): owner_address = ... # type: Column transfer_state = ... # type: Column receiver_address = ... # type: Column - deliverynote_address = ... # type: Column def __init__(self, **kwargs) -> None: super().__init__(**kwargs) @@ -155,7 +154,6 @@ class Computer(DisplayMixin, Device): self.owner_address = ... # type: UUID self.transfer_state = ... self.receiver_address = ... # type: str - self.deliverynote_address = ... # type: str @property def actions(self) -> List: diff --git a/ereuse_devicehub/resources/device/schemas.py b/ereuse_devicehub/resources/device/schemas.py index ea5b3211..512c11bb 100644 --- a/ereuse_devicehub/resources/device/schemas.py +++ b/ereuse_devicehub/resources/device/schemas.py @@ -130,7 +130,6 @@ class Computer(Device): owner_id = UUID(data_key='ownerID') transfer_state = EnumField(enums.TransferState, description=m.Computer.transfer_state.comment) receiver_id = UUID(data_key='receiverID') - deliverynote_address = SanitizedStr(validate=f.validate.Length(max=42)) class Desktop(Computer): diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index fcb0e17f..83e16de7 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -106,7 +106,7 @@ class DeviceView(View): resource_def = app.resources['Computer'] # TODO check how to handle the 'actions_one' patch_schema = resource_def.SCHEMA( - only=['ethereum_address', 'transfer_state', 'deliverynote_address', 'actions_one'], partial=True) + only=['ethereum_address', 'transfer_state', 'actions_one'], partial=True) json = request.get_json(schema=patch_schema) # TODO check how to handle the 'actions_one' json.pop('actions_one') diff --git a/ereuse_devicehub/resources/lot/models.py b/ereuse_devicehub/resources/lot/models.py index eb5a55d0..4be0678b 100644 --- a/ereuse_devicehub/resources/lot/models.py +++ b/ereuse_devicehub/resources/lot/models.py @@ -75,7 +75,6 @@ class Lot(Thing): db.ForeignKey(User.ethereum_address), nullable=True) receiver = db.relationship(User, primaryjoin=receiver_address == User.ethereum_address) - deliverynote_address = db.Column(CIText(), nullable=True) def __init__(self, name: str, closed: bool = closed.default.arg, description: str = None) -> None: diff --git a/ereuse_devicehub/resources/lot/models.pyi b/ereuse_devicehub/resources/lot/models.pyi index cf7c0769..0ba97058 100644 --- a/ereuse_devicehub/resources/lot/models.pyi +++ b/ereuse_devicehub/resources/lot/models.pyi @@ -30,7 +30,6 @@ class Lot(Thing): transfer_state = ... # type: Column receiver_address = ... # type: Column receiver = ... # type: relationship - deliverynote_address = ... # type: Column def __init__(self, name: str, closed: bool = closed.default.arg) -> None: super().__init__() @@ -46,7 +45,6 @@ class Lot(Thing): self.owner_address = ... # type: UUID self.transfer_state = ... self.receiver_address = ... # type: str - self.deliverynote_address = ... # type: str def add_children(self, *children: Union[Lot, uuid.UUID]): pass diff --git a/ereuse_devicehub/resources/lot/views.py b/ereuse_devicehub/resources/lot/views.py index e0ac1691..d2b827e5 100644 --- a/ereuse_devicehub/resources/lot/views.py +++ b/ereuse_devicehub/resources/lot/views.py @@ -41,11 +41,11 @@ class LotView(View): def patch(self, id): patch_schema = self.resource_def.SCHEMA(only=( - 'name', 'description', 'transfer_state', 'receiver_address', 'deposit', 'deliverynote_address', 'devices', + 'name', 'description', 'transfer_state', 'receiver_address', 'deposit', 'devices', 'owner_address'), partial=True) l = request.get_json(schema=patch_schema) lot = Lot.query.filter_by(id=id).one() - device_fields = ['transfer_state', 'receiver_address', 'deposit', 'deliverynote_address', 'owner_address'] + device_fields = ['transfer_state', 'receiver_address', 'deposit', 'owner_address'] computers = [x for x in lot.all_devices if isinstance(x, Computer)] for key, value in l.items(): setattr(lot, key, value) diff --git a/tests/test_device.py b/tests/test_device.py index d9170c5c..e7810542 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -125,7 +125,6 @@ def test_physical_properties(): } assert pc.physical_properties == { 'chassis': ComputerChassis.Tower, - 'deliverynote_address': None, 'deposit': 0, 'ethereum_address': None, 'manufacturer': 'bar', From 2619f88a9f4bdfafc5db117cbc44cdceda67142d Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 4 Feb 2021 13:50:00 +0100 Subject: [PATCH 07/14] drop all proof --- ereuse_devicehub/config.py | 3 +- .../eca457d8b2a4_change_deliverynote.py | 101 +++++++++++- ereuse_devicehub/resources/proof/__init__.py | 37 ----- ereuse_devicehub/resources/proof/models.py | 149 ------------------ ereuse_devicehub/resources/proof/schemas.py | 70 -------- ereuse_devicehub/resources/proof/views.py | 36 ----- tests/test_basic.py | 3 +- 7 files changed, 98 insertions(+), 301 deletions(-) delete mode 100644 ereuse_devicehub/resources/proof/__init__.py delete mode 100644 ereuse_devicehub/resources/proof/models.py delete mode 100644 ereuse_devicehub/resources/proof/schemas.py delete mode 100644 ereuse_devicehub/resources/proof/views.py diff --git a/ereuse_devicehub/config.py b/ereuse_devicehub/config.py index cc4a65f5..449f104d 100644 --- a/ereuse_devicehub/config.py +++ b/ereuse_devicehub/config.py @@ -9,7 +9,7 @@ from teal.enums import Currency from teal.utils import import_resource from ereuse_devicehub.resources import action, agent, deliverynote, inventory, \ - lot, proof, tag, user + lot, tag, user from ereuse_devicehub.resources.device import definitions from ereuse_devicehub.resources.documents import documents from ereuse_devicehub.resources.enums import PriceSoftware @@ -26,7 +26,6 @@ class DevicehubConfig(Config): import_resource(agent), import_resource(lot), import_resource(deliverynote), - import_resource(proof), import_resource(documents), import_resource(inventory), import_resource(versions), diff --git a/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py b/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py index e35d87e7..f437b0cd 100644 --- a/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py +++ b/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py @@ -5,12 +5,11 @@ Revises: 0cbd839b09ef Create Date: 2021-02-03 22:12:41.033661 """ -from alembic import context -from alembic import op -import sqlalchemy as sa -import sqlalchemy_utils import citext -import teal +import sqlalchemy as sa +from alembic import op +from alembic import context +from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. @@ -30,9 +29,101 @@ def upgrade(): op.drop_column('deliverynote', 'ethereum_address', schema=f'{get_inv()}') op.drop_column('computer', 'deliverynote_address', schema=f'{get_inv()}') op.drop_column('lot', 'deliverynote_address', schema=f'{get_inv()}') + op.drop_table('proof_function', schema=f'{get_inv()}') + op.drop_table('proof_data_wipe', schema=f'{get_inv()}') + op.drop_table('proof_transfer', schema=f'{get_inv()}') + op.drop_table('proof_reuse', schema=f'{get_inv()}') + op.drop_table('proof_recycling', schema=f'{get_inv()}') + op.drop_index(op.f('ix_proof_updated'), table_name='proof', schema=f'{get_inv()}') + op.drop_index(op.f('ix_proof_created'), table_name='proof', schema=f'{get_inv()}') + op.drop_table('proof', schema=f'{get_inv()}') def downgrade(): op.add_column('deliverynote', sa.Column('ethereum_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') op.add_column('computer', sa.Column('deliverynote_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') op.add_column('lot', sa.Column('deliverynote_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') + op.create_table('proof', + sa.Column('updated', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), + nullable=False, + comment='The last time Devicehub recorded a change for \n this thing.\n '), + sa.Column('created', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), + nullable=False, comment='When Devicehub created this.'), + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('type', sa.Unicode(), nullable=False), + sa.Column('ethereum_hash', citext.CIText(), nullable=False), + sa.Column('device_id', sa.BigInteger(), nullable=False), + sa.ForeignKeyConstraint(['device_id'], [f'{get_inv()}.device.id'], ), + sa.PrimaryKeyConstraint('id'), + schema=f'{get_inv()}' + ) + op.create_index(op.f('ix_proof_created'), 'proof', ['created'], unique=False, schema=f'{get_inv()}') + op.create_index(op.f('ix_proof_updated'), 'proof', ['updated'], unique=False, schema=f'{get_inv()}') + op.create_table('proof_recycling', + sa.Column('collection_point', citext.CIText(), nullable=False), + sa.Column('date', sa.DateTime(), nullable=False), + sa.Column('contact', citext.CIText(), nullable=False), + sa.Column('ticket', citext.CIText(), nullable=False), + sa.Column('gps_location', citext.CIText(), nullable=False), + sa.Column('recycler_code', citext.CIText(), nullable=False), + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.proof.id'], ), + sa.PrimaryKeyConstraint('id'), + schema=f'{get_inv()}' + ) + + # Proof reuse table + op.create_table('proof_reuse', + sa.Column('receiver_segment', citext.CIText(), nullable=False), + sa.Column('id_receipt', citext.CIText(), nullable=False), + sa.Column('supplier_id', postgresql.UUID(as_uuid=True), nullable=True), + sa.Column('receiver_id', postgresql.UUID(as_uuid=True), nullable=True), + sa.Column('price', sa.Integer(), nullable=True), + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.proof.id'], ), + sa.ForeignKeyConstraint(['receiver_id'], ['common.user.id'], ), + sa.ForeignKeyConstraint(['supplier_id'], ['common.user.id'], ), + sa.PrimaryKeyConstraint('id'), + schema=f'{get_inv()}' + ) + + # Proof transfer table + op.create_table('proof_transfer', + sa.Column('supplier_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('receiver_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('deposit', sa.Integer(), nullable=True), + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.proof.id'], ), + sa.ForeignKeyConstraint(['receiver_id'], ['common.user.id'], ), + sa.ForeignKeyConstraint(['supplier_id'], ['common.user.id'], ), + sa.PrimaryKeyConstraint('id'), + schema=f'{get_inv()}' + ) + + + # ProofDataWipe table + op.create_table('proof_data_wipe', + sa.Column('date', sa.DateTime(), nullable=False), + sa.Column('result', sa.Boolean(), nullable=False, comment='Identifies proof datawipe as a result.'), + sa.Column('proof_author_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('erasure_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.ForeignKeyConstraint(['erasure_id'], [f'{get_inv()}.erase_basic.id'], ), + sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.proof.id'], ), + sa.ForeignKeyConstraint(['proof_author_id'], ['common.user.id'], ), + sa.PrimaryKeyConstraint('id'), + schema=f'{get_inv()}' + ) + + # PRoofFuntion + op.create_table('proof_function', + sa.Column('disk_usage', sa.Integer(), nullable=True), + sa.Column('proof_author_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('rate_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.proof.id'], ), + sa.ForeignKeyConstraint(['proof_author_id'], ['common.user.id'], ), + sa.ForeignKeyConstraint(['rate_id'], [f'{get_inv()}.rate.id'], ), + sa.PrimaryKeyConstraint('id'), + schema=f'{get_inv()}' + ) diff --git a/ereuse_devicehub/resources/proof/__init__.py b/ereuse_devicehub/resources/proof/__init__.py deleted file mode 100644 index ef3a68a6..00000000 --- a/ereuse_devicehub/resources/proof/__init__.py +++ /dev/null @@ -1,37 +0,0 @@ -from teal.resource import Converters, Resource - -from ereuse_devicehub.resources.proof import schemas -from ereuse_devicehub.resources.proof.views import ProofView - - -class ProofDef(Resource): - SCHEMA = schemas.Proof - VIEW = ProofView - # AUTH = True - AUTH = False - ID_CONVERTER = Converters.uuid - - -class ProofTransferDef(ProofDef): - VIEW = None - SCHEMA = schemas.ProofTransfer - - -class ProofDataWipeDef(ProofDef): - VIEW = None - SCHEMA = schemas.ProofDataWipe - - -class ProofFunction(ProofDef): - VIEW = None - SCHEMA = schemas.ProofFunction - - -class ProofReuse(ProofDef): - VIEW = None - SCHEMA = schemas.ProofReuse - - -class ProofRecycling(ProofDef): - VIEW = None - SCHEMA = schemas.ProofRecycling diff --git a/ereuse_devicehub/resources/proof/models.py b/ereuse_devicehub/resources/proof/models.py deleted file mode 100644 index 632ec194..00000000 --- a/ereuse_devicehub/resources/proof/models.py +++ /dev/null @@ -1,149 +0,0 @@ -"""This file contains all proofs related to actions - -""" - -from datetime import datetime -from uuid import uuid4 - -from boltons import urlutils -from citext import CIText -from flask import g -from sqlalchemy import BigInteger, Column, ForeignKey, Unicode -from sqlalchemy.dialects.postgresql import UUID -from sqlalchemy.ext.declarative import declared_attr -from sqlalchemy.orm import backref, relationship -from teal.db import CASCADE_OWN, INHERIT_COND, POLYMORPHIC_ID, \ - POLYMORPHIC_ON -from teal.resource import url_for_resource - -from ereuse_devicehub.db import db -from ereuse_devicehub.resources.action.models import EraseBasic, Rate -from ereuse_devicehub.resources.device.models import Device -from ereuse_devicehub.resources.models import Thing -from ereuse_devicehub.resources.user import User - - -class JoinedTableMixin: - # noinspection PyMethodParameters - @declared_attr - def id(cls): - return Column(UUID(as_uuid=True), ForeignKey(Proof.id), primary_key=True) - - -class Proof(Thing): - """Proof over an action. - - """ - id = Column(UUID(as_uuid=True), primary_key=True, default=uuid4) - type = Column(Unicode, nullable=False) - ethereum_hash = Column(CIText(), default='', nullable=False) - device_id = db.Column(BigInteger, - db.ForeignKey(Device.id), - nullable=False) - device = db.relationship(Device, - backref=db.backref('proofs_device', uselist=True, lazy=True), - lazy=True, - primaryjoin=Device.id == device_id) - - @property - def url(self) -> urlutils.URL: - """The URL where to GET this proof.""" - return urlutils.URL(url_for_resource(Proof, item_id=self.id)) - - # noinspection PyMethodParameters - @declared_attr - def __mapper_args__(cls): - """Defines inheritance. - - From `the guide `_ - """ - args = {POLYMORPHIC_ID: cls.t} - if cls.t == 'Proof': - args[POLYMORPHIC_ON] = cls.type - # noinspection PyUnresolvedReferences - if JoinedTableMixin in cls.mro(): - args[INHERIT_COND] = cls.id == Proof.id - return args - - def __init__(self, **kwargs) -> None: - # sortedset forces us to do this before calling our parent init - super().__init__(**kwargs) - - def __repr__(self): - return '<{0.t} {0.id} >'.format(self) - - -class ProofTransfer(JoinedTableMixin, Proof): - supplier_id = db.Column(UUID(as_uuid=True), - db.ForeignKey(User.id), - nullable=False, - default=lambda: g.user.id) - supplier = db.relationship(User, primaryjoin=lambda: ProofTransfer.supplier_id == User.id) - receiver_id = db.Column(UUID(as_uuid=True), - db.ForeignKey(User.id), - nullable=False) - receiver = db.relationship(User, primaryjoin=lambda: ProofTransfer.receiver_id == User.id) - deposit = Column(db.Integer, default=0) - - -class ProofDataWipe(JoinedTableMixin, Proof): - # erasure_type = Column(CIText(), default='', nullable=False) - date = Column(db.DateTime, nullable=False, default=datetime.utcnow) - result = Column(db.Boolean, default=False, nullable=False) - result.comment = """Identifies proof datawipe as a result.""" - proof_author_id = Column(UUID(as_uuid=True), - db.ForeignKey(User.id), - nullable=False, - default=lambda: g.user.id) - proof_author = relationship(User, primaryjoin=lambda: ProofDataWipe.proof_author_id == User.id) - erasure_id = Column(UUID(as_uuid=True), ForeignKey(EraseBasic.id), nullable=False) - erasure = relationship(EraseBasic, - backref=backref('proof_datawipe', - lazy=True, - uselist=False, - cascade=CASCADE_OWN), - primaryjoin=EraseBasic.id == erasure_id) - - -class ProofFunction(JoinedTableMixin, Proof): - disk_usage = Column(db.Integer, default=0) - proof_author_id = Column(UUID(as_uuid=True), - db.ForeignKey(User.id), - nullable=False, - default=lambda: g.user.id) - proof_author = db.relationship(User, primaryjoin=lambda: ProofFunction.proof_author_id == User.id) - rate_id = Column(UUID(as_uuid=True), ForeignKey(Rate.id), nullable=False) - rate = relationship(Rate, - backref=backref('proof_function', - lazy=True, - uselist=False, - cascade=CASCADE_OWN), - primaryjoin=Rate.id == rate_id) - - -class ProofReuse(JoinedTableMixin, Proof): - receiver_segment = Column(CIText(), default='', nullable=False) - id_receipt = Column(CIText(), default='', nullable=False) - supplier_id = db.Column(UUID(as_uuid=True), - db.ForeignKey(User.id), - # nullable=False, - # default=lambda: g.user.id) - nullable=True) - supplier = db.relationship(User, primaryjoin=lambda: ProofReuse.supplier_id == User.id) - receiver_id = db.Column(UUID(as_uuid=True), - db.ForeignKey(User.id), - # nullable=False) - nullable=True) - receiver = db.relationship(User, primaryjoin=lambda: ProofReuse.receiver_id == User.id) - price = Column(db.Integer) - - -class ProofRecycling(JoinedTableMixin, Proof): - collection_point = Column(CIText(), default='', nullable=False) - date = Column(db.DateTime, nullable=False, default=datetime.utcnow) - contact = Column(CIText(), default='', nullable=False) - ticket = Column(CIText(), default='', nullable=False) - gps_location = Column(CIText(), default='', nullable=False) - recycler_code = Column(CIText(), default='', nullable=False) diff --git a/ereuse_devicehub/resources/proof/schemas.py b/ereuse_devicehub/resources/proof/schemas.py deleted file mode 100644 index 2714e5b8..00000000 --- a/ereuse_devicehub/resources/proof/schemas.py +++ /dev/null @@ -1,70 +0,0 @@ -from marshmallow import fields as f -from marshmallow import fields as f -from marshmallow.fields import Boolean, DateTime, Integer, String, UUID -from marshmallow.validate import Length -from teal.marshmallow import SanitizedStr, URL - -from ereuse_devicehub.marshmallow import NestedOn -from ereuse_devicehub.resources.action import schemas as s_action -from ereuse_devicehub.resources.device import schemas as s_device -from ereuse_devicehub.resources.models import STR_BIG_SIZE, STR_SIZE -from ereuse_devicehub.resources.proof import models as m -from ereuse_devicehub.resources.schemas import Thing -from ereuse_devicehub.resources.user import schemas as s_user - - -class Proof(Thing): - __doc__ = m.Proof.__doc__ - id = UUID(dump_only=True) - ethereum_hash = SanitizedStr(default='', validate=Length(max=STR_BIG_SIZE), - data_key="ethereumHash", required=True) - url = URL(dump_only=True, description=m.Proof.url.__doc__) - device_id = Integer(load_only=True, data_key='deviceID') - device = NestedOn(s_device.Device, dump_only=True) - - -class ProofTransfer(Proof): - __doc__ = m.ProofTransfer.__doc__ - deposit = Integer(validate=f.validate.Range(min=0, max=100)) - supplier_id = UUID(load_only=True, required=True, data_key='supplierID') - receiver_id = UUID(load_only=True, required=True, data_key='receiverID') - - -class ProofDataWipe(Proof): - __doc__ = m.ProofDataWipe.__doc__ - # erasure_type = String(default='', data_key='erasureType') - date = DateTime('iso', required=True) - result = Boolean(required=True) - proof_author_id = SanitizedStr(validate=f.validate.Length(max=STR_SIZE), - load_only=True, required=True, data_key='proofAuthorID') - proof_author = NestedOn(s_user.User, dump_only=True) - erasure = NestedOn(s_action.EraseBasic, only_query='id', data_key='erasureID') - - -class ProofFunction(Proof): - __doc__ = m.ProofFunction.__doc__ - disk_usage = Integer(validate=f.validate.Range(min=0, max=100), data_key='diskUsage') - proof_author_id = SanitizedStr(validate=f.validate.Length(max=STR_SIZE), - load_only=True, required=True, data_key='proofAuthorID') - proof_author = NestedOn(s_user.User, dump_only=True) - rate = NestedOn(s_action.Rate, required=True, - only_query='id', data_key='rateID') - - -class ProofReuse(Proof): - __doc__ = m.ProofReuse.__doc__ - receiver_segment = String(default='', data_key='receiverSegment', required=True) - id_receipt = String(default='', data_key='idReceipt', required=True) - supplier_id = UUID(load_only=True, required=False, data_key='supplierID') - receiver_id = UUID(load_only=True, required=False, data_key='receiverID') - price = Integer(required=True) - - -class ProofRecycling(Proof): - __doc__ = m.ProofRecycling.__doc__ - collection_point = SanitizedStr(default='', data_key='collectionPoint', required=True) - date = DateTime('iso', required=True) - contact = SanitizedStr(default='', required=True) - ticket = SanitizedStr(default='', required=True) - gps_location = SanitizedStr(default='', data_key='gpsLocation', required=True) - recycler_code = SanitizedStr(default='', data_key='recyclerCode', required=True) diff --git a/ereuse_devicehub/resources/proof/views.py b/ereuse_devicehub/resources/proof/views.py deleted file mode 100644 index ec4754d5..00000000 --- a/ereuse_devicehub/resources/proof/views.py +++ /dev/null @@ -1,36 +0,0 @@ -from distutils.version import StrictVersion - -from flask import current_app as app, request, jsonify -from teal.marshmallow import ValidationError -from teal.resource import View - -from ereuse_devicehub.db import db - -SUPPORTED_WORKBENCH = StrictVersion('11.0') - - -class ProofView(View): - def post(self): - """Posts batches of proofs.""" - json = request.get_json(validate=False) - if not json: - raise ValidationError('JSON is not correct.') - # todo there should be a way to better get subclassess resource - # defs - proofs = list() - if json['batch']: - for prf in json['proofs']: - resource_def = app.resources[prf['type']] - p = resource_def.schema.load(prf) - Model = db.Model._decl_class_registry.data[prf['type']]() - proof = Model(**p) - db.session.add(proof) - proofs.append(resource_def.schema.dump(proof)) - db.session().final_flush() - db.session.commit() - response = jsonify({ - 'items': proofs, - 'url': request.path - }) - response.status_code = 201 - return response diff --git a/tests/test_basic.py b/tests/test_basic.py index 53cda3c4..34cb6596 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -80,7 +80,6 @@ def test_api_docs(client: Client): '/pack-of-screwdrivers/{dev1_id}/merge/{dev2_id}', '/printers/{dev1_id}/merge/{dev2_id}', '/processors/{dev1_id}/merge/{dev2_id}', - '/proofs/', '/rackets/{dev1_id}/merge/{dev2_id}', '/ram-modules/{dev1_id}/merge/{dev2_id}', '/recreations/{dev1_id}/merge/{dev2_id}', @@ -119,4 +118,4 @@ def test_api_docs(client: Client): 'scheme': 'basic', 'name': 'Authorization' } - assert len(docs['definitions']) == 124 + assert len(docs['definitions']) == 118 From a0546e284e8e9b194b10dc8f859107c03065acbb Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 4 Feb 2021 20:42:50 +0100 Subject: [PATCH 08/14] fixed a litle bug of documentId representation --- ereuse_devicehub/resources/deliverynote/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/deliverynote/models.py b/ereuse_devicehub/resources/deliverynote/models.py index e791f450..5b56312e 100644 --- a/ereuse_devicehub/resources/deliverynote/models.py +++ b/ereuse_devicehub/resources/deliverynote/models.py @@ -83,4 +83,4 @@ class Deliverynote(Thing): db.session.delete(self) def __repr__(self) -> str: - return ''.format(self) + return ''.format(self) From 761e70b5e63de9de4d96d38e6dc371ba1dd3411a Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 4 Feb 2021 20:43:57 +0100 Subject: [PATCH 09/14] simple test of deliverynote --- tests/files/devices_deliverynote.csv | 10 ++++++++ tests/test_deliverynote.py | 38 ++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tests/files/devices_deliverynote.csv create mode 100644 tests/test_deliverynote.py diff --git a/tests/files/devices_deliverynote.csv b/tests/files/devices_deliverynote.csv new file mode 100644 index 00000000..2e7de40b --- /dev/null +++ b/tests/files/devices_deliverynote.csv @@ -0,0 +1,10 @@ +Box;;Nº Inventary;Type of device;Sub Type;Brand;Model;serial number +;;N006536;PC;;Acer;Veriton M480G;PSV75EZ0070170002C14j00 +;;N006549;PC ;;Acer;Veriton M480G;PSV75EZ0070170003714j00 +;;N006541;PC ;;Acer;Veriton M480G; +;;N006556;PC;;Acer;Veriton M480G;PSV75EZ0070170001D14j00 +;;N006538;PC;;Acer;Veriton M480G; +;;N007465;PC;;Acer;Veriton M480G;PSV75EZ0070170003A14j00 +;;;PC;;Acer;Veriton M480G;PSV75EZ007017000361800 +;;N006537;PC;;Acer;Veriton M480G;PSV75EZ0070170002214j00 +;;N006530;PC;;Acer;Veriton M480G;PSV75EZ0070170000314j00 diff --git a/tests/test_deliverynote.py b/tests/test_deliverynote.py new file mode 100644 index 00000000..2f4bcb74 --- /dev/null +++ b/tests/test_deliverynote.py @@ -0,0 +1,38 @@ +import os +import ipaddress +import json +import shutil +import copy +import pytest +from datetime import datetime +from dateutil.tz import tzutc +from ereuse_devicehub.client import UserClient +from ereuse_devicehub.devicehub import Devicehub +from ereuse_devicehub.resources.deliverynote.models import Deliverynote +from tests import conftest + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_simple_deliverynote(user: UserClient, app: Devicehub): + """ + This test create only one deliverinote with the expected Devices + """ + inventory = [{'n_inventory': 'N006536', + 'type': 'PC', + 'brand': 'Acer', + 'model': 'Veriton M480G', + 'serial_number': 'PSV75EZ0070170002C14j00' + }] + note = {'date': datetime(2020, 2, 14, 23, 0, tzinfo=tzutc()), + 'documentID': 'DocBBE001', + 'deposit': 0, + 'transfer_state': "Initial", + 'expectedDevices': inventory, + 'supplierEmail': user.user['email']} + + deliverynote, _ = user.post(note, res=Deliverynote) + db_note = Deliverynote.query.filter_by(id=deliverynote['id']).one() + + assert deliverynote['documentID'] == note['documentID'] + assert user.user['email'] in db_note.lot.name From cb3f07eb5afa352e7964d957624b52cb6d5e1dc5 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 5 Feb 2021 13:21:20 +0100 Subject: [PATCH 10/14] change deposit for amount --- .../versions/eca457d8b2a4_change_deliverynote.py | 6 ++++++ ereuse_devicehub/resources/deliverynote/models.py | 6 +++--- ereuse_devicehub/resources/deliverynote/models.pyi | 2 +- ereuse_devicehub/resources/deliverynote/schemas.py | 4 ++-- ereuse_devicehub/resources/device/models.py | 2 +- ereuse_devicehub/resources/device/models.pyi | 2 +- ereuse_devicehub/resources/device/schemas.py | 4 ++-- ereuse_devicehub/resources/lot/models.py | 2 +- ereuse_devicehub/resources/lot/models.pyi | 2 +- ereuse_devicehub/resources/lot/schemas.py | 4 ++-- ereuse_devicehub/resources/lot/views.py | 10 +++++----- tests/test_deliverynote.py | 2 +- tests/test_device.py | 4 ++-- 13 files changed, 28 insertions(+), 22 deletions(-) diff --git a/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py b/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py index f437b0cd..6709ea08 100644 --- a/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py +++ b/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py @@ -27,6 +27,9 @@ def get_inv(): def upgrade(): op.drop_column('deliverynote', 'ethereum_address', schema=f'{get_inv()}') + op.alter_column('deliverynote', 'deposit', new_column_name='amount') + op.alter_column('computer', 'deposit', new_column_name='amount') + op.alter_column('lot', 'deposit', new_column_name='amount') op.drop_column('computer', 'deliverynote_address', schema=f'{get_inv()}') op.drop_column('lot', 'deliverynote_address', schema=f'{get_inv()}') op.drop_table('proof_function', schema=f'{get_inv()}') @@ -41,6 +44,9 @@ def upgrade(): def downgrade(): op.add_column('deliverynote', sa.Column('ethereum_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') + op.alter_column('deliverynote', 'amount', new_column_name='deposit') + op.alter_column('computer', 'amount', new_column_name='deposit') + op.alter_column('lot', 'amount', new_column_name='deposit') op.add_column('computer', sa.Column('deliverynote_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') op.add_column('lot', sa.Column('deliverynote_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') op.create_table('proof', diff --git a/ereuse_devicehub/resources/deliverynote/models.py b/ereuse_devicehub/resources/deliverynote/models.py index 5b56312e..57eefe08 100644 --- a/ereuse_devicehub/resources/deliverynote/models.py +++ b/ereuse_devicehub/resources/deliverynote/models.py @@ -36,7 +36,7 @@ class Deliverynote(Thing): receiver = db.relationship(User, primaryjoin=lambda: Deliverynote.receiver_address == User.email) date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) date.comment = 'The date the DeliveryNote initiated' - deposit = db.Column(db.Integer, check_range('deposit', min=0, max=100), default=0) + amount = db.Column(db.Integer, check_range('amount', min=0, max=100), default=0) # The following fields are supposed to be 0:N relationships # to SnapshotDelivery entity. # At this stage of implementation they will treated as a @@ -54,14 +54,14 @@ class Deliverynote(Thing): lazy=True, primaryjoin=Lot.id == lot_id) - def __init__(self, document_id: str, deposit: str, date, + def __init__(self, document_id: str, amount: str, date, supplier_email: str, expected_devices: Iterable, transfer_state: TransferState) -> None: """Initializes a delivery note """ super().__init__(id=uuid.uuid4(), - document_id=document_id, deposit=deposit, date=date, + document_id=document_id, amount=amount, date=date, supplier_email=supplier_email, expected_devices=expected_devices, transfer_state=transfer_state) diff --git a/ereuse_devicehub/resources/deliverynote/models.pyi b/ereuse_devicehub/resources/deliverynote/models.pyi index d428a7cd..1a5714f9 100644 --- a/ereuse_devicehub/resources/deliverynote/models.pyi +++ b/ereuse_devicehub/resources/deliverynote/models.pyi @@ -24,7 +24,7 @@ class Lot(Thing): description = ... # type: Column all_devices = ... # type: relationship parents = ... # type: relationship - deposit = ... # type: Column + amount = ... # type: Column owner_address = ... # type: Column owner = ... # type: relationship transfer_state = ... # type: Column diff --git a/ereuse_devicehub/resources/deliverynote/schemas.py b/ereuse_devicehub/resources/deliverynote/schemas.py index 60854991..f0dbecdc 100644 --- a/ereuse_devicehub/resources/deliverynote/schemas.py +++ b/ereuse_devicehub/resources/deliverynote/schemas.py @@ -19,8 +19,8 @@ class Deliverynote(Thing): supplier = NestedOn(s_user.User, dump_only=True) receiver = NestedOn(s_user.User, dump_only=True) date = f.DateTime('iso', required=True) - deposit = f.Integer(validate=f.validate.Range(min=0, max=100), - description=m.Deliverynote.deposit.__doc__) + amount = f.Integer(validate=f.validate.Range(min=0, max=100), + description=m.Deliverynote.amount.__doc__) expected_devices = f.List(f.Dict, required=True, data_key='expectedDevices') transferred_devices = f.List(f.Integer(), required=False, data_key='transferredDevices') transfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index da1c0888..d5503d13 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -472,7 +472,7 @@ class Computer(Device): It is a subset of the Linux definition of DMI / DMI decode. """ ethereum_address = Column(CIText(), unique=True, default=None) - deposit = Column(Integer, check_range('deposit', min=0, max=100), default=0) + amount = Column(Integer, check_range('amount', min=0, max=100), default=0) owner_id = db.Column(UUID(as_uuid=True), db.ForeignKey(User.id), nullable=False, diff --git a/ereuse_devicehub/resources/device/models.pyi b/ereuse_devicehub/resources/device/models.pyi index 6b3b8dc4..ba1e2fd8 100644 --- a/ereuse_devicehub/resources/device/models.pyi +++ b/ereuse_devicehub/resources/device/models.pyi @@ -141,7 +141,7 @@ class DisplayMixin: class Computer(DisplayMixin, Device): components = ... # type: Column chassis = ... # type: Column - deposit = ... # type: Column + amount = ... # type: Column owner_address = ... # type: Column transfer_state = ... # type: Column receiver_address = ... # type: Column diff --git a/ereuse_devicehub/resources/device/schemas.py b/ereuse_devicehub/resources/device/schemas.py index 512c11bb..ac2d117d 100644 --- a/ereuse_devicehub/resources/device/schemas.py +++ b/ereuse_devicehub/resources/device/schemas.py @@ -124,8 +124,8 @@ class Computer(Device): collection_class=set, description=m.Computer.privacy.__doc__) ethereum_address = SanitizedStr(validate=f.validate.Length(max=42)) - deposit = Integer(validate=f.validate.Range(min=0, max=100), - description=m.Computer.deposit.__doc__) + amount = Integer(validate=f.validate.Range(min=0, max=100), + description=m.Computer.amount.__doc__) # author_id = NestedOn(s_user.User,only_query='author_id') owner_id = UUID(data_key='ownerID') transfer_state = EnumField(enums.TransferState, description=m.Computer.transfer_state.comment) diff --git a/ereuse_devicehub/resources/lot/models.py b/ereuse_devicehub/resources/lot/models.py index 4be0678b..5022b24e 100644 --- a/ereuse_devicehub/resources/lot/models.py +++ b/ereuse_devicehub/resources/lot/models.py @@ -63,7 +63,7 @@ class Lot(Thing): """All devices, including components, inside this lot and its descendants. """ - deposit = db.Column(db.Integer, check_range('deposit', min=0, max=100), default=0) + amount = db.Column(db.Integer, check_range('amount', min=0, max=100), default=0) owner_id = db.Column(UUID(as_uuid=True), db.ForeignKey(User.id), nullable=False, diff --git a/ereuse_devicehub/resources/lot/models.pyi b/ereuse_devicehub/resources/lot/models.pyi index 0ba97058..f70078c7 100644 --- a/ereuse_devicehub/resources/lot/models.pyi +++ b/ereuse_devicehub/resources/lot/models.pyi @@ -24,7 +24,7 @@ class Lot(Thing): description = ... # type: Column all_devices = ... # type: relationship parents = ... # type: relationship - deposit = ... # type: Column + amount = ... # type: Column owner_address = ... # type: Column owner = ... # type: relationship transfer_state = ... # type: Column diff --git a/ereuse_devicehub/resources/lot/schemas.py b/ereuse_devicehub/resources/lot/schemas.py index c30f3890..72e49efe 100644 --- a/ereuse_devicehub/resources/lot/schemas.py +++ b/ereuse_devicehub/resources/lot/schemas.py @@ -19,8 +19,8 @@ class Lot(Thing): children = NestedOn('Lot', many=True, dump_only=True) parents = NestedOn('Lot', many=True, dump_only=True) url = URL(dump_only=True, description=m.Lot.url.__doc__) - deposit = f.Integer(validate=f.validate.Range(min=0, max=100), - description=m.Lot.deposit.__doc__) + amount = f.Integer(validate=f.validate.Range(min=0, max=100), + description=m.Lot.amount.__doc__) # author_id = NestedOn(s_user.User,only_query='author_id') owner_id = f.UUID(data_key='ownerID') transfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment) diff --git a/ereuse_devicehub/resources/lot/views.py b/ereuse_devicehub/resources/lot/views.py index d2b827e5..e9395ff5 100644 --- a/ereuse_devicehub/resources/lot/views.py +++ b/ereuse_devicehub/resources/lot/views.py @@ -41,11 +41,11 @@ class LotView(View): def patch(self, id): patch_schema = self.resource_def.SCHEMA(only=( - 'name', 'description', 'transfer_state', 'receiver_address', 'deposit', 'devices', + 'name', 'description', 'transfer_state', 'receiver_address', 'amount', 'devices', 'owner_address'), partial=True) l = request.get_json(schema=patch_schema) lot = Lot.query.filter_by(id=id).one() - device_fields = ['transfer_state', 'receiver_address', 'deposit', 'owner_address'] + device_fields = ['transfer_state', 'receiver_address', 'amount', 'owner_address'] computers = [x for x in lot.all_devices if isinstance(x, Computer)] for key, value in l.items(): setattr(lot, key, value) @@ -142,9 +142,9 @@ class LotView(View): if path: cls._p(node['nodes'], path) - def get_lot_deposit(self, l: Lot): - """Return lot deposit value""" - return l.deposit + def get_lot_amount(self, l: Lot): + """Return lot amount value""" + return l.amount def change_state(self): """Change state of Lot""" diff --git a/tests/test_deliverynote.py b/tests/test_deliverynote.py index 2f4bcb74..9940e14f 100644 --- a/tests/test_deliverynote.py +++ b/tests/test_deliverynote.py @@ -26,7 +26,7 @@ def test_simple_deliverynote(user: UserClient, app: Devicehub): }] note = {'date': datetime(2020, 2, 14, 23, 0, tzinfo=tzutc()), 'documentID': 'DocBBE001', - 'deposit': 0, + 'amount': 0, 'transfer_state': "Initial", 'expectedDevices': inventory, 'supplierEmail': user.user['email']} diff --git a/tests/test_device.py b/tests/test_device.py index e7810542..fa6de215 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -125,7 +125,7 @@ def test_physical_properties(): } assert pc.physical_properties == { 'chassis': ComputerChassis.Tower, - 'deposit': 0, + 'amount': 0, 'ethereum_address': None, 'manufacturer': 'bar', 'model': 'foo', @@ -251,7 +251,7 @@ def test_sync_execute_register_desktop_existing_no_tag(): **conftest.file('pc-components.db')['device']) # Create a new transient non-db object # 1: device exists on DB db_pc = Sync().execute_register(pc) - pc.deposit = 0 + pc.amount = 0 pc.owner_id = db_pc.owner_id pc.transfer_state = TransferState.Initial assert pc.physical_properties == db_pc.physical_properties From 6b7571fe8609edc50dd3605c7aeb0e2eb4f27c82 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 5 Feb 2021 15:35:52 +0100 Subject: [PATCH 11/14] change deposit for amount --- CHANGELOG.md | 2 ++ .../versions/eca457d8b2a4_change_deliverynote.py | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93602dea..81e3870f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ ml). - [addend] #102 adding endpoint for download metrics - [bugfix] #100 fixing bug of scheme live - [bugfix] #101 fixing bug when 2 users have one device and launch one live +- [changes] #114 clean blockchein of deliverynote +- [remove] #114 remove proof system ## [1.0.3-beta] - [addend] #85 add mac of network adapter to device hid diff --git a/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py b/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py index 6709ea08..24f4a161 100644 --- a/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py +++ b/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py @@ -27,9 +27,9 @@ def get_inv(): def upgrade(): op.drop_column('deliverynote', 'ethereum_address', schema=f'{get_inv()}') - op.alter_column('deliverynote', 'deposit', new_column_name='amount') - op.alter_column('computer', 'deposit', new_column_name='amount') - op.alter_column('lot', 'deposit', new_column_name='amount') + op.alter_column('deliverynote', 'deposit', new_column_name='amount', schema=f'{get_inv()}') + op.alter_column('computer', 'deposit', new_column_name='amount', schema=f'{get_inv()}') + op.alter_column('lot', 'deposit', new_column_name='amount', schema=f'{get_inv()}') op.drop_column('computer', 'deliverynote_address', schema=f'{get_inv()}') op.drop_column('lot', 'deliverynote_address', schema=f'{get_inv()}') op.drop_table('proof_function', schema=f'{get_inv()}') @@ -44,9 +44,9 @@ def upgrade(): def downgrade(): op.add_column('deliverynote', sa.Column('ethereum_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') - op.alter_column('deliverynote', 'amount', new_column_name='deposit') - op.alter_column('computer', 'amount', new_column_name='deposit') - op.alter_column('lot', 'amount', new_column_name='deposit') + op.alter_column('deliverynote', 'amount', new_column_name='deposit', schema=f'{get_inv()}') + op.alter_column('computer', 'amount', new_column_name='deposit', schema=f'{get_inv()}') + op.alter_column('lot', 'amount', new_column_name='deposit', schema=f'{get_inv()}') op.add_column('computer', sa.Column('deliverynote_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') op.add_column('lot', sa.Column('deliverynote_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') op.create_table('proof', From 72466003d0b61fdd4458e7763358bc047bd511b2 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 10 Feb 2021 13:05:43 +0100 Subject: [PATCH 12/14] drop all ethereum_address in the system --- ereuse_devicehub/dummy/dummy.py | 4 ++-- .../eca457d8b2a4_change_deliverynote.py | 21 +++++++++++++++++-- .../resources/deliverynote/views.py | 7 ------- ereuse_devicehub/resources/device/models.py | 1 - ereuse_devicehub/resources/device/models.pyi | 2 +- ereuse_devicehub/resources/device/schemas.py | 1 - ereuse_devicehub/resources/device/views.py | 2 +- ereuse_devicehub/resources/lot/models.py | 7 ++++--- ereuse_devicehub/resources/user/models.py | 10 ++------- ereuse_devicehub/resources/user/models.pyi | 2 -- ereuse_devicehub/resources/user/schemas.py | 1 - ereuse_devicehub/resources/user/views.py | 2 +- 12 files changed, 30 insertions(+), 30 deletions(-) diff --git a/ereuse_devicehub/dummy/dummy.py b/ereuse_devicehub/dummy/dummy.py index ed402141..162ccf56 100644 --- a/ereuse_devicehub/dummy/dummy.py +++ b/ereuse_devicehub/dummy/dummy.py @@ -188,8 +188,8 @@ class Dummy: # For netbook: to preapre -> torepair -> to dispose -> disposed print('⭐ Done.') - def user_client(self, email: str, password: str, name: str, ethereum_address: str): - user = User(email=email, password=password, ethereum_address=ethereum_address) + def user_client(self, email: str, password: str, name: str: + user = User(email=email, password=password) user.individuals.add(Person(name=name)) db.session.add(user) diff --git a/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py b/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py index 24f4a161..e8bcc663 100644 --- a/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py +++ b/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py @@ -31,7 +31,14 @@ def upgrade(): op.alter_column('computer', 'deposit', new_column_name='amount', schema=f'{get_inv()}') op.alter_column('lot', 'deposit', new_column_name='amount', schema=f'{get_inv()}') op.drop_column('computer', 'deliverynote_address', schema=f'{get_inv()}') + op.drop_column('computer', 'ethereum_address', schema=f'{get_inv()}') + op.drop_column('user', 'ethereum_address', schema='common') op.drop_column('lot', 'deliverynote_address', schema=f'{get_inv()}') + + op.drop_column('lot', 'receiver_address', schema=f'{get_inv()}') + op.add_column('lot', sa.Column('receiver_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') + op.add_column('lot', sa.ForeignKeyConstraint(['receiver_address'], ['common.user.email'],), schema=f'{get_inv()}') + op.drop_table('proof_function', schema=f'{get_inv()}') op.drop_table('proof_data_wipe', schema=f'{get_inv()}') op.drop_table('proof_transfer', schema=f'{get_inv()}') @@ -45,10 +52,20 @@ def upgrade(): def downgrade(): op.add_column('deliverynote', sa.Column('ethereum_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') op.alter_column('deliverynote', 'amount', new_column_name='deposit', schema=f'{get_inv()}') - op.alter_column('computer', 'amount', new_column_name='deposit', schema=f'{get_inv()}') - op.alter_column('lot', 'amount', new_column_name='deposit', schema=f'{get_inv()}') op.add_column('computer', sa.Column('deliverynote_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') op.add_column('lot', sa.Column('deliverynote_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') + + # ===== + op.alter_column('computer', 'amount', new_column_name='deposit', schema=f'{get_inv()}') + op.alter_column('lot', 'amount', new_column_name='deposit', schema=f'{get_inv()}') + + # ===== + op.add_column('computer', sa.Column('ethereum_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') + op.add_column('user', sa.Column('ethereum_address', citext.CIText(), nullable=True), schema='common') + op.add_column('lot', sa.Column('receiver_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') + op.add_column('lot', sa.ForeignKeyConstraint(['receiver_address'], ['common.user.ethereum_address'],), schema=f'{get_inv()}') + + # ===== op.create_table('proof', sa.Column('updated', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, diff --git a/ereuse_devicehub/resources/deliverynote/views.py b/ereuse_devicehub/resources/deliverynote/views.py index 321f7ad9..15ceaa4b 100644 --- a/ereuse_devicehub/resources/deliverynote/views.py +++ b/ereuse_devicehub/resources/deliverynote/views.py @@ -35,13 +35,6 @@ class DeliverynoteView(View): # computers = [x for x in dlvnote.transferred_devices if isinstance(x, Computer)] for key, value in d.items(): setattr(dlvnote, key, value) - # Transalate ethereum_address attribute - # devKey = key - # if key == 'ethereum_address': - # devKey = 'deliverynote_address' - # if devKey in device_fields: - # for dev in computers: - # setattr(dev, devKey, value) db.session.commit() return Response(status=204) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index d5503d13..a9efc105 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -471,7 +471,6 @@ class Computer(Device): It is a subset of the Linux definition of DMI / DMI decode. """ - ethereum_address = Column(CIText(), unique=True, default=None) amount = Column(Integer, check_range('amount', min=0, max=100), default=0) owner_id = db.Column(UUID(as_uuid=True), db.ForeignKey(User.id), diff --git a/ereuse_devicehub/resources/device/models.pyi b/ereuse_devicehub/resources/device/models.pyi index ba1e2fd8..837a737f 100644 --- a/ereuse_devicehub/resources/device/models.pyi +++ b/ereuse_devicehub/resources/device/models.pyi @@ -144,7 +144,7 @@ class Computer(DisplayMixin, Device): amount = ... # type: Column owner_address = ... # type: Column transfer_state = ... # type: Column - receiver_address = ... # type: Column + receiver_id = ... # uuid: Column def __init__(self, **kwargs) -> None: super().__init__(**kwargs) diff --git a/ereuse_devicehub/resources/device/schemas.py b/ereuse_devicehub/resources/device/schemas.py index ac2d117d..706b7e03 100644 --- a/ereuse_devicehub/resources/device/schemas.py +++ b/ereuse_devicehub/resources/device/schemas.py @@ -123,7 +123,6 @@ class Computer(Device): dump_only=True, collection_class=set, description=m.Computer.privacy.__doc__) - ethereum_address = SanitizedStr(validate=f.validate.Length(max=42)) amount = Integer(validate=f.validate.Range(min=0, max=100), description=m.Computer.amount.__doc__) # author_id = NestedOn(s_user.User,only_query='author_id') diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index 83e16de7..3dde5e3b 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -106,7 +106,7 @@ class DeviceView(View): resource_def = app.resources['Computer'] # TODO check how to handle the 'actions_one' patch_schema = resource_def.SCHEMA( - only=['ethereum_address', 'transfer_state', 'actions_one'], partial=True) + only=['transfer_state', 'actions_one'], partial=True) json = request.get_json(schema=patch_schema) # TODO check how to handle the 'actions_one' json.pop('actions_one') diff --git a/ereuse_devicehub/resources/lot/models.py b/ereuse_devicehub/resources/lot/models.py index 5022b24e..f8a9066b 100644 --- a/ereuse_devicehub/resources/lot/models.py +++ b/ereuse_devicehub/resources/lot/models.py @@ -72,9 +72,10 @@ class Lot(Thing): transfer_state = db.Column(IntEnum(TransferState), default=TransferState.Initial, nullable=False) transfer_state.comment = TransferState.__doc__ receiver_address = db.Column(CIText(), - db.ForeignKey(User.ethereum_address), - nullable=True) - receiver = db.relationship(User, primaryjoin=receiver_address == User.ethereum_address) + db.ForeignKey(User.email), + nullable=False, + default=lambda: g.user.email) + receiver = db.relationship(User, primaryjoin=receiver_address == User.email) def __init__(self, name: str, closed: bool = closed.default.arg, description: str = None) -> None: diff --git a/ereuse_devicehub/resources/user/models.py b/ereuse_devicehub/resources/user/models.py index 98a25598..0ab670c8 100644 --- a/ereuse_devicehub/resources/user/models.py +++ b/ereuse_devicehub/resources/user/models.py @@ -25,11 +25,10 @@ class User(Thing): backref=db.backref('users', lazy=True, collection_class=set), secondary=lambda: UserInventory.__table__, collection_class=set) - ethereum_address = Column(CIText(), unique=True, default=None) # todo set restriction that user has, at least, one active db - def __init__(self, email, password=None, ethereum_address=None, inventories=None) -> None: + def __init__(self, email, password=None, inventories=None) -> None: """Creates an user. :param email: :param password: @@ -38,7 +37,7 @@ class User(Thing): inventory. """ inventories = inventories or {Inventory.current} - super().__init__(email=email, password=password, ethereum_address=ethereum_address, inventories=inventories) + super().__init__(email=email, password=password, inventories=inventories) def __repr__(self) -> str: return ''.format(self) @@ -52,11 +51,6 @@ class User(Thing): """The individual associated for this database, or None.""" return next(iter(self.individuals), None) - @property - def get_ethereum_address(self): - """The ethereum address in Blockchain, or None.""" - return next(iter(self.ethereum_address), None) - class UserInventory(db.Model): """Relationship between users and their inventories.""" diff --git a/ereuse_devicehub/resources/user/models.pyi b/ereuse_devicehub/resources/user/models.pyi index 15874464..6e8d03b9 100644 --- a/ereuse_devicehub/resources/user/models.pyi +++ b/ereuse_devicehub/resources/user/models.pyi @@ -17,7 +17,6 @@ class User(Thing): password = ... # type: Column token = ... # type: Column inventories = ... # type: relationship - ethereum_address = ... # type: Column def __init__(self, email: str, password: str = None, inventories: Set[Inventory] = None) -> None: @@ -28,7 +27,6 @@ class User(Thing): self.individuals = ... # type: Set[Individual] self.token = ... # type: UUID self.inventories = ... # type: Set[Inventory] - self.ethereum_address = ... # type: str @property def individual(self) -> Union[Individual, None]: diff --git a/ereuse_devicehub/resources/user/schemas.py b/ereuse_devicehub/resources/user/schemas.py index 00d022ad..e8d0d768 100644 --- a/ereuse_devicehub/resources/user/schemas.py +++ b/ereuse_devicehub/resources/user/schemas.py @@ -19,7 +19,6 @@ class User(Thing): description='Use this token in an Authorization header to access the app.' 'The token can change overtime.') inventories = NestedOn(Inventory, many=True, dump_only=True) - ethereum_address = String(description='User identifier address inside the Blockchain') def __init__(self, only=None, diff --git a/ereuse_devicehub/resources/user/views.py b/ereuse_devicehub/resources/user/views.py index 19624b80..7053eea7 100644 --- a/ereuse_devicehub/resources/user/views.py +++ b/ereuse_devicehub/resources/user/views.py @@ -15,7 +15,7 @@ class UserView(View): def login(): # We use custom schema as we only want to parse a subset of user - user_s = g.resource_def.SCHEMA(only=('email', 'password', 'ethereum_address')) # type: UserS + user_s = g.resource_def.SCHEMA(only=('email', 'password')) # type: UserS # noinspection PyArgumentList u = request.get_json(schema=user_s) user = User.query.filter_by(email=u['email']).one_or_none() From afa4f9ce456564a5d0391bb586a88f9e87ac1967 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 10 Feb 2021 13:40:24 +0100 Subject: [PATCH 13/14] fixing tests --- CHANGELOG.md | 2 +- ereuse_devicehub/dummy/dummy.py | 10 +++++----- tests/test_device.py | 1 - 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81e3870f..2e3c4d45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ ml). - [addend] #102 adding endpoint for download metrics - [bugfix] #100 fixing bug of scheme live - [bugfix] #101 fixing bug when 2 users have one device and launch one live -- [changes] #114 clean blockchein of deliverynote +- [changes] #114 clean blockchain of all models - [remove] #114 remove proof system ## [1.0.3-beta] diff --git a/ereuse_devicehub/dummy/dummy.py b/ereuse_devicehub/dummy/dummy.py index 162ccf56..376ccd1b 100644 --- a/ereuse_devicehub/dummy/dummy.py +++ b/ereuse_devicehub/dummy/dummy.py @@ -65,10 +65,10 @@ class Dummy: with click_spinner.spinner(): out = runner.invoke('org', 'add', *self.ORG).output org_id = json.loads(out)['id'] - user1 = self.user_client('user@dhub.com', '1234', 'user1', '0xC79F7fE80B5676fe38D8187b79d55F7A61e702b2') - user2 = self.user_client('user2@dhub.com', '1234', 'user2', '0x56EbFdbAA98f52027A9776456e4fcD5d91090818') - user3 = self.user_client('user3@dhub.com', '1234', 'user3', '0xF88618956696aB7e56Cb7bc87d9848E921C4FDaA') - user4 = self.user_client('user4@dhub.com', '1234', 'user4', '0x37be35ae7eced44ca25e4683e98425fc7830a8a5') + user1 = self.user_client('user@dhub.com', '1234', 'user1') + user2 = self.user_client('user2@dhub.com', '1234', 'user2') + user3 = self.user_client('user3@dhub.com', '1234', 'user3') + user4 = self.user_client('user4@dhub.com', '1234', 'user4') # todo put user's agent into Org for id in self.TAGS: @@ -188,7 +188,7 @@ class Dummy: # For netbook: to preapre -> torepair -> to dispose -> disposed print('⭐ Done.') - def user_client(self, email: str, password: str, name: str: + def user_client(self, email: str, password: str, name: str): user = User(email=email, password=password) user.individuals.add(Person(name=name)) diff --git a/tests/test_device.py b/tests/test_device.py index fa6de215..851698fb 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -126,7 +126,6 @@ def test_physical_properties(): assert pc.physical_properties == { 'chassis': ComputerChassis.Tower, 'amount': 0, - 'ethereum_address': None, 'manufacturer': 'bar', 'model': 'foo', 'receiver_id': None, From deff20afaee6a16786ad6ddca9e2cec9849e915d Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 11 Feb 2021 12:51:50 +0100 Subject: [PATCH 14/14] fixing migrations --- .../eca457d8b2a4_change_deliverynote.py | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py b/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py index e8bcc663..0ce69c20 100644 --- a/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py +++ b/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py @@ -30,14 +30,16 @@ def upgrade(): op.alter_column('deliverynote', 'deposit', new_column_name='amount', schema=f'{get_inv()}') op.alter_column('computer', 'deposit', new_column_name='amount', schema=f'{get_inv()}') op.alter_column('lot', 'deposit', new_column_name='amount', schema=f'{get_inv()}') + op.drop_column('lot', 'deliverynote_address', schema=f'{get_inv()}') op.drop_column('computer', 'deliverynote_address', schema=f'{get_inv()}') op.drop_column('computer', 'ethereum_address', schema=f'{get_inv()}') - op.drop_column('user', 'ethereum_address', schema='common') - op.drop_column('lot', 'deliverynote_address', schema=f'{get_inv()}') - op.drop_column('lot', 'receiver_address', schema=f'{get_inv()}') - op.add_column('lot', sa.Column('receiver_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') - op.add_column('lot', sa.ForeignKeyConstraint(['receiver_address'], ['common.user.email'],), schema=f'{get_inv()}') + op.add_column('lot', sa.Column('receiver_address', citext.CIText(), + sa.ForeignKey('common.user.email'), nullable=True), + schema=f'{get_inv()}') + + op.drop_column('user', 'ethereum_address', schema='common') + op.drop_table('proof_function', schema=f'{get_inv()}') op.drop_table('proof_data_wipe', schema=f'{get_inv()}') @@ -61,9 +63,13 @@ def downgrade(): # ===== op.add_column('computer', sa.Column('ethereum_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') - op.add_column('user', sa.Column('ethereum_address', citext.CIText(), nullable=True), schema='common') - op.add_column('lot', sa.Column('receiver_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') - op.add_column('lot', sa.ForeignKeyConstraint(['receiver_address'], ['common.user.ethereum_address'],), schema=f'{get_inv()}') + op.add_column('user', sa.Column('ethereum_address', citext.CIText(), unique=True, nullable=True), schema='common') + + + op.drop_column('lot', 'receiver_address', schema=f'{get_inv()}') + op.add_column('lot', sa.Column('receiver_address', citext.CIText(), + sa.ForeignKey('common.user.ethereum_address'), nullable=True), + schema=f'{get_inv()}') # ===== op.create_table('proof',