当前位置: 首页>>代码示例>>Python>>正文


Python BloodhoundSearchApi.upgrade_environment方法代码示例

本文整理汇总了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)
开发者ID:mohsadki,项目名称:dargest,代码行数:44,代码来源:search.py

示例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')
#.........这里部分代码省略.........
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:103,代码来源:api.py

示例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')
#.........这里部分代码省略.........
开发者ID:mohsadki,项目名称:dargest,代码行数:103,代码来源:api.py


注:本文中的bhsearch.api.BloodhoundSearchApi.upgrade_environment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。