How to use perform_search method in Wtframework

Best Python code snippet using wtframework

test_system_search.py

Source:test_system_search.py Github

copy

Full Screen

...113 b.find_element_by_link_text('Select All').click()114 b.find_element_by_xpath("//form[@id='searchform']").submit()115 columns = b.find_elements_by_xpath("//table[@id='widget']//th")116 self.assertGreater(len(columns), 8)117def perform_search(browser, searchcriteria, search_url=''):118 b = browser119 b.get(get_server_base() + search_url)120 b.find_element_by_link_text('Show Search Options').click()121 wait_for_animation(b, '#searchform')122 for fieldid, criteria in enumerate(searchcriteria):123 if criteria[0] == 'Key/Value':124 assert len(criteria) == 4, "Key/Value criteria must be specified as" \125 " ('Key/Value', keyname, operation, value)"126 fieldname, keyvalue, operation, value = criteria127 else:128 fieldname, operation, value = criteria129 if fieldid > 0:130 # press the add button to add a new row131 b.find_element_by_id('doclink').click()132 Select(b.find_element_by_name('systemsearch-%i.table' % fieldid))\133 .select_by_visible_text(fieldname)134 if criteria[0] == 'Key/Value':135 Select(browser.find_element_by_name('systemsearch-%i.keyvalue' % fieldid))\136 .select_by_visible_text(keyvalue)137 Select(b.find_element_by_name('systemsearch-%i.operation' % fieldid))\138 .select_by_visible_text(operation)139 b.find_element_by_name('systemsearch-%i.value' % fieldid).clear()140 b.find_element_by_name('systemsearch-%i.value' % fieldid).send_keys(value)141 b.find_element_by_id('searchform').submit()142class Search(WebDriverTestCase):143 def setUp(self):144 with session.begin():145 self.user = data_setup.create_user(password=u'password')146 self.system = data_setup.create_system(147 lab_controller=data_setup.create_labcontroller())148 self.system.loaned = self.user149 self.another_system = data_setup.create_system(150 lab_controller=data_setup.create_labcontroller())151 self.another_system.loaned = self.user152 self.browser = self.get_browser()153 login(self.browser, user=self.user.user_name, password=u'password')154 def test_multiple_cpu_flags(self):155 with session.begin():156 system = data_setup.create_system()157 system.cpu = Cpu(flags=['flag1', 'flag2'])158 another_system = data_setup.create_system()159 another_system.cpu = Cpu(flags=['flag3'])160 b = self.browser161 perform_search(b, [('CPU/Flags', 'is', 'flag1'),162 ('CPU/Flags', 'is', 'flag2')])163 check_system_search_results(b, present=[system],164 absent=[another_system])165 def test_by_device(self):166 with session.begin():167 system = data_setup.create_system()168 device = data_setup.create_device(169 device_class='testclass',170 subsys_vendor_id='1111',171 subsys_device_id='1112')172 system.devices.append(device)173 another_system = data_setup.create_system()174 another_device = data_setup.create_device(175 device_class='testclass',176 subsys_vendor_id='2223',177 subsys_device_id='2224')178 another_system.devices.append(another_device)179 b = self.browser180 perform_search(b, [('Devices/Subsys_device_id', 'is', '1112')])181 check_system_search_results(b, present=[system],182 absent=[another_system])183 perform_search(b, [('Devices/Subsys_vendor_id', 'is not', '1111'),184 ('Devices/Subsys_device_id', 'is', '2224')])185 check_system_search_results(b, present=[another_system],186 absent=[system])187 def test_by_name(self):188 b = self.browser189 perform_search(b, [('System/Name', 'is', self.system.fqdn)])190 check_system_search_results(b, present=[self.system],191 absent=[self.another_system])192 def test_by_type(self):193 with session.begin():194 self.system.type = SystemType.laptop195 b = self.browser196 b.get(urljoin(get_server_base(),'mine'))197 b.find_element_by_link_text('Show Search Options').click()198 wait_for_animation(b, '#searchform')199 Select(b.find_element_by_name('systemsearch-0.table'))\200 .select_by_visible_text('System/Type')201 Select(b.find_element_by_name('systemsearch-0.operation'))\202 .select_by_visible_text('is')203 Select(b.find_element_by_name('systemsearch-0.value'))\204 .select_by_visible_text('Laptop')205 b.find_element_by_id('searchform').submit()206 check_system_search_results(b, present=[self.system],207 absent=[self.another_system])208 def test_by_status(self):209 with session.begin():210 self.system.status = SystemStatus.manual211 b = self.browser212 b.get(urljoin(get_server_base(),'mine'))213 b.find_element_by_link_text('Show Search Options').click()214 wait_for_animation(b, '#searchform')215 Select(b.find_element_by_name('systemsearch-0.table'))\216 .select_by_visible_text('System/Status')217 Select(b.find_element_by_name('systemsearch-0.operation'))\218 .select_by_visible_text('is')219 Select(b.find_element_by_name('systemsearch-0.value'))\220 .select_by_visible_text('Manual')221 b.find_element_by_id('searchform').submit()222 check_system_search_results(b, present=[self.system],223 absent=[self.another_system])224 def test_by_reserved_since(self):225 with session.begin():226 s1 = data_setup.create_system()227 data_setup.create_manual_reservation(s1, start=datetime.datetime(2003, 1, 21, 11, 30, 0))228 s2 = data_setup.create_system(fqdn='aaadvark.testdata')229 data_setup.create_manual_reservation(s2, start=datetime.datetime(2005, 1, 21, 11, 30, 0))230 b = self.browser231 perform_search(b, [('System/Reserved', 'is', '2003-01-21')])232 check_system_search_results(b, present=[s1], absent=[s2])233 perform_search(b, [('System/Reserved', 'before', '2005-1-21')])234 check_system_search_results(b, present=[s1], absent=[s2])235 perform_search(b, [('System/Reserved', 'after', '2005-1-21')])236 check_system_search_results(b, absent=[s1, s2])237 perform_search(b, [('System/Reserved', 'after', '2005-1-1')])238 check_system_search_results(b, present=[s2], absent=[s1])239 def test_by_date_added(self):240 with session.begin():241 new_system = data_setup.create_system()242 new_system.date_added = datetime.datetime(2020, 6, 21, 11, 30, 0)243 old_system = data_setup.create_system()244 old_system.date_added = datetime.datetime(2001, 1, 15, 14, 12, 0)245 b = self.browser246 perform_search(b, [('System/Added', 'is', '2001-01-15')])247 check_system_search_results(b, present=[old_system], absent=[new_system])248 perform_search(b, [('System/Added', 'before', '2001-01-16')])249 check_system_search_results(b, present=[old_system], absent=[new_system])250 perform_search(b, [('System/Added', 'after', '2020-12-31')])251 # no results252 b.find_element_by_xpath('//table[@id="widget" and not(.//td)]')253 perform_search(b, [('System/Added', 'after', '2020-06-20')])254 check_system_search_results(b, present=[new_system], absent=[old_system])255 perform_search(b, [('System/Added', 'after', '2020-06-20'),256 ('System/Added', 'before', '2020-06-22')])257 check_system_search_results(b, present=[new_system], absent=[old_system])258 def test_by_notes(self):259 with session.begin():260 owner = data_setup.create_user()261 new_system = data_setup.create_system()262 new_system.add_note("Note1", owner)263 old_system = data_setup.create_system()264 old_system.add_note("Note2", owner)265 b = self.browser266 # System/Notes search is supposed to be case-insensitive267 perform_search(b, [('System/Notes', 'contains', 'nOTe1')])268 check_system_search_results(b, present=[new_system], absent=[old_system])269 # Specific search270 perform_search(b, [('System/Notes', 'is', 'Note2')])271 check_system_search_results(b, present=[old_system], absent=[new_system])272 # All systems without any note273 perform_search(b, [('System/Notes', 'is', '')])274 check_system_search_results(b, absent=[old_system, new_system])275 # All systems with any note276 perform_search(b, [('System/Notes', 'is not', '')])277 check_system_search_results(b, present=[old_system, new_system])278 perform_search(b, [('System/Notes', 'is', 'foobar')])279 # no results280 b.find_element_by_xpath('//table[@id="widget" and not(.//td)]')281 def test_by_key_value_is(self):282 with session.begin():283 self.system.key_values_string.append(Key_Value_String(284 Key.by_name(u'CPUMODEL'), 'foocodename'))285 b = self.browser286 b.get(get_server_base())287 b.find_element_by_link_text('Show Search Options').click()288 wait_for_animation(b, '#searchform')289 Select(b.find_element_by_name('systemsearch-0.table'))\290 .select_by_visible_text('Key/Value')291 Select(b.find_element_by_name('systemsearch-0.keyvalue'))\292 .select_by_visible_text('CPUMODEL')293 Select(b.find_element_by_name('systemsearch-0.operation'))\294 .select_by_visible_text('is')295 b.find_element_by_name('systemsearch-0.value').send_keys('foocodename')296 b.find_element_by_id('searchform').submit()297 check_system_search_results(b, present=[self.system],298 absent=[self.another_system])299 def test_by_key_value_is_on_removed_systems_page(self):300 with session.begin():301 system = data_setup.create_system()302 removed_system = data_setup.create_system(status=SystemStatus.removed)303 removed_system.key_values_string.append(Key_Value_String(304 Key.by_name(u'CPUMODEL'), 'foocodename'))305 # Key Value search from "Removed Systems"306 b = self.browser307 perform_search(b, [('Key/Value', 'CPUMODEL', 'is', 'foocodename')],308 search_url='removed')309 check_system_search_results(b, present=[removed_system],310 absent=[system])311 def test_by_key_value_is_not(self):312 with session.begin():313 self.another_system.key_values_string.append(Key_Value_String(314 Key.by_name(u'CPUMODEL'), 'foocodename'))315 b = self.browser316 perform_search(b, [('Key/Value', 'CPUMODEL', 'is not', 'foocodename')],317 search_url=u'mine')318 check_system_search_results(b, present=[self.system],319 absent=[self.another_system])320 def test_by_multiple_key_values(self):321 with session.begin():322 self.system = data_setup.create_system()323 self.system.key_values_string.append(Key_Value_String(324 Key.by_name(u'CPUMODEL'), 'foocodename'))325 self.system.key_values_string.append(Key_Value_String(326 Key.by_name(u'HVM'), '1'))327 self.system.key_values_int.append(Key_Value_Int(328 Key.by_name(u'DISKSPACE'), '1024'))329 b = self.browser330 perform_search(b, [('Key/Value', 'HVM', 'is', '1'),331 ('Key/Value', 'CPUMODEL', 'is', 'foocodename'),332 ('Key/Value', 'DISKSPACE', 'greater than', '1000')])333 check_system_search_results(b, present=[self.system],334 absent=[self.another_system])335 def test_can_search_by_numa_node_count(self):336 with session.begin():337 self.system.numa = Numa(nodes=1)338 self.another_system.numa = Numa(nodes=2)339 b = self.browser340 perform_search(b, [('System/NumaNodes', 'greater than', '1')])341 check_system_search_results(b, present=[self.another_system],342 absent=[self.system])343 b.get(get_server_base())344 perform_search(b, [('System/NumaNodes', 'less than', '2')])345 check_system_search_results(b, present=[self.system],346 absent=[self.another_system])347 # https://bugzilla.redhat.com/show_bug.cgi?id=1304927348 def test_search_works_on_reserve_report(self):349 # Reserve Report is a specialisation of the regular systems grid, so we 350 # aren't testing it exhaustively, we just want to make sure that the 351 # search is wired up properly.352 with session.begin():353 included = data_setup.create_system()354 data_setup.create_manual_reservation(included)355 excluded = data_setup.create_system(fqdn=data_setup.unique_name(u'aardvark%s'))356 data_setup.create_manual_reservation(excluded)357 b = self.browser358 perform_search(b, [('System/Name', 'is', included.fqdn)],359 search_url='reports/')360 check_system_search_results(b, present=[included], absent=[excluded])361 # https://bugzilla.redhat.com/show_bug.cgi?id=1120705362 def test_searchbar_dropdowns_are_sorted(self):363 b = self.browser364 b.get(get_server_base())365 b.find_element_by_link_text('Show Search Options').click()366 wait_for_animation(b, '#searchform')367 table_options = b.find_element_by_name('systemsearch-0.table')\368 .find_elements_by_tag_name('option')369 assert_sorted([option.text for option in table_options])370 Select(b.find_element_by_name('systemsearch-0.table'))\371 .select_by_visible_text('Key/Value')372 keyvalue_options = b.find_element_by_name('systemsearch-0.keyvalue')\373 .find_elements_by_tag_name('option')374 assert_sorted([option.text for option in keyvalue_options])375 # https://bugzilla.redhat.com/show_bug.cgi?id=1182545376 def test_invalid_date(self):377 b = self.browser378 b.get(get_server_base())379 b.find_element_by_link_text('Show Search Options').click()380 wait_for_animation(b, '#searchform')381 Select(b.find_element_by_name('systemsearch-0.table'))\382 .select_by_visible_text('System/Added')383 Select(b.find_element_by_name('systemsearch-0.operation'))\384 .select_by_visible_text('after')385 search_field = b.find_element_by_name('systemsearch-0.value')386 search_field.click()387 # close the date picker388 search_field.send_keys(Keys.ESCAPE)389 search_field.send_keys('02-02-2002')390 # we can't actually check the HTML5 validation error391 b.find_element_by_css_selector('input[name="systemsearch-0.value"]:invalid')392 # https://bugzilla.redhat.com/show_bug.cgi?id=1182545393 def test_date_picker(self):394 with session.begin():395 today = datetime.date.today()396 new_system = data_setup.create_system()397 new_system.date_added = today398 old_system = data_setup.create_system()399 old_system.date_added = today - datetime.timedelta(days=10)400 b = self.browser401 b.get(get_server_base())402 b.find_element_by_link_text('Show Search Options').click()403 wait_for_animation(b, '#searchform')404 Select(b.find_element_by_name('systemsearch-0.table'))\405 .select_by_visible_text('System/Added')406 Select(b.find_element_by_name('systemsearch-0.operation'))\407 .select_by_visible_text('before')408 search_field = b.find_element_by_name('systemsearch-0.value')409 search_field.click()410 b.find_element_by_css_selector('.datepicker td.active').click()411 b.find_element_by_id('searchform').submit()412 check_system_search_results(b, present=[old_system], absent=[new_system])413 # https://bugzilla.redhat.com/show_bug.cgi?id=1215024414 def test_closing_script_tag_escaped_in_search_bar(self):415 with session.begin():416 Key.lazy_create(key_name=u'</script>')417 b = self.browser418 b.get(get_server_base())419 b.find_element_by_link_text('Show Search Options').click()420 wait_for_animation(b, '#searchform')421 Select(b.find_element_by_name('systemsearch-0.table'))\422 .select_by_visible_text('Key/Value')423 Select(b.find_element_by_name('systemsearch-0.keyvalue'))\424 .select_by_visible_text('</script>')425 # https://bugzilla.redhat.com/show_bug.cgi?id=1295998426 def test_closing_script_tag_from_search_value_is_escaped(self):427 bad_string = u"</script><script>alert('hi')</script>"428 with session.begin():429 system = data_setup.create_system(location=bad_string)430 another_system = data_setup.create_system()431 b = self.browser432 perform_search(b, [('System/Location', 'is', bad_string)])433 check_system_search_results(b, present=[system],434 absent=[another_system])435 # https://bugzilla.redhat.com/show_bug.cgi?id=1295998436 def test_closing_script_tag_from_simplesearch_is_escaped(self):437 bad_string = u"</script><script>alert('hi')</script>"438 b = self.browser439 b.get(get_server_base())440 b.find_element_by_name('simplesearch').send_keys(bad_string)441 b.find_element_by_name('systemsearch_simple').submit()442 # System simplesearch matches on FQDN but we can never have an FQDN 443 # containing </script> so we can only expect empty results. The 444 # important thing is that there should not be a JS alert present.445 b.find_element_by_xpath('//span[@class="item-count" and text()="Items found: 0"]')446 # https://bugzilla.redhat.com/show_bug.cgi?id=1498804447 def test_no_value(self):448 # This is just a bizarre edge case in how the existing search bar 449 # handles adding new rows to the search, causing the value control to 450 # be "unsuccessful" in HTML forms parlance.451 # Just delete this test when the search bar is improved in future.452 with session.begin():453 not_virtualised = data_setup.create_system(fqdn=u'bz1498804.notvirtualised')454 not_virtualised.hypervisor = None455 virtualised = data_setup.create_system(fqdn=u'bz1498804.virtualised')456 virtualised.hypervisor = Hypervisor.by_name(u'KVM')457 b = self.browser458 # Open a page with an existing search filled in.459 b.get(get_server_base() +460 '?systemsearch-0.table=System%2FName'461 '&systemsearch-0.operation=contains'462 '&systemsearch-0.value=bz1498804')463 # Add a new row to the search464 b.find_element_by_id('doclink').click()465 # Select a field, but don't type anything into the value466 Select(b.find_element_by_name('systemsearch-1.table'))\467 .select_by_visible_text('System/Hypervisor')468 b.find_element_by_id('searchform').submit()469 check_system_search_results(b, present=[not_virtualised], absent=[virtualised])470class LabControllerSearchTest(WebDriverTestCase):471 def setUp(self):472 with session.begin():473 self.owner = data_setup.create_user(password=u'password')474 self.lc1 = data_setup.create_labcontroller(fqdn=u'bz704399.example.invalid')475 self.lc2 = data_setup.create_labcontroller()476 self.s1 = data_setup.create_system(lab_controller=self.lc1, loaned=self.owner)477 self.s2 = data_setup.create_system(lab_controller=self.lc2, loaned=self.owner)478 self.browser = self.get_browser()479 login(self.browser, user=self.owner.user_name, password=u'password')480 def test_by_lab_controller(self):481 b = self.browser482 perform_search(b, [('System/LabController', 'is', self.lc1.fqdn)], search_url='mine')483 check_system_search_results(b, present=[self.s1], absent=[self.s2])484 def test_by_lab_controller_is_not(self):485 b = self.browser486 perform_search(b, [('System/LabController', 'is not', self.lc1.fqdn)], search_url='mine')487 check_system_search_results(b,488 present=[self.s2],489 absent=[self.s1])490 def test_by_lab_controller_contains(self):491 b = self.browser492 perform_search(b, [('System/LabController', 'contains', self.lc1.fqdn)], search_url='mine')493 check_system_search_results(b,494 present=[self.s1],495 absent=[self.s2])496class SystemVisibilityTest(WebDriverTestCase):497 def setUp(self):498 with session.begin():499 self.user = data_setup.create_user(password=u'password')500 self.browser = self.get_browser()501 def test_secret_system_not_visible(self):502 with session.begin():503 secret_system = data_setup.create_system(shared=False, private=True)504 b = self.browser505 login(b, user=self.user.user_name, password=u'password')506 b.get(get_server_base())507 search_for_system(b, secret_system)508 # results grid should be empty509 b.find_element_by_xpath('//table[@id="widget" and not(.//td)]')510 # https://bugzilla.redhat.com/show_bug.cgi?id=582008511 def test_secret_system_visible_when_loaned(self):512 with session.begin():513 secret_system = data_setup.create_system(shared=False, private=True)514 secret_system.loaned = self.user515 b = self.browser516 login(b, user=self.user.user_name, password=u'password')517 b.get(get_server_base())518 search_for_system(b, secret_system)519 b.find_element_by_xpath('//table[@id="widget"]'520 '//tr/td[1][./a/text()="%s"]' % secret_system.fqdn)521 def test_secret_system_visible_to_users_with_view_permission(self):522 with session.begin():523 secret_system = data_setup.create_system(shared=False, private=True)524 secret_system.custom_access_policy.add_rule(SystemPermission.view,525 user=self.user)526 b = self.browser527 login(b, user=self.user.user_name, password=u'password')528 b.get(get_server_base())529 search_for_system(b, secret_system)530 b.find_element_by_xpath('//table[@id="widget"]'531 '//tr/td[1][./a/text()="%s"]' % secret_system.fqdn)532class HypervisorSearchTest(WebDriverTestCase):533 def setUp(self):534 with session.begin():535 self.user = data_setup.create_user(password=u'hypervisin')536 self.kvm = data_setup.create_system(loaned=self.user, hypervisor=u'KVM')537 self.xen = data_setup.create_system(loaned=self.user, hypervisor=u'Xen')538 self.phys = data_setup.create_system(loaned=self.user, hypervisor=None)539 self.browser = self.get_browser()540 login(self.browser, user=self.user.user_name, password=u'hypervisin')541 def test_search_hypervisor_is(self):542 b = self.browser543 b.get(get_server_base() + 'mine')544 b.find_element_by_link_text('Show Search Options').click()545 wait_for_animation(b, '#searchform')546 Select(b.find_element_by_name('systemsearch-0.table'))\547 .select_by_visible_text('System/Hypervisor')548 Select(b.find_element_by_name('systemsearch-0.operation'))\549 .select_by_visible_text('is')550 Select(b.find_element_by_name('systemsearch-0.value'))\551 .select_by_visible_text('KVM')552 b.find_element_by_id('searchform').submit()553 check_system_search_results(b, present=[self.kvm], absent=[self.xen, self.phys])554 def test_search_hypervisor_is_not(self):555 b = self.browser556 b.get(get_server_base() + 'mine')557 b.find_element_by_link_text('Show Search Options').click()558 wait_for_animation(b, '#searchform')559 Select(b.find_element_by_name('systemsearch-0.table'))\560 .select_by_visible_text('System/Hypervisor')561 Select(b.find_element_by_name('systemsearch-0.operation'))\562 .select_by_visible_text('is not')563 Select(b.find_element_by_name('systemsearch-0.value'))\564 .select_by_visible_text('KVM')565 b.find_element_by_id('searchform').submit()566 check_system_search_results(b, present=[self.xen, self.phys], absent=[self.kvm])567 def test_search_hypervisor_is_blank(self):568 b = self.browser569 b.get(get_server_base() + 'mine')570 b.find_element_by_link_text('Show Search Options').click()571 wait_for_animation(b, '#searchform')572 Select(b.find_element_by_name('systemsearch-0.table'))\573 .select_by_visible_text('System/Hypervisor')574 Select(b.find_element_by_name('systemsearch-0.operation'))\575 .select_by_visible_text('is')576 Select(b.find_element_by_name('systemsearch-0.value'))\577 .select_by_visible_text('')578 b.find_element_by_id('searchform').submit()579 check_system_search_results(b, present=[self.phys], absent=[self.kvm, self.xen])580class DiskSearchTest(WebDriverTestCase):581 def setUp(self):582 with session.begin():583 self.user = data_setup.create_user(password=u'diskin')584 self.no_disks = data_setup.create_system(loaned=self.user)585 self.no_disks.disks[:] = []586 self.small_disk = data_setup.create_system(loaned=self.user)587 self.small_disk.disks[:] = [Disk(size=8000000000,588 sector_size=512, phys_sector_size=512)]589 self.big_disk = data_setup.create_system(loaned=self.user)590 self.big_disk.disks[:] = [Disk(size=2000000000000,591 sector_size=4096, phys_sector_size=4096)]592 self.two_disks = data_setup.create_system(loaned=self.user)593 self.two_disks.disks[:] = [594 Disk(size=8000000000, sector_size=512, phys_sector_size=512),595 Disk(size=2000000000000, sector_size=4096, phys_sector_size=4096),596 ]597 self.browser = self.get_browser()598 login(self.browser, user=self.user.user_name, password=u'diskin')599 def test_search_size_greater_than(self):600 b = self.browser601 perform_search(b, [('Disk/Size', 'greater than', '10000000000')],602 search_url='mine')603 check_system_search_results(b, present=[self.big_disk, self.two_disks],604 absent=[self.small_disk, self.no_disks])605 def test_sector_size_is_not_for_multiple_disks(self):606 # The search bar special-cases "is not" searches on one-to-many 607 # relationships. "Disk/Size is not 1000" does not mean "systems with 608 # a disk whose size is not 1000" but rather "systems with no disks of 609 # size 1000".610 b = self.browser611 perform_search(b, [('Disk/SectorSize', 'is not', '512')],612 search_url='mine')613 check_system_search_results(b, present=[self.big_disk, self.no_disks],614 absent=[self.small_disk, self.two_disks])615#https://bugzilla.redhat.com/show_bug.cgi?id=949777616# we visit the 'mine' page, so that we have substantially617# less systems to deal with618class InventoriedSearchTest(WebDriverTestCase):619 def setUp(self):620 with session.begin():621 self.user = data_setup.create_user(password=u'password')622 self.browser = self.get_browser()623 login(self.browser, user=self.user.user_name, password=u'password')624 def test_uninventoried_search(self):625 with session.begin():626 system = data_setup.create_system(loaned=self.user)627 b = self.browser628 perform_search(b, [('System/LastInventoried', 'is', ' ')],629 search_url='mine')630 check_system_search_results(b, present=[system])631 def test_inventoried_search_after(self):632 with session.begin():633 system_one = data_setup.create_system(loaned=self.user)634 system_one.date_lastcheckin = datetime.datetime(2001, 1, 15, 14, 12, 0)635 system_two = data_setup.create_system(loaned=self.user)636 system_two.date_lastcheckin = datetime.datetime(2001, 1, 16, 14, 12, 0)637 b = self.browser638 perform_search(b, [('System/LastInventoried', 'after', '2001-01-15')],639 search_url='mine')640 check_system_search_results(b, present=[system_two], absent=[system_one])641 def test_inventoried_search_is(self):642 with session.begin():643 system = data_setup.create_system(loaned=self.user)644 system.date_lastcheckin = datetime.datetime(2001, 1, 15, 14, 12, 0)645 b = self.browser646 perform_search(b, [('System/LastInventoried', 'is', '2001-01-15')],647 search_url='mine')648 check_system_search_results(b, present=[system])649 def test_inventoried_search_before(self):650 with session.begin():651 system_one = data_setup.create_system(loaned=self.user)652 system_one.date_lastcheckin = datetime.datetime(2001, 1, 15, 14, 12, 0)653 system_two = data_setup.create_system(loaned=self.user)654 system_two.date_lastcheckin = datetime.datetime(2001, 1, 14, 14, 12, 0)655 b = self.browser656 perform_search(b, [('System/LastInventoried', 'before', '2001-01-15')],657 search_url='mine')658 check_system_search_results(b, present=[system_two], absent=[system_one])659 def test_inventoried_search_range(self):660 with session.begin():661 system_one = data_setup.create_system(loaned=self.user)662 system_one.date_lastcheckin = datetime.datetime(2001, 1, 15, 14, 12, 0)663 system_two = data_setup.create_system(loaned=self.user)664 system_two.date_lastcheckin = datetime.datetime(2001, 1, 14, 14, 12, 0)665 system_three = data_setup.create_system(loaned=self.user)666 system_three.date_lastcheckin = datetime.datetime(2001, 1, 16, 14, 12, 0)667 b = self.browser668 perform_search(b, [('System/LastInventoried', 'after', '2001-01-14'),669 ('System/LastInventoried', 'before', '2001-01-16')], search_url='mine')670 check_system_search_results(b, present=[system_one],...

Full Screen

Full Screen

matchers.py

Source:matchers.py Github

copy

Full Screen

...48 def find_match(self, pattern_name, content, rule, perms):49 if pattern_name not in self.patterns:50 pattern_class = globals()[pattern_name]51 self.patterns[pattern_name] = pattern_class()52 return self.patterns[pattern_name].perform_search(content, rule, perms)53class MatchStrategy(ABC):54 @abstractclassmethod55 def perform_search(self, content, rule, perms):56 """Search for instance of match in content."""57class SingleRegex(MatchStrategy):58 def perform_search(self, content, rule, perms):59 return bool(re.findall(rule['match'], content))60class RegexAnd(MatchStrategy):61 def perform_search(self, content, rule, perms):62 # This check is used because if you only pass a str rather than a list,63 # Python will iterate through the str without raising an exception64 if isinstance(rule['match'], str):65 logger.debug('wrong regex type, switching to single regex')66 return SingleRegex().perform_search(content, rule, perms)67 for regex in rule['match']:68 if not bool(re.findall(regex, content)):69 return False70 return True71class RegexOr(MatchStrategy):72 def perform_search(self, content, rule, perms):73 if isinstance(rule['match'], str):74 logger.debug('wrong regex type, switching to single regex')75 return SingleRegex().perform_search(content, rule, perms)76 for regex in rule['match']:77 if re.findall(regex, content):78 return True79 return False80class SingleString(MatchStrategy):81 def perform_search(self, content, rule, perms):82 return rule['match'] in content83class StringAnd(MatchStrategy):84 def perform_search(self, content, rule, perms):85 for match in rule['match']:86 if match not in content:87 return False88 return True89class StringAndOr(MatchStrategy):90 def perform_search(self, content, rule, perms):91 string_or_stat = False92 or_list = rule['match'][1]93 for match in or_list:94 if match in content:95 string_or_stat = True96 break97 return string_or_stat and rule['match'][0] in content98class StringOrAndPerm(MatchStrategy):99 def perform_search(self, content, rule, perms):100 string_or_ps = False101 for match in rule['match']:102 if match in content:103 string_or_ps = True104 break105 return rule['perm'] in perms and string_or_ps106class StringAndPerm(MatchStrategy):107 def perform_search(self, content, rule, perms):108 return rule['perm'] in perms and rule['match'] in content109class StringOr(MatchStrategy):110 def perform_search(self, content, rule, perms):111 for match in rule['match']:112 if match in content:113 return True114 return False115class StringAndNot(MatchStrategy):116 def perform_search(self, content, rule, perms):...

Full Screen

Full Screen

test.py

Source:test.py Github

copy

Full Screen

...44 super(AlgoliasearchTest, self).tearDown()45 unpatch()46 if hasattr(self, 'tracer'):47 self.reset()48 def perform_search(self, query_text, query_args=None):49 if algoliasearch_version < (2, 0) and algoliasearch_version >= (1, 0):50 self.index.search(query_text, args=query_args)51 else:52 self.index.search(query_text, request_options=query_args)53 def test_algoliasearch(self):54 self.patch_algoliasearch()55 self.perform_search(56 'test search',57 {'attributesToRetrieve': 'firstname,lastname', 'unsupportedTotallyNewArgument': 'ignore'}58 )59 spans = self.get_spans()60 self.reset()61 assert len(spans) == 162 span = spans[0]63 assert span.service == 'algoliasearch'64 assert span.name == 'algoliasearch.search'65 assert span.span_type is None66 assert span.error == 067 assert span.get_tag('query.args.attributes_to_retrieve') == 'firstname,lastname'68 # Verify that adding new arguments to the search API will simply be ignored and not cause69 # errors70 assert span.get_tag('query.args.unsupported_totally_new_argument') is None71 assert span.get_metric('processing_time_ms') == 2372 assert span.get_metric('number_of_hits') == 173 # Verify query_text, which may contain sensitive data, is not passed along74 # unless the config value is appropriately set75 assert span.get_tag('query.text') is None76 def test_algoliasearch_with_query_text(self):77 self.patch_algoliasearch()78 config.algoliasearch.collect_query_text = True79 self.perform_search(80 'test search',81 {'attributesToRetrieve': 'firstname,lastname', 'unsupportedTotallyNewArgument': 'ignore'}82 )83 spans = self.get_spans()84 span = spans[0]85 assert span.get_tag('query.text') == 'test search'86 def test_patch_unpatch(self):87 self.patch_algoliasearch()88 # Test patch idempotence89 patch()90 patch()91 self.perform_search('test search')92 spans = self.get_spans()93 self.reset()94 assert spans, spans95 assert len(spans) == 196 # Test unpatch97 unpatch()98 self.index.search('test search')99 spans = self.get_spans()100 self.reset()101 assert not spans, spans102 # Test patch again103 self.reset()104 patch()105 self.index.search('test search')106 spans = self.get_spans()107 assert spans, spans108 assert len(spans) == 1109 def test_patch_all_auto_enable(self):110 patch_all()111 Pin.override(self.index, tracer=self.tracer)112 self.perform_search('test search')113 spans = self.get_spans()114 self.reset()115 assert spans, spans116 assert len(spans) == 1117 unpatch()118 self.perform_search('test search')119 spans = self.get_spans()...

Full Screen

Full Screen

spending_by_category.py

Source:spending_by_category.py Github

copy

Full Screen

1import copy2import logging3from django.conf import settings4from rest_framework.request import Request5from rest_framework.response import Response6from rest_framework.views import APIView7from usaspending_api.common.api_versioning import api_transformations, API_TRANSFORM_FUNCTIONS8from usaspending_api.common.cache_decorator import cache_response9from usaspending_api.common.exceptions import NotImplementedException10from usaspending_api.common.validator.award_filter import AWARD_FILTER11from usaspending_api.common.validator.pagination import PAGINATION12from usaspending_api.common.validator.tinyshield import TinyShield13from usaspending_api.search.v2.views.spending_by_category_views.spending_by_agency_types import (14 AwardingAgencyViewSet,15 AwardingSubagencyViewSet,16 FundingAgencyViewSet,17 FundingSubagencyViewSet,18)19from usaspending_api.search.v2.views.spending_by_category_views.spending_by_industry_codes import (20 CfdaViewSet,21 PSCViewSet,22 NAICSViewSet,23)24from usaspending_api.search.v2.views.spending_by_category_views.spending_by_federal_account import FederalAccountViewSet25from usaspending_api.search.v2.views.spending_by_category_views.spending_by_locations import (26 CountyViewSet,27 CountryViewSet,28 DistrictViewSet,29 StateTerritoryViewSet,30)31from usaspending_api.search.v2.views.spending_by_category_views.spending_by_recipient import (32 RecipientViewSet,33 RecipientDunsViewSet,34)35logger = logging.getLogger(__name__)36API_VERSION = settings.API_VERSION37@api_transformations(api_version=API_VERSION, function_list=API_TRANSFORM_FUNCTIONS)38class SpendingByCategoryVisualizationViewSet(APIView):39 """40 This route takes award filters, and returns spending by the defined category/scope.41 The category is defined by the category keyword, and the scope is defined by is denoted by the scope keyword.42 """43 endpoint_doc = "usaspending_api/api_contracts/contracts/v2/search/spending_by_category.md"44 @cache_response()45 def post(self, request: Request) -> Response:46 """Return all budget function/subfunction titles matching the provided search text"""47 categories = [48 "awarding_agency",49 "awarding_subagency",50 "funding_agency",51 "funding_subagency",52 "recipient",53 "recipient_duns",54 "recipient_parent_duns",55 "cfda",56 "psc",57 "naics",58 "county",59 "district",60 "country",61 "state_territory",62 "federal_account",63 ]64 models = [65 {"name": "category", "key": "category", "type": "enum", "enum_values": categories, "optional": False},66 {"name": "subawards", "key": "subawards", "type": "boolean", "default": False, "optional": True},67 ]68 models.extend(copy.deepcopy(AWARD_FILTER))69 models.extend(copy.deepcopy(PAGINATION))70 # Apply/enforce POST body schema and data validation in request71 original_filters = request.data.get("filters")72 validated_payload = TinyShield(models).block(request.data)73 # Execute the business logic for the endpoint and return a python dict to be converted to a Django response74 business_logic_lookup = {75 "awarding_agency": AwardingAgencyViewSet().perform_search,76 "awarding_subagency": AwardingSubagencyViewSet().perform_search,77 "cfda": CfdaViewSet().perform_search,78 "country": CountryViewSet().perform_search,79 "county": CountyViewSet().perform_search,80 "district": DistrictViewSet().perform_search,81 "federal_account": FederalAccountViewSet().perform_search,82 "funding_agency": FundingAgencyViewSet().perform_search,83 "funding_subagency": FundingSubagencyViewSet().perform_search,84 "naics": NAICSViewSet().perform_search,85 "psc": PSCViewSet().perform_search,86 "recipient": RecipientViewSet().perform_search,87 "recipient_duns": RecipientDunsViewSet().perform_search,88 "state_territory": StateTerritoryViewSet().perform_search,89 }90 business_logic_func = business_logic_lookup.get(validated_payload["category"])91 if business_logic_func:92 return Response(business_logic_func(validated_payload, original_filters))93 else:94 self.raise_not_implemented(validated_payload)95 @staticmethod96 def raise_not_implemented(payload):97 msg = f"Category '{payload['category']}' is not implemented"...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Wtframework automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful