Merge pull request #101 from eReuse/bugfix/live-two-users

fixing bug of 2 users with the same device and launch one live
This commit is contained in:
cayop 2021-01-08 11:01:21 +01:00 committed by GitHub
commit 87bb2265ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 77 additions and 44 deletions

View File

@ -15,6 +15,8 @@ ml).
- [addend] #95 adding endpoint for check the hash of one report
- [addend] #98 adding endpoint for insert a new live
- [addend] #98 adding endpoint for get all licences in one query
- [bugfix] #100 fixing bug of scheme live
- [bugfix] #101 fixing bug when 2 users have one device and launch one live
## [1.0.3-beta]
- [addend] #85 add mac of network adapter to device hid

View File

@ -170,7 +170,7 @@ class LiveView(View):
raise ValidationError('Device not exist.')
device = Device.query.filter(
Device.hid==hid).one()
Device.hid==hid, Device.allocated==True).one()
# Is not necessary
if not device:
raise ValidationError('Device not exist.')

View File

@ -1,38 +1,11 @@
[
{
"WorkbenchDesktopVersion": "v.1",
"USOdyPrivacyPolicyVersion": "v.1",
"Language": "CAT",
"Description": "Recollim informació bàsica bla bla bla"
},
{
"WorkbenchesktopVersion": "v.1",
"USOdyPrivacyPolicyVersion": "v.2",
"Language": "CAT",
"Description": "Recollim informació bàsica bla bla bla i a partir de tal data les dades dhores dús les usem també per estimar la durabilitat"
},
{
"WorkbenchDesktopVersion": "v.1.1",
"USOdyPrivacyPolicyVersion": "v.3",
"Language": "CAT",
"Description": "Recollim informació bàsica bla bla bla pero ara també recollim la versió del sistema operatiu"
},
{
"WorkbenchDesktopVersion": "v.1",
"USOdyPrivacyPolicyVersion": "v.1",
"Language": "EN",
"Description": "We collect basic information blah blah blah"
},
{
"WorkbenchDesktopVersion": "v.1",
"USOdyPrivacyPolicyVersion": "v.2",
"Language": "EN",
"Description": "We collect basic information blah blah blah and from that date we also use the usage time data to estimate durability"
},
{
"WorkbenchDesktopVersion": "v.1.1",
"USOdyPrivacyPolicyVersion": "v.3",
"Language": "EN",
"Description": "We collect basic information blah blah blah but now we also collect the operating system version"
}
]
[
{"WorkbenchDesktopVersion": "1.0.0", "USOdyPrivacyPolicyVersion": "1.0.0", "Language": "CAT", "Description": "Recollim informació bàsica bla bla bla"},
{"WorkbenchDesktopVersion": "1.0.0", "USOdyPrivacyPolicyVersion": "2.0.0", "Language": "CAT", "Description": "Recollim informació bàsica bla bla bla i a partir de tal data les dades d'hores d'ús les usem també per estimar la durabilitat"},
{"WorkbenchDesktopVersion": "1.1.0", "USOdyPrivacyPolicyVersion": "3.0.0", "Language": "CAT", "Description": "Recollim informació bàsica bla bla bla pero ara també recollim la versió del sistema operatiu"},
{"WorkbenchDesktopVersion": "1.0.0", "USOdyPrivacyPolicyVersion": "1.0.0", "Language": "ESP", "Description": "Recogemos información básica bla bla bla"},
{"WorkbenchDesktopVersion": "1.0.0", "USOdyPrivacyPolicyVersion": "2.0.0", "Language": "ESP", "Description": "Recogemos información básica bla bla bla y a partir de cierta fecha los datos de horas de uso los usamos para estimar la durabilidad "},
{"WorkbenchDesktopVersion": "1.1.0", "USOdyPrivacyPolicyVersion": "3.0.0", "Language": "ESP", "Description": "Recogemos información básica bla bla bla pero ahora también recogemos la versión del sistema operativo"},
{"WorkbenchDesktopVersion": "1.0.0", "USOdyPrivacyPolicyVersion": "1.0.0", "Language": "ENG", "Description": "We collect basic information blah blah blah"},
{"WorkbenchDesktopVersion": "1.0.0", "USOdyPrivacyPolicyVersion": "2.0.0", "Language": "ENG", "Description": "We collect basic information blah blah blah and from that date we also use the usage time data to estimate durability"},
{"WorkbenchDesktopVersion": "1.1.0", "USOdyPrivacyPolicyVersion": "3.0.0", "Language": "ENG", "Description": "We collect basic information blah blah blah but now we also collect the operating system version"}
]

View File

@ -256,7 +256,6 @@ def test_live(user: UserClient, client: Client, app: Devicehub):
acer = file('acer.happy.battery.snapshot')
snapshot, _ = user.post(acer, res=models.Snapshot)
device_id = snapshot['device']['id']
db_device = Device.query.filter_by(id=1).one()
post_request = {"transaction": "ccc", "name": "John", "endUsers": 1,
"devices": [device_id], "description": "aaa",
"finalUserCode": "abcdefjhi",
@ -271,7 +270,7 @@ def test_live(user: UserClient, client: Client, app: Devicehub):
acer.pop('elapsed')
acer['licence_version'] = '1.0.0'
snapshot, _ = client.post(acer, res=models.Live)
db_device = Device.query.filter_by(id=1).one()
db_device = Device.query.filter_by(id=device_id).one()
action_live = [a for a in db_device.actions if a.type == 'Live']
assert len(action_live) == 1
assert action_live[0].usage_time_hdd == timedelta(hours=hdd_action['lifetime'])
@ -289,7 +288,6 @@ def test_live_example(user: UserClient, client: Client, app: Devicehub):
acer = file('snapshotLive')
snapshot, _ = user.post(acer, res=models.Snapshot)
device_id = snapshot['device']['id']
db_device = Device.query.filter_by(id=1).one()
post_request = {"transaction": "ccc", "name": "John", "endUsers": 1,
"devices": [device_id], "description": "aaa",
"finalUserCode": "abcdefjhi",
@ -301,12 +299,72 @@ def test_live_example(user: UserClient, client: Client, app: Devicehub):
acer = file('live')
live, _ = client.post(acer, res=models.Live)
db_device = Device.query.filter_by(id=1).one()
db_device = Device.query.filter_by(id=device_id).one()
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']
@pytest.mark.mvp
@pytest.mark.usefixtures(conftest.app_context.__name__)
def test_live_two_users(user: UserClient, user2: UserClient, client: Client, app: Devicehub):
"""Tests inserting a Live into the database and GETting it."""
acer = file('snapshotLive')
snapshot, _ = user.post(acer, res=models.Snapshot)
acer2 = file('snapshotLive')
acer2['uuid'] = '3b6a9288-0ba6-4bdd-862a-2b1f660e7115'
snapshot2, _ = user2.post(acer2, res=models.Snapshot)
device_id = snapshot['device']['id']
post_request = {"transaction": "ccc", "name": "John", "endUsers": 1,
"devices": [device_id], "description": "aaa",
"finalUserCode": "abcdefjhi",
"startTime": "2020-11-01T02:00:00+00:00",
"endTime": "2020-12-01T02:00:00+00:00"
}
user.post(res=models.Allocate, data=post_request)
acer = file('live')
live, _ = client.post(acer, res=models.Live)
db_device = Device.query.filter_by(id=device_id).one()
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']
@pytest.mark.mvp
@pytest.mark.usefixtures(conftest.app_context.__name__)
def test_live_two_allocated(user: UserClient, user2: UserClient, client: Client, app: Devicehub):
"""Tests inserting a Live into the database and GETting it."""
acer = file('snapshotLive')
snapshot, _ = user.post(acer, res=models.Snapshot)
acer2 = file('snapshotLive')
acer2['uuid'] = '3b6a9288-0ba6-4bdd-862a-2b1f660e7115'
snapshot2, _ = user2.post(acer2, res=models.Snapshot)
device_id = snapshot['device']['id']
device_id2 = snapshot2['device']['id']
post_request = {"transaction": "ccc", "name": "John", "endUsers": 1,
"devices": [device_id], "description": "aaa",
"finalUserCode": "abcdefjhi",
"startTime": "2020-11-01T02:00:00+00:00",
"endTime": "2020-12-01T02:00:00+00:00"
}
post_request2 = {"transaction": "ccc", "name": "John", "endUsers": 1,
"devices": [device_id2], "description": "aaa",
"finalUserCode": "abcdefjhi",
"startTime": "2020-11-01T02:00:00+00:00",
"endTime": "2020-12-01T02:00:00+00:00"
}
user.post(res=models.Allocate, data=post_request)
user2.post(res=models.Allocate, data=post_request2)
acer = file('live')
live, _ = client.post(acer, res=models.Live, status=422)
message = 'Expected only one Device but multiple where found'
assert live['message'] == message
@pytest.mark.mvp
@pytest.mark.usefixtures(conftest.app_context.__name__)
def test_live_without_TestDataStorage(user: UserClient, client: Client, app: Devicehub):
@ -538,7 +596,7 @@ def test_licences(client: Client):
"""
licences, _ = client.get('/licences/')
licences = json.loads(licences)
assert licences[0]['USOdyPrivacyPolicyVersion'] == 'v.1'
assert licences[0]['USOdyPrivacyPolicyVersion'] == '1.0.0'
@pytest.mark.mvp