Fix not adding tag.secondary to search
This commit is contained in:
parent
8889496a34
commit
5301242dbd
|
@ -108,6 +108,7 @@ class DeviceSearch(db.Model):
|
|||
tags = session.query(
|
||||
search.Search.vectorize(
|
||||
(db.func.string_agg(Tag.id, ' '), search.Weight.A),
|
||||
(db.func.string_agg(Tag.secondary, ' '), search.Weight.A),
|
||||
(db.func.string_agg(Organization.name, ' '), search.Weight.B)
|
||||
)
|
||||
).filter(Tag.device_id == device.id).join(Tag.org)
|
||||
|
|
|
@ -12,10 +12,12 @@ from ereuse_devicehub.devicehub import Devicehub
|
|||
from ereuse_devicehub.resources.agent.models import Organization
|
||||
from ereuse_devicehub.resources.device.models import Desktop, Device
|
||||
from ereuse_devicehub.resources.enums import ComputerChassis
|
||||
from ereuse_devicehub.resources.event.models import Snapshot
|
||||
from ereuse_devicehub.resources.tag import Tag
|
||||
from ereuse_devicehub.resources.tag.view import CannotCreateETag, LinkedToAnotherDevice, \
|
||||
TagNotLinked
|
||||
from tests import conftest
|
||||
from tests.conftest import file
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
||||
|
@ -179,8 +181,10 @@ def test_tag_manual_link(app: Devicehub, user: UserClient):
|
|||
|
||||
|
||||
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
||||
def test_tag_secondary():
|
||||
"""Creates and consumes tags with a secondary id."""
|
||||
def test_tag_secondary_workbench_link_find(user: UserClient):
|
||||
"""Creates and consumes tags with a secondary id, linking them
|
||||
through Workbench to a device
|
||||
and getting them through search."""
|
||||
t = Tag('foo', secondary='bar')
|
||||
db.session.add(t)
|
||||
db.session.flush()
|
||||
|
@ -189,6 +193,18 @@ def test_tag_secondary():
|
|||
with pytest.raises(ResourceNotFound):
|
||||
Tag.from_an_id('nope').one()
|
||||
|
||||
s = file('basic.snapshot')
|
||||
s['device']['tags'] = [{'id': 'foo', 'secondary': 'bar', 'type': 'Tag'}]
|
||||
snapshot, _ = user.post(s, res=Snapshot)
|
||||
device, _ = user.get(res=Device, item=snapshot['device']['id'])
|
||||
assert device['tags'][0]['id'] == 'foo'
|
||||
assert device['tags'][0]['secondary'] == 'bar'
|
||||
|
||||
r, _ = user.get(res=Device, query=[('search', 'foo'), ('filter', {'type': ['Computer']})])
|
||||
assert len(r['items']) == 1
|
||||
r, _ = user.get(res=Device, query=[('search', 'bar'), ('filter', {'type': ['Computer']})])
|
||||
assert len(r['items']) == 1
|
||||
|
||||
|
||||
def test_tag_create_tags_cli_csv(app: Devicehub, user: UserClient):
|
||||
"""Checks creating tags with the CLI endpoint using a CSV."""
|
||||
|
|
Reference in New Issue