本文整理汇总了Python中bhsearch.api.BloodhoundSearchApi.upgrade_environment方法的典型用法代码示例。如果您正苦于以下问题:Python BloodhoundSearchApi.upgrade_environment方法的具体用法?Python BloodhoundSearchApi.upgrade_environment怎么用?Python BloodhoundSearchApi.upgrade_environment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bhsearch.api.BloodhoundSearchApi
的用法示例。
在下文中一共展示了BloodhoundSearchApi.upgrade_environment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SearchIntegrationTestCase
# 需要导入模块: from bhsearch.api import BloodhoundSearchApi [as 别名]
# 或者: from bhsearch.api.BloodhoundSearchApi import upgrade_environment [as 别名]
class SearchIntegrationTestCase(BaseRelationsTestCase):
def setUp(self):
BaseRelationsTestCase.setUp(self, enabled=['bhsearch.*'])
self.global_env.path = tempfile.mkdtemp('bhrelations-tempenv')
self.search_api = BloodhoundSearchApi(self.env)
self.search_api.upgrade_environment(self.env.db_transaction)
def tearDown(self):
shutil.rmtree(self.env.path)
BaseRelationsTestCase.tearDown(self)
def test_relations_are_indexed_on_creation(self):
t1 = self._insert_and_load_ticket("Foo")
t2 = self._insert_and_load_ticket("Bar")
self.add_relation(t1, DEPENDENCY_OF, t2)
result = self.search_api.query('%s:#2' % DEPENDENCY_OF)
self.assertEqual(result.hits, 1)
def test_relations_are_indexed_on_deletion(self):
t1 = self._insert_and_load_ticket("Foo")
t2 = self._insert_and_load_ticket("Bar")
self.add_relation(t1, DEPENDENCY_OF, t2)
relations = self.get_relations(t1)
self.relations_system.delete(relations[0]["relation_id"])
result = self.search_api.query('%s:#2' % DEPENDENCY_OF)
self.assertEqual(result.hits, 0)
def test_different_types_of_queries(self):
t1 = self._insert_and_load_ticket("Foo")
t2 = self._insert_and_load_ticket("Bar")
self.add_relation(t1, DEPENDENCY_OF, t2)
self.assertEqual(self.search_api.query('%s:#2'
% DEPENDENCY_OF).hits, 1)
self.assertEqual(self.search_api.query('%s:#tp1-2'
% DEPENDENCY_OF).hits, 1)
示例2: ApiQueryWithWhooshTestCase
# 需要导入模块: from bhsearch.api import BloodhoundSearchApi [as 别名]
# 或者: from bhsearch.api.BloodhoundSearchApi import upgrade_environment [as 别名]
class ApiQueryWithWhooshTestCase(BaseBloodhoundSearchTest):
def setUp(self):
super(ApiQueryWithWhooshTestCase, self).setUp(create_req=True)
WhooshBackend(self.env).recreate_index()
self.search_api = BloodhoundSearchApi(self.env)
self.ticket_participant = TicketSearchParticipant(self.env)
self.query_parser = DefaultQueryParser(self.env)
def tearDown(self):
shutil.rmtree(self.env.path)
self.env.reset_db()
def test_can_search_free_description(self):
#arrange
self.insert_ticket("dummy summary", description="aaa keyword bla")
#act
results = self.search_api.query("keyword")
#assert
self.print_result(results)
self.assertEqual(1, results.hits)
def test_can_query_free_summary(self):
#arrange
self.insert_ticket("summary1 keyword")
#act
results = self.search_api.query("keyword")
#assert
self.print_result(results)
self.assertEqual(1, results.hits)
def test_can_query_strict_summary(self):
#arrange
self.insert_ticket("summary1 keyword")
self.insert_ticket("summary2", description = "bla keyword")
#act
results = self.search_api.query("summary:keyword")
#assert
self.print_result(results)
self.assertEqual(1, results.hits)
def test_that_summary_hit_is_higher_than_description(self):
#arrange
self.insert_ticket("summary1 keyword")
self.insert_ticket("summary2", description = "bla keyword")
#act
results = self.search_api.query("keyword")
self.print_result(results)
#assert
self.assertEqual(2, results.hits)
docs = results.docs
self.assertEqual("summary1 keyword", docs[0]["summary"])
self.assertEqual("summary2", docs[1]["summary"])
def test_other_conditions_applied(self):
#arrange
self.insert_ticket("summary1 keyword", status="closed")
self.insert_ticket("summary2", description = "bla keyword")
self.insert_ticket("summary3", status="closed")
#act
results = self.search_api.query("keyword status:closed")
self.print_result(results)
#assert
self.assertEqual(1, results.hits)
docs = results.docs
self.assertEqual("summary1 keyword", docs[0]["summary"])
def test_that_filter_queries_applied(self):
#arrange
self.insert_ticket("t1", status="closed", component = "c1")
self.insert_ticket("t2", status="closed", component = "c1")
self.insert_ticket("t3", status="closed",
component = "NotInFilterCriteria")
#act
results = self.search_api.query(
"*",
filter= ['status:"closed"', 'component:"c1"'],
sort= [SortInstruction("id", ASC)]
)
self.print_result(results)
#assert
self.assertEqual(2, results.hits)
docs = results.docs
self.assertEqual("t1", docs[0]["summary"])
self.assertEqual("t2", docs[1]["summary"])
def test_that_upgrading_environment_adds_documents_to_index(self):
self.insert_ticket("t1")
self.insert_ticket("t2")
self.search_api.upgrade_environment(self.env.db_transaction)
results = self.search_api.query("type:ticket")
self.assertEqual(2, results.hits)
def test_can_index_wiki_with_same_id_from_different_products(self):
with self.product('p1'):
self.insert_wiki('title', 'content')
with self.product('p2'):
self.insert_wiki('title', 'content 2')
#.........这里部分代码省略.........
示例3: ApiQueryWithWhooshTestCase
# 需要导入模块: from bhsearch.api import BloodhoundSearchApi [as 别名]
# 或者: from bhsearch.api.BloodhoundSearchApi import upgrade_environment [as 别名]
class ApiQueryWithWhooshTestCase(BaseBloodhoundSearchTest):
def setUp(self):
super(ApiQueryWithWhooshTestCase, self).setUp(create_req=True)
WhooshBackend(self.env).recreate_index()
self.search_api = BloodhoundSearchApi(self.env)
self.ticket_participant = TicketSearchParticipant(self.env)
self.query_parser = DefaultQueryParser(self.env)
def tearDown(self):
shutil.rmtree(self.env.path)
self.env.reset_db()
def test_can_search_free_description(self):
#arrange
self.insert_ticket("dummy summary", description="aaa keyword bla")
#act
results = self.search_api.query("keyword")
#assert
self.print_result(results)
self.assertEqual(1, results.hits)
def test_can_query_free_summary(self):
#arrange
self.insert_ticket("summary1 keyword")
#act
results = self.search_api.query("keyword")
#assert
self.print_result(results)
self.assertEqual(1, results.hits)
def test_can_query_strict_summary(self):
#arrange
self.insert_ticket("summary1 keyword")
self.insert_ticket("summary2", description = "bla keyword")
#act
results = self.search_api.query("summary:keyword")
#assert
self.print_result(results)
self.assertEqual(1, results.hits)
def test_that_summary_hit_is_higher_than_description(self):
#arrange
self.insert_ticket("summary1 keyword")
self.insert_ticket("summary2", description = "bla keyword")
#act
results = self.search_api.query("keyword")
self.print_result(results)
#assert
self.assertEqual(2, results.hits)
docs = results.docs
self.assertEqual("summary1 keyword", docs[0]["summary"])
self.assertEqual("summary2", docs[1]["summary"])
def test_other_conditions_applied(self):
#arrange
self.insert_ticket("summary1 keyword", status="closed")
self.insert_ticket("summary2", description = "bla keyword")
self.insert_ticket("summary3", status="closed")
#act
results = self.search_api.query("keyword status:closed")
self.print_result(results)
#assert
self.assertEqual(1, results.hits)
docs = results.docs
self.assertEqual("summary1 keyword", docs[0]["summary"])
def test_that_filter_queries_applied(self):
#arrange
self.insert_ticket("t1", status="closed", component = "c1")
self.insert_ticket("t2", status="closed", component = "c1")
self.insert_ticket("t3", status="closed",
component = "NotInFilterCriteria")
#act
results = self.search_api.query(
"*",
filter= ['status:"closed"', 'component:"c1"'],
sort= [SortInstruction("id", ASC)]
)
self.print_result(results)
#assert
self.assertEqual(2, results.hits)
docs = results.docs
self.assertEqual("t1", docs[0]["summary"])
self.assertEqual("t2", docs[1]["summary"])
def test_that_upgrading_environment_adds_documents_to_index(self):
self.insert_ticket("t1")
self.insert_ticket("t2")
self.search_api.upgrade_environment(self.env.db_transaction)
results = self.search_api.query("type:ticket")
self.assertEqual(2, results.hits)
def test_can_index_wiki_with_same_id_from_different_products(self):
with self.product('p1'):
self.insert_wiki('title', 'content')
with self.product('p2'):
self.insert_wiki('title', 'content 2')
#.........这里部分代码省略.........