From 92c403579bd4f31b28f4e30cf953f77672c89578 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 1 Dec 2020 15:33:49 +0100 Subject: [PATCH] ading finalUserCode to allocate action --- .../versions/e93aec8fc41f_added_assigned_action.py | 2 ++ ereuse_devicehub/resources/action/models.py | 3 +++ ereuse_devicehub/resources/action/schemas.py | 5 +++++ tests/test_action.py | 3 +++ tests/test_metrics.py | 3 +++ 5 files changed, 16 insertions(+) diff --git a/ereuse_devicehub/migrations/versions/e93aec8fc41f_added_assigned_action.py b/ereuse_devicehub/migrations/versions/e93aec8fc41f_added_assigned_action.py index 690967e4..0d65cf9d 100644 --- a/ereuse_devicehub/migrations/versions/e93aec8fc41f_added_assigned_action.py +++ b/ereuse_devicehub/migrations/versions/e93aec8fc41f_added_assigned_action.py @@ -30,6 +30,8 @@ def upgrade(): # Allocate action op.drop_table('allocate', schema=f'{get_inv()}') op.create_table('allocate', + sa.Column('final_user_code', citext.CIText(), default='', nullable=True, + comment = "This is a internal code for mainteing the secrets of the personal datas of the new holder") sa.Column('transaction', citext.CIText(), nullable=True, comment='The code used from the owner for relation with external tool.'), sa.Column('end_users', sa.Numeric(precision=4), nullable=True), sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index ad05efca..fadc23ad 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -313,6 +313,9 @@ class Remove(ActionWithOneDevice): class Allocate(JoinedTableMixin, ActionWithMultipleDevices): """The act of allocate one list of devices to one person """ + final_user_code = Column(CIText(), default='', nullable=True) + final_user_code.comment = """This is a internal code for mainteing the secrets of the + personal datas of the new holder""" transaction = Column(CIText(), default='', nullable=True) transaction.comment = "The code used from the owner for relation with external tool." end_users = Column(Numeric(precision=4), check_range('end_users', 0), nullable=True) diff --git a/ereuse_devicehub/resources/action/schemas.py b/ereuse_devicehub/resources/action/schemas.py index 4c72a456..e32112ca 100644 --- a/ereuse_devicehub/resources/action/schemas.py +++ b/ereuse_devicehub/resources/action/schemas.py @@ -71,6 +71,11 @@ class Allocate(ActionWithMultipleDevices): description=m.Action.start_time.comment) end_time = DateTime(data_key='endTime', required=False, description=m.Action.end_time.comment) + final_user_code = SanitizedStr(data_key="finalUserCode" + validate=Length(min=1, max=STR_BIG_SIZE), + required=False, + description='This is a internal code for mainteing the secrets of the \ + personal datas of the new holder') transaction = SanitizedStr(validate=Length(min=1, max=STR_BIG_SIZE), required=False, description='The code used from the owner for \ diff --git a/tests/test_action.py b/tests/test_action.py index 5e4e014d..79cfa89c 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -279,6 +279,7 @@ def test_allocate(user: UserClient): snapshot, _ = user.post(file('basic.snapshot'), res=models.Snapshot) device_id = snapshot['device']['id'] post_request = {"transaction": "ccc", + "finalUserCode": "aabbcc", "name": "John", "severity": "Info", "endUsers": 1, @@ -294,6 +295,7 @@ def test_allocate(user: UserClient): assert device['allocated'] == True action = [a for a in device['actions'] if a['type'] == 'Allocate'][0] assert action['transaction'] == allocate['transaction'] + assert action['finalUserCode'] == allocate['finalUserCode'] assert action['created'] == allocate['created'] assert action['startTime'] == allocate['startTime'] assert action['endUsers'] == allocate['endUsers'] @@ -322,6 +324,7 @@ def test_allocate_bad_dates(user: UserClient): delta = timedelta(days=30) future = datetime.now() + delta post_request = {"transaction": "ccc", + "finalUserCode": "aabbcc", "name": "John", "severity": "Info", "end_users": 1, diff --git a/tests/test_metrics.py b/tests/test_metrics.py index c053235f..238b6132 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -17,6 +17,7 @@ def test_simple_metrics(user: UserClient): snapshot, _ = user.post(acer, res=ma.Snapshot) device_id = snapshot['device']['id'] post_request = {"transaction": "ccc", "name": "John", "endUsers": 1, + "finalUserCode": "abcdefjhi", "devices": [device_id], "description": "aaa", "startTime": "2020-11-01T02:00:00+00:00", "endTime": "2020-12-01T02:00:00+00:00" @@ -59,6 +60,7 @@ def test_second_hdd_metrics(user: UserClient): snapshot, _ = user.post(acer, res=ma.Snapshot) device_id = snapshot['device']['id'] post_request = {"transaction": "ccc", "name": "John", "endUsers": 1, + "finalUserCode": "abcdefjhi", "devices": [device_id], "description": "aaa", "startTime": "2020-11-01T02:00:00+00:00", "endTime": "2020-12-01T02:00:00+00:00" @@ -100,6 +102,7 @@ def test_metrics_with_live_null(user: UserClient): snapshot, _ = user.post(acer, res=ma.Snapshot) device_id = snapshot['device']['id'] post_request = {"transaction": "ccc", "name": "John", "endUsers": 1, + "finalUserCode": "abcdefjhi", "devices": [device_id], "description": "aaa", "startTime": "2020-11-01T02:00:00+00:00", "endTime": "2020-12-01T02:00:00+00:00"