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


Python SuperSearch.get方法代码示例

本文整理汇总了Python中socorro.external.elasticsearch.supersearch.SuperSearch.get方法的典型用法代码示例。如果您正苦于以下问题:Python SuperSearch.get方法的具体用法?Python SuperSearch.get怎么用?Python SuperSearch.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在socorro.external.elasticsearch.supersearch.SuperSearch的用法示例。


在下文中一共展示了SuperSearch.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_with_range_operators

# 需要导入模块: from socorro.external.elasticsearch.supersearch import SuperSearch [as 别名]
# 或者: from socorro.external.elasticsearch.supersearch.SuperSearch import get [as 别名]
    def test_get_with_range_operators(self):
        """Test a search with several filters and operators returns expected
        results. """
        with _get_config_manager(self.config).context() as config:
            api = SuperSearch(config)

        # Test date
        now = datetimeutil.utc_now()
        lastweek = now - datetime.timedelta(days=7)
        lastmonth = lastweek - datetime.timedelta(weeks=4)
        args = {"date": ["<%s" % lastweek, ">=%s" % lastmonth]}
        res = api.get(**args)
        self.assertEqual(res["total"], 1)
        self.assertEqual(res["hits"][0]["signature"], "my_little_signature")

        # Test build id
        args = {"build_id": "<1234567890"}
        res = api.get(**args)
        self.assertEqual(res["total"], 1)
        self.assertEqual(res["hits"][0]["signature"], "js::break_your_browser")
        self.assertTrue(res["hits"][0]["build_id"] < 1234567890)

        args = {"build_id": ">1234567889"}
        res = api.get(**args)
        self.assertEqual(res["total"], 20)
        self.assertTrue(res["hits"])
        for report in res["hits"]:
            self.assertTrue(report["build_id"] > 1234567889)

        args = {"build_id": "<=1234567890"}
        res = api.get(**args)
        self.assertEqual(res["total"], 21)
        self.assertTrue(res["hits"])
        for report in res["hits"]:
            self.assertTrue(report["build_id"] <= 1234567890)
开发者ID:vfazio,项目名称:socorro,代码行数:37,代码来源:test_supersearch.py

示例2: test_get_with_pagination

# 需要导入模块: from socorro.external.elasticsearch.supersearch import SuperSearch [as 别名]
# 或者: from socorro.external.elasticsearch.supersearch.SuperSearch import get [as 别名]
    def test_get_with_pagination(self):
        """Test a search with pagination returns expected results. """
        with _get_config_manager().context() as config:
            api = SuperSearch(config)

        args = {
            '_results_number': '10',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 21)
        self.assertEqual(len(res['hits']), 10)

        args = {
            '_results_number': '10',
            '_results_offset': '10',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 21)
        self.assertEqual(len(res['hits']), 10)

        args = {
            '_results_number': '10',
            '_results_offset': '15',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 21)
        self.assertEqual(len(res['hits']), 6)

        args = {
            '_results_number': '10',
            '_results_offset': '30',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 21)
        self.assertEqual(len(res['hits']), 0)
开发者ID:GabiThume,项目名称:socorro,代码行数:37,代码来源:test_supersearch.py

示例3: test_get

# 需要导入模块: from socorro.external.elasticsearch.supersearch import SuperSearch [as 别名]
# 或者: from socorro.external.elasticsearch.supersearch.SuperSearch import get [as 别名]
    def test_get(self):
        """Test a search with default values returns the right structure. """
        with _get_config_manager().context() as config:
            api = SuperSearch(config)

        res = api.get()

        self.assertTrue('total' in res)
        self.assertEqual(res['total'], 21)

        self.assertTrue('hits' in res)
        self.assertEqual(len(res['hits']), res['total'])

        self.assertTrue('facets' in res)
        self.assertTrue('signature' in res['facets'])

        expected_signatures = [
            {'term': 'js::break_your_browser', 'count': 20},
            {'term': 'my_bad', 'count': 1},
        ]
        self.assertEqual(res['facets']['signature'], expected_signatures)

        # Test fields are being renamed
        self.assertTrue('date' in res['hits'][0])  # date_processed > date
        self.assertTrue('build_id' in res['hits'][0])  # build > build_id
        self.assertTrue('platform' in res['hits'][0])  # os_name > platform
开发者ID:GabiThume,项目名称:socorro,代码行数:28,代码来源:test_supersearch.py

示例4: test_get_with_range_operators

# 需要导入模块: from socorro.external.elasticsearch.supersearch import SuperSearch [as 别名]
# 或者: from socorro.external.elasticsearch.supersearch.SuperSearch import get [as 别名]
    def test_get_with_range_operators(self):
        """Test a search with several filters and operators returns expected
        results. """
        with _get_config_manager().context() as config:
            api = SuperSearch(config)

        # Test date
        now = datetimeutil.utc_now()
        lastweek = now - datetime.timedelta(days=7)
        lastmonth = lastweek - datetime.timedelta(weeks=4)
        args = {
            'date': [
                '<%s' % lastweek,
                '>=%s' % lastmonth,
            ]
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 1)
        self.assertEqual(res['hits'][0]['signature'], 'my_little_signature')

        # Test build id
        args = {
            'build_id': '<1234567890',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 1)
        self.assertEqual(res['hits'][0]['signature'], 'js::break_your_browser')
        self.assertTrue(res['hits'][0]['build'] < 1234567890)

        args = {
            'build_id': '>1234567889',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 20)
        self.assertTrue(res['hits'])
        for report in res['hits']:
            self.assertTrue(report['build'] > 1234567889)

        args = {
            'build_id': '<=1234567890',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 21)
        self.assertTrue(res['hits'])
        for report in res['hits']:
            self.assertTrue(report['build'] <= 1234567890)
开发者ID:GabiThume,项目名称:socorro,代码行数:48,代码来源:test_supersearch.py

示例5: test_get_with_not_operator

# 需要导入模块: from socorro.external.elasticsearch.supersearch import SuperSearch [as 别名]
# 或者: from socorro.external.elasticsearch.supersearch.SuperSearch import get [as 别名]
    def test_get_with_not_operator(self):
        """Test a search with a few NOT operators. """
        with _get_config_manager(self.config).context() as config:
            api = SuperSearch(config)

        # Test signature
        args = {"signature": ["js", "break_your_browser"]}
        res = api.get(**args)
        self.assertEqual(res["total"], 20)
        self.assertTrue(res["hits"])
        for report in res["hits"]:
            self.assertEqual(report["signature"], "js::break_your_browser")

        # - Test contains mode
        args = {"signature": "!~bad"}
        res = api.get(**args)
        self.assertEqual(res["total"], 20)

        # - Test is_exactly mode
        args = {"signature": "!=js::break_your_browser"}
        res = api.get(**args)
        self.assertEqual(res["total"], 1)
        self.assertEqual(res["hits"][0]["signature"], "my_bad")

        # - Test starts_with mode
        args = {"signature": "!$js"}
        res = api.get(**args)
        self.assertEqual(res["total"], 1)
        self.assertEqual(res["hits"][0]["signature"], "my_bad")

        # - Test ends_with mode
        args = {"signature": "!^browser"}
        res = api.get(**args)
        self.assertEqual(res["total"], 1)
        self.assertEqual(res["hits"][0]["signature"], "my_bad")

        # Test build id
        args = {"build_id": "!<1234567890"}
        res = api.get(**args)
        self.assertEqual(res["total"], 20)
        self.assertTrue(res["hits"])
        for report in res["hits"]:
            self.assertTrue(report["build_id"] > 1234567889)

        args = {"build_id": "!>1234567889"}
        res = api.get(**args)
        self.assertEqual(res["total"], 1)
        self.assertEqual(res["hits"][0]["signature"], "js::break_your_browser")
        self.assertTrue(res["hits"][0]["build_id"] < 1234567890)

        args = {"build_id": "!<=1234567890"}
        res = api.get(**args)
        self.assertEqual(res["total"], 0)
开发者ID:vfazio,项目名称:socorro,代码行数:55,代码来源:test_supersearch.py

示例6: test_get_with_facets

# 需要导入模块: from socorro.external.elasticsearch.supersearch import SuperSearch [as 别名]
# 或者: from socorro.external.elasticsearch.supersearch.SuperSearch import get [as 别名]
    def test_get_with_facets(self):
        """Test a search with facets returns expected results. """
        with _get_config_manager(self.config).context() as config:
            api = SuperSearch(config)

        # Test several facets
        args = {"_facets": ["signature", "platform"]}
        res = api.get(**args)

        self.assertTrue("facets" in res)
        self.assertTrue("signature" in res["facets"])

        expected_signatures = [{"term": "js::break_your_browser", "count": 20}, {"term": "my_bad", "count": 1}]
        self.assertEqual(res["facets"]["signature"], expected_signatures)

        self.assertTrue("platform" in res["facets"])
        expected_platforms = [{"term": "Linux", "count": 20}, {"term": "Windows NT", "count": 1}]
        self.assertEqual(res["facets"]["platform"], expected_platforms)

        # Test one facet with filters
        args = {"_facets": ["release_channel"], "release_channel": "aurora"}
        res = api.get(**args)

        self.assertTrue("release_channel" in res["facets"])

        expected_signatures = [{"term": "aurora", "count": 1}]
        self.assertEqual(res["facets"]["release_channel"], expected_signatures)

        # Test one facet with a different filter
        args = {"_facets": ["release_channel"], "platform": "linux"}
        res = api.get(**args)

        self.assertTrue("release_channel" in res["facets"])

        expected_signatures = [{"term": "release", "count": 19}, {"term": "aurora", "count": 1}]
        self.assertEqual(res["facets"]["release_channel"], expected_signatures)

        # Test errors
        self.assertRaises(BadArgumentError, api.get, _facets=["unkownfield"])
开发者ID:vfazio,项目名称:socorro,代码行数:41,代码来源:test_supersearch.py

示例7: test_get_with_pagination

# 需要导入模块: from socorro.external.elasticsearch.supersearch import SuperSearch [as 别名]
# 或者: from socorro.external.elasticsearch.supersearch.SuperSearch import get [as 别名]
    def test_get_with_pagination(self):
        """Test a search with pagination returns expected results. """
        with _get_config_manager(self.config).context() as config:
            api = SuperSearch(config)

        args = {"_results_number": "10"}
        res = api.get(**args)
        self.assertEqual(res["total"], 21)
        self.assertEqual(len(res["hits"]), 10)

        args = {"_results_number": "10", "_results_offset": "10"}
        res = api.get(**args)
        self.assertEqual(res["total"], 21)
        self.assertEqual(len(res["hits"]), 10)

        args = {"_results_number": "10", "_results_offset": "15"}
        res = api.get(**args)
        self.assertEqual(res["total"], 21)
        self.assertEqual(len(res["hits"]), 6)

        args = {"_results_number": "10", "_results_offset": "30"}
        res = api.get(**args)
        self.assertEqual(res["total"], 21)
        self.assertEqual(len(res["hits"]), 0)
开发者ID:vfazio,项目名称:socorro,代码行数:26,代码来源:test_supersearch.py

示例8: test_get

# 需要导入模块: from socorro.external.elasticsearch.supersearch import SuperSearch [as 别名]
# 或者: from socorro.external.elasticsearch.supersearch.SuperSearch import get [as 别名]
    def test_get(self):
        """Test a search with default values returns the right structure. """
        with _get_config_manager(self.config).context() as config:
            api = SuperSearch(config)

        res = api.get()

        self.assertTrue("total" in res)
        self.assertEqual(res["total"], 21)

        self.assertTrue("hits" in res)
        self.assertEqual(len(res["hits"]), res["total"])

        self.assertTrue("facets" in res)
        self.assertTrue("signature" in res["facets"])

        expected_signatures = [{"term": "js::break_your_browser", "count": 20}, {"term": "my_bad", "count": 1}]
        self.assertEqual(res["facets"]["signature"], expected_signatures)

        # Test fields are being renamed
        self.assertTrue("date" in res["hits"][0])  # date_processed > date
        self.assertTrue("build_id" in res["hits"][0])  # build > build_id
        self.assertTrue("platform" in res["hits"][0])  # os_name > platform
开发者ID:vfazio,项目名称:socorro,代码行数:25,代码来源:test_supersearch.py

示例9: test_get_with_facets

# 需要导入模块: from socorro.external.elasticsearch.supersearch import SuperSearch [as 别名]
# 或者: from socorro.external.elasticsearch.supersearch.SuperSearch import get [as 别名]
    def test_get_with_facets(self):
        """Test a search with facets returns expected results. """
        with _get_config_manager().context() as config:
            api = SuperSearch(config)

        # Test several facets
        args = {
            '_facets': ['signature', 'platform']
        }
        res = api.get(**args)

        self.assertTrue('facets' in res)
        self.assertTrue('signature' in res['facets'])

        expected_signatures = [
            {'term': 'js::break_your_browser', 'count': 20},
            {'term': 'my_bad', 'count': 1},
        ]
        self.assertEqual(res['facets']['signature'], expected_signatures)

        self.assertTrue('platform' in res['facets'])
        expected_platforms = [
            {'term': 'linux', 'count': 20},
            {'term': 'windows', 'count': 1},
            {'term': 'nt', 'count': 1},
        ]
        self.assertEqual(res['facets']['platform'], expected_platforms)

        # Test one facet with filters
        args = {
            '_facets': ['release_channel'],
            'release_channel': 'aurora',
        }
        res = api.get(**args)

        self.assertTrue('release_channel' in res['facets'])

        expected_signatures = [
            {'term': 'aurora', 'count': 1},
        ]
        self.assertEqual(res['facets']['release_channel'], expected_signatures)

        # Test one facet with a different filter
        args = {
            '_facets': ['release_channel'],
            'platform': 'linux',
        }
        res = api.get(**args)

        self.assertTrue('release_channel' in res['facets'])

        expected_signatures = [
            {'term': 'release', 'count': 19},
            {'term': 'aurora', 'count': 1},
        ]
        self.assertEqual(res['facets']['release_channel'], expected_signatures)

        # Test errors
        self.assertRaises(
            BadArgumentError,
            api.get,
            _facets=['unkownfield']
        )
开发者ID:GabiThume,项目名称:socorro,代码行数:65,代码来源:test_supersearch.py

示例10: test_get_with_string_operators

# 需要导入模块: from socorro.external.elasticsearch.supersearch import SuperSearch [as 别名]
# 或者: from socorro.external.elasticsearch.supersearch.SuperSearch import get [as 别名]
    def test_get_with_string_operators(self):
        """Test a search with several filters and operators returns expected
        results. """
        with _get_config_manager().context() as config:
            api = SuperSearch(config)

        # Test signature
        args = {
            'signature': ['js', 'break_your_browser'],
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 20)
        self.assertTrue(res['hits'])
        for report in res['hits']:
            self.assertEqual(report['signature'], 'js::break_your_browser')

        # - Test contains mode
        args = {
            'signature': '~bad',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 1)
        self.assertEqual(res['hits'][0]['signature'], 'my_bad')

        args = {
            'signature': '~js::break',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 20)
        self.assertTrue(res['hits'])
        for report in res['hits']:
            self.assertEqual(report['signature'], 'js::break_your_browser')

        # - Test is_exactly mode
        args = {
            'signature': '=js::break_your_browser',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 20)
        self.assertTrue(res['hits'])
        for report in res['hits']:
            self.assertEqual(report['signature'], 'js::break_your_browser')

        args = {
            'signature': '=my_bad',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 1)
        self.assertEqual(res['hits'][0]['signature'], 'my_bad')

        # - Test starts_with mode
        args = {
            'signature': '$js',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 20)
        self.assertTrue(res['hits'])
        for report in res['hits']:
            self.assertEqual(report['signature'], 'js::break_your_browser')

        # - Test ends_with mode
        args = {
            'signature': '^browser',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 20)
        self.assertTrue(res['hits'])
        for report in res['hits']:
            self.assertEqual(report['signature'], 'js::break_your_browser')

        # Test email
        args = {
            'email': ['gmail', 'hotmail'],
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 19)
        self.assertTrue(res['hits'])
        for report in res['hits']:
            self.assertTrue('@' in report['email'])
            self.assertTrue('mail.com' in report['email'])

        args = {
            'email': '~mail.com',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 19)
        self.assertTrue(res['hits'])
        for report in res['hits']:
            self.assertTrue('@' in report['email'])
            self.assertTrue('mail.com' in report['email'])

        args = {
            'email': '[email protected]',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 2)
        self.assertTrue(res['hits'])
        for report in res['hits']:
            self.assertTrue('[email protected]' in report['email'])

#.........这里部分代码省略.........
开发者ID:GabiThume,项目名称:socorro,代码行数:103,代码来源:test_supersearch.py

示例11: test_get_individual_filters

# 需要导入模块: from socorro.external.elasticsearch.supersearch import SuperSearch [as 别名]
# 或者: from socorro.external.elasticsearch.supersearch.SuperSearch import get [as 别名]
    def test_get_individual_filters(self):
        """Test a search with single filters returns expected results. """
        with _get_config_manager().context() as config:
            api = SuperSearch(config)

        # Test signature
        args = {
            'signature': 'my_bad',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 1)
        self.assertEqual(res['hits'][0]['signature'], 'my_bad')

        # Test product
        args = {
            'product': 'EarthRaccoon',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 1)
        self.assertEqual(res['hits'][0]['signature'], 'js::break_your_browser')
        self.assertEqual(res['hits'][0]['product'], 'EarthRaccoon')

        # Test version
        args = {
            'version': '2.0',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 1)
        self.assertEqual(res['hits'][0]['signature'], 'js::break_your_browser')
        self.assertEqual(res['hits'][0]['version'], '2.0')

        # Test release_channel
        args = {
            'release_channel': 'aurora',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 1)
        self.assertEqual(res['hits'][0]['signature'], 'js::break_your_browser')
        self.assertEqual(res['hits'][0]['release_channel'], 'aurora')

        # Test platform
        args = {
            'platform': 'Windows',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 1)
        self.assertEqual(res['hits'][0]['signature'], 'js::break_your_browser')
        self.assertEqual(res['hits'][0]['os_name'], 'Windows NT')

        # Test build_id
        args = {
            'build_id': '987654321',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 1)
        self.assertEqual(res['hits'][0]['signature'], 'js::break_your_browser')
        self.assertEqual(res['hits'][0]['build'], 987654321)

        # Test reason
        args = {
            'reason': 'MOZALLOC_WENT_WRONG',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 20)
        self.assertEqual(res['hits'][0]['reason'], 'MOZALLOC_WENT_WRONG')

        args = {
            'reason': ['very_bad_exception'],
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 1)
        self.assertEqual(res['hits'][0]['signature'], 'js::break_your_browser')
        self.assertEqual(res['hits'][0]['reason'], 'VERY_BAD_EXCEPTION')

        # Test process_type
        args = {
            'process_type': 'plugin',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 3)
        self.assertEqual(res['hits'][0]['signature'], 'js::break_your_browser')
        self.assertEqual(res['hits'][0]['process_type'], 'plugin')

        # Test url
        args = {
            'url': 'mozilla',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 20)
        self.assertEqual(res['hits'][0]['signature'], 'js::break_your_browser')
        self.assertTrue('mozilla.org' in res['hits'][0]['url'])

        # Test user_comments
        args = {
            'user_comments': 'WaterWolf',
        }
        res = api.get(**args)
        self.assertEqual(res['total'], 2)
        self.assertEqual(res['hits'][0]['signature'], 'js::break_your_browser')
        self.assertTrue('WaterWolf' in res['hits'][0]['user_comments'])
#.........这里部分代码省略.........
开发者ID:GabiThume,项目名称:socorro,代码行数:103,代码来源:test_supersearch.py

示例12: test_get_individual_filters

# 需要导入模块: from socorro.external.elasticsearch.supersearch import SuperSearch [as 别名]
# 或者: from socorro.external.elasticsearch.supersearch.SuperSearch import get [as 别名]
    def test_get_individual_filters(self):
        """Test a search with single filters returns expected results. """
        with _get_config_manager(self.config).context() as config:
            api = SuperSearch(config)

        # Test signature
        args = {"signature": "my_bad"}
        res = api.get(**args)
        self.assertEqual(res["total"], 1)
        self.assertEqual(res["hits"][0]["signature"], "my_bad")

        # Test product
        args = {"product": "EarthRaccoon"}
        res = api.get(**args)
        self.assertEqual(res["total"], 1)
        self.assertEqual(res["hits"][0]["signature"], "js::break_your_browser")
        self.assertEqual(res["hits"][0]["product"], "EarthRaccoon")

        # Test version
        args = {"version": "2.0"}
        res = api.get(**args)
        self.assertEqual(res["total"], 1)
        self.assertEqual(res["hits"][0]["signature"], "js::break_your_browser")
        self.assertEqual(res["hits"][0]["version"], "2.0")

        # Test release_channel
        args = {"release_channel": "aurora"}
        res = api.get(**args)
        self.assertEqual(res["total"], 1)
        self.assertEqual(res["hits"][0]["signature"], "js::break_your_browser")
        self.assertEqual(res["hits"][0]["release_channel"], "aurora")

        # Test platform
        args = {"platform": "Windows"}
        res = api.get(**args)
        self.assertEqual(res["total"], 1)
        self.assertEqual(res["hits"][0]["signature"], "js::break_your_browser")
        self.assertEqual(res["hits"][0]["platform"], "Windows NT")

        # Test build_id
        args = {"build_id": "987654321"}
        res = api.get(**args)
        self.assertEqual(res["total"], 1)
        self.assertEqual(res["hits"][0]["signature"], "js::break_your_browser")
        self.assertEqual(res["hits"][0]["build_id"], 987654321)

        # Test reason
        args = {"reason": "MOZALLOC_WENT_WRONG"}
        res = api.get(**args)
        self.assertEqual(res["total"], 20)
        self.assertEqual(res["hits"][0]["reason"], "MOZALLOC_WENT_WRONG")

        args = {"reason": ["very_bad_exception"]}
        res = api.get(**args)
        self.assertEqual(res["total"], 1)
        self.assertEqual(res["hits"][0]["signature"], "js::break_your_browser")
        self.assertEqual(res["hits"][0]["reason"], "VERY_BAD_EXCEPTION")

        # Test process_type
        args = {"process_type": "plugin"}
        res = api.get(**args)
        self.assertEqual(res["total"], 3)
        self.assertEqual(res["hits"][0]["signature"], "js::break_your_browser")
        self.assertEqual(res["hits"][0]["process_type"], "plugin")

        # Test url
        args = {"url": "https://mozilla.org"}
        res = api.get(**args)
        self.assertEqual(res["total"], 19)
        self.assertEqual(res["hits"][0]["signature"], "js::break_your_browser")
        self.assertTrue("mozilla.org" in res["hits"][0]["url"])

        # Test user_comments
        args = {"user_comments": "WaterWolf"}
        res = api.get(**args)
        self.assertEqual(res["total"], 2)
        self.assertEqual(res["hits"][0]["signature"], "js::break_your_browser")
        self.assertTrue("WaterWolf" in res["hits"][0]["user_comments"])

        # Test address
        args = {"address": "0x0"}
        res = api.get(**args)
        self.assertEqual(res["total"], 20)
        self.assertTrue("0x0" in res["hits"][0]["address"])
开发者ID:vfazio,项目名称:socorro,代码行数:86,代码来源:test_supersearch.py

示例13: IntegrationTestSuperSearch

# 需要导入模块: from socorro.external.elasticsearch.supersearch import SuperSearch [as 别名]
# 或者: from socorro.external.elasticsearch.supersearch.SuperSearch import get [as 别名]
class IntegrationTestSuperSearch(ElasticSearchTestCase):
    """Test SuperSearch with an elasticsearch database containing fake data.
    """

    def setUp(self):
        super(IntegrationTestSuperSearch, self).setUp()

        config = self.get_config_context()
        self.api = SuperSearch(config=config)
        self.storage = crashstorage.ElasticSearchCrashStorage(config)

        # clear the indices cache so the index is created on every test
        self.storage.indices_cache = set()

        now = datetimeutil.utc_now()

        yesterday = now - datetime.timedelta(days=1)
        yesterday = datetimeutil.date_to_string(yesterday)

        last_month = now - datetime.timedelta(weeks=4)
        last_month = datetimeutil.date_to_string(last_month)

        # insert data into elasticsearch
        default_crash_report = {
            'uuid': 100,
            'address': '0x0',
            'signature': 'js::break_your_browser',
            'date_processed': yesterday,
            'product': 'WaterWolf',
            'version': '1.0',
            'release_channel': 'release',
            'os_name': 'Linux',
            'build': 1234567890,
            'reason': 'MOZALLOC_WENT_WRONG',
            'hangid': None,
            'process_type': None,
            'email': '[email protected]',
            'url': 'https://mozilla.org',
            'user_comments': '',
            'install_age': 0,
        }
        default_raw_crash_report = {
            'Accessibility': True,
            'AvailableVirtualMemory': 10211743,
            'B2G_OS_Version': '1.1.203448',
            'BIOS_Manufacturer': 'SUSA',
            'IsGarbageCollecting': False,
            'Vendor': 'mozilla',
            'useragent_locale': 'en-US',
        }

        self.storage.save_raw_and_processed(
            default_raw_crash_report,
            None,
            default_crash_report,
            default_crash_report['uuid']
        )

        self.storage.save_raw_and_processed(
            dict(default_raw_crash_report, Accessibility=False),
            None,
            dict(default_crash_report, uuid=1, product='EarthRaccoon'),
            1
        )

        self.storage.save_raw_and_processed(
            dict(default_raw_crash_report, AvailableVirtualMemory=0),
            None,
            dict(default_crash_report, uuid=2, version='2.0'),
            2
        )

        self.storage.save_raw_and_processed(
            dict(default_raw_crash_report, B2G_OS_Version='1.3'),
            None,
            dict(default_crash_report, uuid=3, release_channel='aurora'),
            3
        )

        self.storage.save_raw_and_processed(
            dict(default_raw_crash_report, BIOS_Manufacturer='aidivn'),
            None,
            dict(default_crash_report, uuid=4, os_name='Windows NT'),
            4
        )

        self.storage.save_raw_and_processed(
            dict(default_raw_crash_report, IsGarbageCollecting=True),
            None,
            dict(default_crash_report, uuid=5, build=987654321),
            5
        )

        self.storage.save_raw_and_processed(
            dict(default_raw_crash_report, Vendor='gnusmas'),
            None,
            dict(default_crash_report, uuid=6, reason='VERY_BAD_EXCEPTION'),
            6
        )

#.........这里部分代码省略.........
开发者ID:JisJis,项目名称:socorro,代码行数:103,代码来源:test_supersearch.py

示例14: IntegrationTestSettings

# 需要导入模块: from socorro.external.elasticsearch.supersearch import SuperSearch [as 别名]
# 或者: from socorro.external.elasticsearch.supersearch.SuperSearch import get [as 别名]
class IntegrationTestSettings(ElasticSearchTestCase):
    """Test the settings and mappings used in elasticsearch, through
    the supersearch service. """

    def setUp(self):
        super(IntegrationTestSettings, self).setUp()

        config = self.get_config_context()
        self.storage = crashstorage.ElasticSearchCrashStorage(config)
        self.api = SuperSearch(config)

        # clear the indices cache so the index is created on every test
        self.storage.indices_cache = set()

        self.now = utc_now()

        # Create the index that will be used.
        es_index = self.storage.get_index_for_crash(self.now)
        self.storage.create_socorro_index(es_index)

        # This an ugly hack to give elasticsearch some time to finish creating
        # the new index. It is needed for jenkins only, because we have a
        # special case here where we index only one or two documents before
        # querying. Other tests are not affected.
        # TODO: try to remove it, or at least understand why it is needed.
        time.sleep(1)

    def tearDown(self):
        # clear the test index
        config = self.get_config_context()
        self.storage.es.delete_index(config.webapi.elasticsearch_index)

        super(IntegrationTestSettings, self).tearDown()

    def test_dump_field(self):
        """Verify that the 'dump' field can be queried as expected. """
        # Index some data.
        processed_crash = {
            "uuid": "06a0c9b5-0381-42ce-855a-ccaaa2120100",
            "date_processed": self.now,
            "dump": EXAMPLE_DUMP,
        }
        self.storage.save_processed(processed_crash)
        self.storage.es.refresh()

        # Simple test with one word, no upper case.
        res = self.api.get(dump="~family")
        self.assertEqual(res["total"], 1)

        # Several words, with upper case.
        res = self.api.get(dump="~Windows NT")
        self.assertEqual(res["total"], 1)

    def test_cpu_info_field(self):
        """Verify that the 'cpu_info' field can be queried as expected. """
        processed_crash = {
            "uuid": "06a0c9b5-0381-42ce-855a-ccaaa2120101",
            "date_processed": self.now,
            "cpu_info": "GenuineIntel family 6 model 15 stepping 13",
        }
        self.storage.save_processed(processed_crash)
        self.storage.es.refresh()

        # Simple test with one word, no upper case.
        res = self.api.get(cpu_info="~model")
        self.assertEqual(res["total"], 1)
        self.assertTrue("model" in res["hits"][0]["cpu_info"])

        # Several words, with upper case, 'starts with' mode.
        res = self.api.get(cpu_info="$GenuineIntel family")
        self.assertEqual(res["total"], 1)
        self.assertTrue("GenuineIntel family" in res["hits"][0]["cpu_info"])

    def test_dom_ipc_enabled_field(self):
        """Verify that the 'dom_ipc_enabled' field can be queried as
        expected. """
        processed_crash = {"uuid": "06a0c9b5-0381-42ce-855a-ccaaa2120101", "date_processed": self.now}
        raw_crash = {"DOMIPCEnabled": True}
        self.storage.save_raw_and_processed(raw_crash, None, processed_crash, processed_crash["uuid"])
        processed_crash = {"uuid": "06a0c9b5-0381-42ce-855a-ccaaa2120102", "date_processed": self.now}
        raw_crash = {"DOMIPCEnabled": False}
        self.storage.save_raw_and_processed(raw_crash, None, processed_crash, processed_crash["uuid"])
        processed_crash = {"uuid": "06a0c9b5-0381-42ce-855a-ccaaa2120103", "date_processed": self.now}
        raw_crash = {"DOMIPCEnabled": None}
        self.storage.save_raw_and_processed(raw_crash, None, processed_crash, processed_crash["uuid"])
        self.storage.es.refresh()

        res = self.api.get(dom_ipc_enabled="true")
        self.assertEqual(res["total"], 1)
        self.assertTrue(res["hits"][0]["dom_ipc_enabled"])

        res = self.api.get(dom_ipc_enabled="false")
        self.assertEqual(res["total"], 2)

    def test_platform_field(self):
        """Verify that the 'platform' field can be queried as expected. """
        processed_crash = {
            "uuid": "06a0c9b5-0381-42ce-855a-ccaaa2120102",
            "date_processed": self.now,
            "os_name": "Mac OS X",
#.........这里部分代码省略.........
开发者ID:FishingCactus,项目名称:socorro,代码行数:103,代码来源:test_settings.py

示例15: test_get_with_string_operators

# 需要导入模块: from socorro.external.elasticsearch.supersearch import SuperSearch [as 别名]
# 或者: from socorro.external.elasticsearch.supersearch.SuperSearch import get [as 别名]
    def test_get_with_string_operators(self):
        """Test a search with several filters and operators returns expected
        results. """
        with _get_config_manager(self.config).context() as config:
            api = SuperSearch(config)

        # Test signature
        args = {"signature": ["js", "break_your_browser"]}
        res = api.get(**args)
        self.assertEqual(res["total"], 20)
        self.assertTrue(res["hits"])
        for report in res["hits"]:
            self.assertEqual(report["signature"], "js::break_your_browser")

        # - Test contains mode
        args = {"signature": "~bad"}
        res = api.get(**args)
        self.assertEqual(res["total"], 1)
        self.assertEqual(res["hits"][0]["signature"], "my_bad")

        args = {"signature": "~js::break"}
        res = api.get(**args)
        self.assertEqual(res["total"], 20)
        self.assertTrue(res["hits"])
        for report in res["hits"]:
            self.assertEqual(report["signature"], "js::break_your_browser")

        # - Test is_exactly mode
        args = {"signature": "=js::break_your_browser"}
        res = api.get(**args)
        self.assertEqual(res["total"], 20)
        self.assertTrue(res["hits"])
        for report in res["hits"]:
            self.assertEqual(report["signature"], "js::break_your_browser")

        args = {"signature": "=my_bad"}
        res = api.get(**args)
        self.assertEqual(res["total"], 1)
        self.assertEqual(res["hits"][0]["signature"], "my_bad")

        # - Test starts_with mode
        args = {"signature": "$js"}
        res = api.get(**args)
        self.assertEqual(res["total"], 20)
        self.assertTrue(res["hits"])
        for report in res["hits"]:
            self.assertEqual(report["signature"], "js::break_your_browser")

        # - Test ends_with mode
        args = {"signature": "^browser"}
        res = api.get(**args)
        self.assertEqual(res["total"], 20)
        self.assertTrue(res["hits"])
        for report in res["hits"]:
            self.assertEqual(report["signature"], "js::break_your_browser")

        # Test email
        args = {"email": "[email protected]"}
        res = api.get(**args)
        self.assertEqual(res["total"], 1)
        self.assertTrue(res["hits"])
        self.assertEqual(res["hits"][0]["email"], "[email protected]")

        args = {"email": "~mail.com"}
        res = api.get(**args)
        self.assertEqual(res["total"], 19)
        self.assertTrue(res["hits"])
        for report in res["hits"]:
            self.assertTrue("@" in report["email"])
            self.assertTrue("mail.com" in report["email"])

        args = {"email": "[email protected]"}
        res = api.get(**args)
        self.assertEqual(res["total"], 2)
        self.assertTrue(res["hits"])
        for report in res["hits"]:
            self.assertTrue("[email protected]" in report["email"])

        # Test url
        args = {"url": "https://mozilla.org"}
        res = api.get(**args)
        self.assertEqual(res["total"], 19)

        args = {"url": "~mozilla.org"}
        res = api.get(**args)
        self.assertEqual(res["total"], 20)
        self.assertTrue(res["hits"])
        for report in res["hits"]:
            self.assertTrue("mozilla.org" in report["url"])

        args = {"url": "^.com"}
        res = api.get(**args)
        self.assertEqual(res["total"], 1)
        self.assertEqual(res["hits"][0]["signature"], "js::break_your_browser")
        self.assertEqual(res["hits"][0]["url"], "http://www.example.com")

        # Test user_comments
        args = {"user_comments": "~love"}
        res = api.get(**args)
        self.assertEqual(res["total"], 1)
#.........这里部分代码省略.........
开发者ID:vfazio,项目名称:socorro,代码行数:103,代码来源:test_supersearch.py


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