summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Callaghan <dcallagh@redhat.com>2017-10-10 16:50:32 +1000
committerDan Callaghan <dcallagh@redhat.com>2017-10-12 06:29:39 +0000
commitf162eea0e2db39a59689341e381e0fbea8e587ed (patch)
tree06d9a8539e99e0ebf69a71241e80509e2f77c47b
parent902a75b0a1d1f0c8a92d522e83c3fab06969086d (diff)
system search: treat missing value as empty string
-rw-r--r--IntegrationTests/src/bkr/inttest/server/selenium/test_system_search.py27
-rw-r--r--IntegrationTests/src/bkr/inttest/server/selenium/test_systems.py19
-rw-r--r--Server/bkr/server/controllers.py6
3 files changed, 47 insertions, 5 deletions
diff --git a/IntegrationTests/src/bkr/inttest/server/selenium/test_system_search.py b/IntegrationTests/src/bkr/inttest/server/selenium/test_system_search.py
index ce47812..57b1d62 100644
--- a/IntegrationTests/src/bkr/inttest/server/selenium/test_system_search.py
+++ b/IntegrationTests/src/bkr/inttest/server/selenium/test_system_search.py
@@ -8,7 +8,7 @@ from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
from bkr.server.model import Numa, User, Key, Key_Value_String, Key_Value_Int, \
Device, DeviceClass, Disk, Cpu, SystemPermission, System, \
- SystemType, SystemStatus
+ SystemType, SystemStatus, Hypervisor
from bkr.inttest.server.selenium import WebDriverTestCase
from bkr.inttest.server.webdriver_utils import get_server_base, login, \
search_for_system, wait_for_animation, check_system_search_results
@@ -468,6 +468,31 @@ class Search(WebDriverTestCase):
# important thing is that there should not be a JS alert present.
b.find_element_by_xpath('//span[@class="item-count" and text()="Items found: 0"]')
+ # https://bugzilla.redhat.com/show_bug.cgi?id=1498804
+ def test_no_value(self):
+ # This is just a bizarre edge case in how the existing search bar
+ # handles adding new rows to the search, causing the value control to
+ # be "unsuccessful" in HTML forms parlance.
+ # Just delete this test when the search bar is improved in future.
+ with session.begin():
+ not_virtualised = data_setup.create_system(fqdn=u'bz1498804.notvirtualised')
+ not_virtualised.hypervisor = None
+ virtualised = data_setup.create_system(fqdn=u'bz1498804.virtualised')
+ virtualised.hypervisor = Hypervisor.by_name(u'KVM')
+ b = self.browser
+ # Open a page with an existing search filled in.
+ b.get(get_server_base() +
+ '?systemsearch-0.table=System%2FName'
+ '&systemsearch-0.operation=contains'
+ '&systemsearch-0.value=bz1498804')
+ # Add a new row to the search
+ b.find_element_by_id('doclink').click()
+ # Select a field, but don't type anything into the value
+ Select(b.find_element_by_name('systemsearch-1.table'))\
+ .select_by_visible_text('System/Hypervisor')
+ b.find_element_by_id('searchform').submit()
+ check_system_search_results(b, present=[not_virtualised], absent=[virtualised])
+
class LabControllerSearchTest(WebDriverTestCase):
def setUp(self):
diff --git a/IntegrationTests/src/bkr/inttest/server/selenium/test_systems.py b/IntegrationTests/src/bkr/inttest/server/selenium/test_systems.py
index 62f2581..46a741e 100644
--- a/IntegrationTests/src/bkr/inttest/server/selenium/test_systems.py
+++ b/IntegrationTests/src/bkr/inttest/server/selenium/test_systems.py
@@ -22,7 +22,7 @@ from bkr.inttest import data_setup, get_server_base, with_transaction, \
DatabaseTestCase
from bkr.inttest.assertions import assert_sorted
from bkr.server.model import Cpu, Key, Key_Value_String, System, \
- SystemStatus, SystemPermission, Job, Disk, User
+ SystemStatus, SystemPermission, Job, Disk, User, Hypervisor
from bkr.inttest.server.webdriver_utils import check_system_search_results, login, \
wait_for_animation
from bkr.inttest.server.requests_utils import patch_json, login as requests_login
@@ -356,6 +356,23 @@ class TestSystemsAtomFeed(DatabaseTestCase):
self.assertFalse(self.feed_contains_system(feed, nopool.fqdn))
self.assertTrue(self.feed_contains_system(feed, inpool.fqdn))
+ # https://bugzilla.redhat.com/show_bug.cgi?id=1498804
+ def test_filter_with_no_value(self):
+ with session.begin():
+ not_virtualised = data_setup.create_system()
+ not_virtualised.hypervisor = None
+ virtualised = data_setup.create_system()
+ virtualised.hypervisor = Hypervisor.by_name(u'KVM')
+ feed_url = urljoin(get_server_base(), '?' + urlencode({
+ 'tg_format': 'atom',
+ 'list_tgp_order': '-date_modified',
+ 'list_tgp_limit': '0',
+ 'systemsearch-0.table': 'System/Hypervisor',
+ 'systemsearch-0.operation': 'is'}))
+ feed = lxml.etree.parse(urlopen(feed_url)).getroot()
+ self.assertFalse(self.feed_contains_system(feed, virtualised.fqdn))
+ self.assertTrue(self.feed_contains_system(feed, not_virtualised.fqdn))
+
# https://bugzilla.redhat.com/show_bug.cgi?id=690063
def test_xml_filter(self):
with session.begin():
diff --git a/Server/bkr/server/controllers.py b/Server/bkr/server/controllers.py
index cece8db..b05664b 100644
--- a/Server/bkr/server/controllers.py
+++ b/Server/bkr/server/controllers.py
@@ -391,11 +391,11 @@ class Root(RPCRoot):
class_field_list = search['table'].split('/')
cls_ref = su.System.search.translate_name_to_class(class_field_list[0])
col = class_field_list[1]
- #If value id False or True, let's convert them to
+ value = search.get('value', '')
if class_field_list[0] != 'Key':
- sys_search.append_results(cls_ref,search['value'],col,search['operation'])
+ sys_search.append_results(cls_ref, value, col, search['operation'])
else:
- sys_search.append_results(cls_ref,search['value'],col,search['operation'],keyvalue=search['keyvalue'])
+ sys_search.append_results(cls_ref, value, col, search['operation'], keyvalue=search['keyvalue'])
return sys_search.return_results()