fixed test for check with owners
This commit is contained in:
parent
3eecdb4a1e
commit
bc923d5576
|
@ -137,6 +137,7 @@ def test_physical_properties():
|
|||
@pytest.mark.mvp
|
||||
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
|
||||
def test_component_similar_one():
|
||||
user = User.query.filter().first()
|
||||
snapshot = conftest.file('pc-components.db')
|
||||
pc = snapshot['device']
|
||||
snapshot['components'][0]['serial_number'] = snapshot['components'][1]['serial_number'] = None
|
||||
|
@ -145,7 +146,8 @@ def test_component_similar_one():
|
|||
db.session.add(pc)
|
||||
db.session.flush()
|
||||
# Let's create a new component named 'A' similar to 1
|
||||
componentA = d.Component(model=component1.model, manufacturer=component1.manufacturer)
|
||||
componentA = d.Component(model=component1.model, manufacturer=component1.manufacturer,
|
||||
owner_id=user.id)
|
||||
similar_to_a = componentA.similar_one(pc, set())
|
||||
assert similar_to_a == component1
|
||||
# d.Component B does not have the same model
|
||||
|
@ -164,16 +166,17 @@ def test_add_remove():
|
|||
# pc has c1 and c2
|
||||
# pc2 has c3
|
||||
# c4 is not with any pc
|
||||
user = User.query.filter().first()
|
||||
values = conftest.file('pc-components.db')
|
||||
pc = values['device']
|
||||
c1, c2 = (d.Component(**c) for c in values['components'])
|
||||
pc = d.Desktop(**pc, components=OrderedSet([c1, c2]))
|
||||
db.session.add(pc)
|
||||
c3 = d.Component(serial_number='nc1')
|
||||
c3 = d.Component(serial_number='nc1', owner_id=user.id)
|
||||
pc2 = d.Desktop(serial_number='s2',
|
||||
components=OrderedSet([c3]),
|
||||
chassis=ComputerChassis.Microtower)
|
||||
c4 = d.Component(serial_number='c4s')
|
||||
c4 = d.Component(serial_number='c4s', owner_id=user.id)
|
||||
db.session.add(pc2)
|
||||
db.session.add(c4)
|
||||
db.session.commit()
|
||||
|
@ -312,14 +315,16 @@ def test_sync_execute_register_no_hid_tag_not_linked(tag_id: str):
|
|||
|
||||
|
||||
@pytest.mark.mvp
|
||||
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
||||
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
|
||||
def test_sync_execute_register_tag_does_not_exist():
|
||||
"""Ensures not being able to register if the tag does not exist,
|
||||
even if the device has HID or it existed before.
|
||||
|
||||
Tags have to be created before trying to link them through a Snapshot.
|
||||
"""
|
||||
user = User.query.filter().first()
|
||||
pc = d.Desktop(**conftest.file('pc-components.db')['device'], tags=OrderedSet([Tag('foo')]))
|
||||
pc.owner_id = user.id
|
||||
with raises(ResourceNotFound):
|
||||
Sync().execute_register(pc)
|
||||
|
||||
|
@ -463,17 +468,21 @@ def test_get_devices(app: Devicehub, user: UserClient):
|
|||
|
||||
|
||||
@pytest.mark.mvp
|
||||
def test_get_device_permissions(app: Devicehub, user: UserClient, user2: UserClient):
|
||||
def test_get_device_permissions(app: Devicehub, user: UserClient, user2: UserClient,
|
||||
client: Client):
|
||||
"""Checks GETting a d.Desktop with its components."""
|
||||
|
||||
user.post(file('asus-eee-1000h.snapshot.11'), res=m.Snapshot)
|
||||
pc, res = user.get("/devices/1", None)
|
||||
s, _ = user.post(file('asus-eee-1000h.snapshot.11'), res=m.Snapshot)
|
||||
pc, res = user.get(res=d.Device, item=s['device']['id'])
|
||||
assert res.status_code == 200
|
||||
assert len(pc['actions']) == 9
|
||||
|
||||
pc2, res2 = user2.get("/devices/1", None)
|
||||
html, _ = client.get(res=d.Device, item=s['device']['id'], accept=ANY)
|
||||
assert 'intel atom cpu n270 @ 1.60ghz' in html
|
||||
assert '00:24:8C:7F:CF:2D – 100 Mbps' in html
|
||||
pc2, res2 = user2.get(res=d.Device, item=s['device']['id'], accept=ANY)
|
||||
assert res2.status_code == 200
|
||||
assert pc2 == {}
|
||||
assert pc2 == html
|
||||
|
||||
|
||||
@pytest.mark.mvp
|
||||
|
|
|
@ -4,6 +4,7 @@ from io import StringIO
|
|||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from werkzeug.exceptions import Unauthorized
|
||||
import teal.marshmallow
|
||||
from ereuse_utils.test import ANY
|
||||
|
||||
|
@ -79,6 +80,29 @@ def test_erasure_certificate_wrong_id(client: Client):
|
|||
status=teal.marshmallow.ValidationError)
|
||||
|
||||
|
||||
@pytest.mark.mvp
|
||||
def test_export_csv_permitions(user: UserClient, user2: UserClient, client: Client):
|
||||
"""Test export device information in a csv file with others users."""
|
||||
snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot)
|
||||
csv_user, _ = user.get(res=documents.DocumentDef.t,
|
||||
item='devices/',
|
||||
accept='text/csv',
|
||||
query=[('filter', {'type': ['Computer']})])
|
||||
|
||||
csv_user2, _ = user2.get(res=documents.DocumentDef.t,
|
||||
item='devices/',
|
||||
accept='text/csv',
|
||||
query=[('filter', {'type': ['Computer']})])
|
||||
|
||||
_, res = client.get(res=documents.DocumentDef.t,
|
||||
item='devices/',
|
||||
accept='text/csv',
|
||||
query=[('filter', {'type': ['Computer']})], status=401)
|
||||
assert res.status_code == 401
|
||||
|
||||
assert len(csv_user) > 0
|
||||
assert len(csv_user2) == 0
|
||||
|
||||
@pytest.mark.mvp
|
||||
def test_export_basic_snapshot(user: UserClient):
|
||||
"""Test export device information in a csv file."""
|
||||
|
|
|
@ -252,7 +252,9 @@ def test_snapshot_component_add_remove(user: UserClient):
|
|||
assert {c['serialNumber'] for c in pc1['components']} == {'p1c3s', 'p1c4s'}
|
||||
assert all(c['parent'] == pc1_id for c in pc1['components'])
|
||||
# This last Action only
|
||||
assert get_actions_info(pc1['actions'])[-1] == ('RateComputer', ['p1c3s', 'p1c4s'])
|
||||
act = get_actions_info(pc1['actions'])[-1]
|
||||
assert 'RateComputer' in act
|
||||
assert set(act[1]) == {'p1c3s', 'p1c4s'}
|
||||
# PC2
|
||||
# We haven't changed PC2
|
||||
assert tuple(c['serialNumber'] for c in pc2['components']) == ('p2c1s',)
|
||||
|
|
Reference in a new issue