new tests and fixing others
This commit is contained in:
parent
adcb330b87
commit
b2859781f0
|
@ -8,7 +8,7 @@ from pytest import raises
|
||||||
from teal.db import MultipleResourcesFound, ResourceNotFound, UniqueViolation, DBError
|
from teal.db import MultipleResourcesFound, ResourceNotFound, UniqueViolation, DBError
|
||||||
from teal.marshmallow import ValidationError
|
from teal.marshmallow import ValidationError
|
||||||
|
|
||||||
from ereuse_devicehub.client import UserClient
|
from ereuse_devicehub.client import UserClient, Client
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.devicehub import Devicehub
|
from ereuse_devicehub.devicehub import Devicehub
|
||||||
from ereuse_devicehub.resources.action.models import Snapshot
|
from ereuse_devicehub.resources.action.models import Snapshot
|
||||||
|
@ -78,7 +78,8 @@ def test_create_two_same_tags(user: UserClient):
|
||||||
db.session.add(Tag(id='foo-bar', owner_id=user.user['id']))
|
db.session.add(Tag(id='foo-bar', owner_id=user.user['id']))
|
||||||
org2 = Organization(name='org 2', tax_id='tax id org 2')
|
org2 = Organization(name='org 2', tax_id='tax id org 2')
|
||||||
db.session.add(Tag(id='foo-bar', org=org2, owner_id=user.user['id']))
|
db.session.add(Tag(id='foo-bar', org=org2, owner_id=user.user['id']))
|
||||||
db.session.commit()
|
with raises(DBError):
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.mvp
|
@pytest.mark.mvp
|
||||||
|
@ -145,17 +146,39 @@ def test_tag_get_device_from_tag_endpoint_no_tag(user: UserClient):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.mvp
|
@pytest.mark.mvp
|
||||||
def test_tag_get_device_from_tag_endpoint_multiple_tags(app: Devicehub, user: UserClient):
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
||||||
"""As above, but when there are two tags with the same ID, the
|
def test_tag_get_device_from_tag_endpoint_multiple_tags(app: Devicehub, user: UserClient, user2: UserClient, client: Client):
|
||||||
|
"""As above, but when there are two tags with the secondary ID, the
|
||||||
system should not return any of both (to be deterministic) so
|
system should not return any of both (to be deterministic) so
|
||||||
it should raise an exception.
|
it should raise an exception.
|
||||||
"""
|
"""
|
||||||
with app.app_context():
|
db.session.add(Tag(id='foo', secondary='bar', owner_id=user.user['id']))
|
||||||
db.session.add(Tag(id='foo-bar', owner_id=user.user['id']))
|
db.session.commit()
|
||||||
org2 = Organization(name='org 2', tax_id='tax id org 2')
|
|
||||||
db.session.add(Tag(id='foo-bar', org=org2, owner_id=user.user['id']))
|
db.session.add(Tag(id='foo', secondary='bar', owner_id=user2.user['id']))
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
db.session.add(Tag(id='foo2', secondary='bar', owner_id=user.user['id']))
|
||||||
|
with raises(DBError):
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
user.get(res=Tag, item='foo-bar/device', status=MultipleResourcesFound)
|
db.session.rollback()
|
||||||
|
|
||||||
|
tag1 = Tag.from_an_id('foo').filter_by(owner_id=user.user['id']).one()
|
||||||
|
tag2 = Tag.from_an_id('foo').filter_by(owner_id=user2.user['id']).one()
|
||||||
|
pc1 = Desktop(serial_number='sn1', chassis=ComputerChassis.Tower, owner_id=user.user['id'])
|
||||||
|
pc2 = Desktop(serial_number='sn2', chassis=ComputerChassis.Tower, owner_id=user2.user['id'])
|
||||||
|
pc1.tags.add(tag1)
|
||||||
|
pc2.tags.add(tag2)
|
||||||
|
db.session.add(pc1)
|
||||||
|
db.session.add(pc2)
|
||||||
|
db.session.commit()
|
||||||
|
computer, _ = user.get(res=Tag, item='foo/device')
|
||||||
|
assert computer['serialNumber'] == 'sn1'
|
||||||
|
computer, _ = user2.get(res=Tag, item='foo/device')
|
||||||
|
assert computer['serialNumber'] == 'sn2'
|
||||||
|
|
||||||
|
_, status = client.get(res=Tag, item='foo/device', status=MultipleResourcesFound)
|
||||||
|
assert status.status_code == 422
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.mvp
|
@pytest.mark.mvp
|
||||||
|
@ -230,8 +253,7 @@ def test_tag_secondary_workbench_link_find(user: UserClient):
|
||||||
t = Tag('foo', secondary='bar', owner_id=user.user['id'])
|
t = Tag('foo', secondary='bar', owner_id=user.user['id'])
|
||||||
db.session.add(t)
|
db.session.add(t)
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
assert Tag.from_an_id('bar').one() == t
|
assert Tag.from_an_id('bar').one() == Tag.from_an_id('foo').one()
|
||||||
assert Tag.from_an_id('foo').one() == t
|
|
||||||
with pytest.raises(ResourceNotFound):
|
with pytest.raises(ResourceNotFound):
|
||||||
Tag.from_an_id('nope').one()
|
Tag.from_an_id('nope').one()
|
||||||
|
|
||||||
|
|
Reference in New Issue