本文整理汇总了Python中socorro.external.elasticsearch.search.Search类的典型用法代码示例。如果您正苦于以下问题:Python Search类的具体用法?Python Search怎么用?Python Search使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Search类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_search_versions
def test_search_versions(self, mock_psql_util):
mock_psql_util.return_value.versions_info.return_value = {
'EarlyOwl:11.0b1': {
'product_version_id': 1,
'product_name': 'EarlyOwl',
'version_string': '11.0b1',
'major_version': '11.0b1',
'release_channel': 'Beta',
'build_id': [1234567890],
'is_rapid_beta': False,
'is_from_rapid_beta': True,
'from_beta_version': 'EarlyOwl:11.0b',
},
'EarlyOwl:11.0b2': {
'product_version_id': 2,
'product_name': 'EarlyOwl',
'version_string': '11.0b2',
'major_version': '11.0b1',
'release_channel': 'Beta',
'build_id': [1234567890],
'is_rapid_beta': False,
'is_from_rapid_beta': True,
'from_beta_version': 'EarlyOwl:11.0b',
},
'EarlyOwl:11.0b': {
'product_version_id': 3,
'product_name': 'EarlyOwl',
'version_string': '11.0b',
'major_version': '11.0',
'release_channel': 'Beta',
'build_id': None,
'is_rapid_beta': True,
'is_from_rapid_beta': True,
'from_beta_version': 'EarlyOwl:11.0b',
}
}
with self.get_config_manager().context() as config:
api = Search(config=config)
# Get all from the different beta versions
params = dict(
versions=['EarlyOwl:11.0b1', 'EarlyOwl:11.0b2'],
)
res1 = api.get(**params)
self.assertEqual(res1['total'], 1)
# Get all from the rapid beta alias
params = dict(
versions='EarlyOwl:11.0b',
)
res2 = api.get(**params)
self.assertEqual(res2['total'], 1)
# The results should be identical
self.assertEqual(res1, res2)
开发者ID:esamanas,项目名称:socorro,代码行数:56,代码来源:test_search.py
示例2: test_search_combined_filters
def test_search_combined_filters(self, mock_psql_util):
with self.get_config_manager().context() as config:
api = Search(config=config)
# get the first, default crash report
params = {
'terms': 'js::break_your_browser',
'search_mode': 'is_exactly',
'products': 'WaterWolf',
'versions': 'WaterWolf:1.0',
'release_channels': 'release',
'os': 'Linux',
'build_ids': '1234567890',
'reasons': 'MOZALLOC_WENT_WRONG',
'report_type': 'crash',
'report_process': 'browser',
}
res = api.get(**params)
self.assertEqual(res['total'], 1)
self.assertEqual(
res['hits'][0]['signature'],
'js::break_your_browser'
)
self.assertEqual(res['hits'][0]['is_linux'], 1)
self.assertEqual(res['hits'][0]['is_windows'], 0)
self.assertEqual(res['hits'][0]['is_mac'], 0)
# get the crash report from last month
now = datetimeutil.utc_now()
three_weeks_ago = now - datetime.timedelta(weeks=3)
three_weeks_ago = datetimeutil.date_to_string(three_weeks_ago)
five_weeks_ago = now - datetime.timedelta(weeks=5)
five_weeks_ago = datetimeutil.date_to_string(five_weeks_ago)
params = {
'from_date': five_weeks_ago,
'to_date': three_weeks_ago,
}
res = api.get(**params)
self.assertEqual(res['total'], 1)
self.assertEqual(
res['hits'][0]['signature'],
'my_little_signature'
)
self.assertEqual(res['hits'][0]['is_linux'], 1)
self.assertEqual(res['hits'][0]['is_windows'], 0)
self.assertEqual(res['hits'][0]['is_mac'], 0)
开发者ID:erikrose,项目名称:socorro,代码行数:51,代码来源:test_search.py
示例3: test_get_signatures
def test_get_signatures(self):
"""
Test Search.get_signatures()
"""
context = self.get_dummy_context()
facets = {
"signatures": {
"terms": [
{
"term": "hang",
"count": 145
},
{
"term": "js",
"count": 7
},
{
"term": "ws",
"count": 4
}
]
}
}
size = 3
expected = ["hang", "js", "ws"]
signatures = Search.get_signatures(facets, size, context.platforms)
res_signs = []
for sign in signatures:
self.assertTrue(sign["signature"] in expected)
res_signs.append(sign["signature"])
for sign in expected:
self.assertTrue(sign in res_signs)
开发者ID:Manchester412,项目名称:socorro,代码行数:33,代码来源:test_search.py
示例4: test_search_no_results
def test_search_no_results(self, mock_psql_util):
with self.get_config_manager().context() as config:
api = Search(config=config)
# unexisting signature
params = {
'terms': 'callMeMaybe()',
}
res = api.get(**params)
self.assertEqual(res['total'], 0)
# unexisting product
params = {
'products': 'WindBear',
}
res = api.get(**params)
self.assertEqual(res['total'], 0)
开发者ID:erikrose,项目名称:socorro,代码行数:17,代码来源:test_search.py
示例5: test_get_signatures
def test_get_signatures():
"""
Test Search.get_signatures()
"""
context = get_dummy_context()
facets = {
"signatures": {
"terms": [
{
"term": "hang",
"count": 145
},
{
"term": "js",
"count": 7
},
{
"term": "ws",
"count": 4
}
]
}
}
size = 3
expected = ["hang", "js", "ws"]
signatures = Search.get_signatures(facets, size, context.platforms)
res_signs = []
for sign in signatures:
assert sign["signature"] in expected, (
"get_signatures returned an unexpected signature: %s" %
sign["signature"])
res_signs.append(sign["signature"])
for sign in expected:
assert sign in res_signs, (
"An expected signature is missing: %s" % sign)
开发者ID:mattloci,项目名称:socorro,代码行数:36,代码来源:test_search.py
示例6: test_get_counts
def test_get_counts(self):
"""
Test Search.get_counts()
"""
context = self.get_dummy_context()
signatures = [
{
"signature": "hang",
"count": 12
},
{
"signature": "js",
"count": 4
}
]
count_sign = {
"hang": {
"terms": [
{
"term": "windows",
"count": 3
},
{
"term": "linux",
"count": 4
}
]
},
"js": {
"terms": [
{
"term": "windows",
"count": 2
}
]
},
"hang_hang": {
"count": 0
},
"js_hang": {
"count": 0
},
"hang_plugin": {
"count": 0
},
"js_plugin": {
"count": 0
},
"hang_content": {
"count": 0
},
"js_content": {
"count": 0
}
}
res = Search.get_counts(
signatures,
count_sign,
0,
2,
context.platforms
)
self.assertTrue(type(res) is list)
for sign in res:
self.assertTrue("signature" in sign)
self.assertTrue("count" in sign)
self.assertTrue("is_windows" in sign)
self.assertTrue("numhang" in sign)
self.assertTrue("numplugin" in sign)
self.assertTrue("numcontent" in sign)
self.assertTrue("is_linux" in res[0])
self.assertFalse("is_linux" in res[1])
开发者ID:nizarnizario,项目名称:socorro,代码行数:74,代码来源:test_search.py
示例7: setUp
def setUp(self):
super(IntegrationElasticsearchSearch, self).setUp()
config = self.get_config_context()
self.api = Search(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,
'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,
}
self.storage.save_processed(default_crash_report)
self.storage.save_processed(
dict(default_crash_report, uuid=1, product='EarthRaccoon')
)
self.storage.save_processed(
dict(default_crash_report, uuid=2, version='2.0')
)
self.storage.save_processed(
dict(default_crash_report, uuid=3, release_channel='aurora')
)
self.storage.save_processed(
dict(default_crash_report, uuid=4, os_name='Windows NT')
)
self.storage.save_processed(
dict(default_crash_report, uuid=5, build='0987654321')
)
self.storage.save_processed(
dict(default_crash_report, uuid=6, reason='VERY_BAD_EXCEPTION')
)
self.storage.save_processed(
dict(default_crash_report, uuid=7, hangid='12')
)
self.storage.save_processed(
dict(default_crash_report, uuid=8, process_type='plugin')
)
self.storage.save_processed(
dict(default_crash_report, uuid=9, signature='my_bad')
)
self.storage.save_processed(
dict(
default_crash_report,
uuid=10,
date_processed=last_month,
signature='my_little_signature',
)
)
# for plugin terms test
self.storage.save_processed(
dict(
default_crash_report,
uuid=11,
product='PluginSoft',
process_type='plugin',
PluginFilename='carly.dll',
PluginName='Hey I just met you',
PluginVersion='1.2',
)
)
self.storage.save_processed(
dict(
default_crash_report,
uuid=12,
product='PluginSoft',
process_type='plugin',
PluginFilename='hey.dll',
#.........这里部分代码省略.........
开发者ID:FishingCactus,项目名称:socorro,代码行数:101,代码来源:test_search.py
示例8: IntegrationElasticsearchSearch
class IntegrationElasticsearchSearch(ElasticSearchTestCase):
"""Test search with an elasticsearch database containing fake data. """
def setUp(self):
super(IntegrationElasticsearchSearch, self).setUp()
config = self.get_config_context()
self.api = Search(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,
'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,
}
self.storage.save_processed(default_crash_report)
self.storage.save_processed(
dict(default_crash_report, uuid=1, product='EarthRaccoon')
)
self.storage.save_processed(
dict(default_crash_report, uuid=2, version='2.0')
)
self.storage.save_processed(
dict(default_crash_report, uuid=3, release_channel='aurora')
)
self.storage.save_processed(
dict(default_crash_report, uuid=4, os_name='Windows NT')
)
self.storage.save_processed(
dict(default_crash_report, uuid=5, build='0987654321')
)
self.storage.save_processed(
dict(default_crash_report, uuid=6, reason='VERY_BAD_EXCEPTION')
)
self.storage.save_processed(
dict(default_crash_report, uuid=7, hangid='12')
)
self.storage.save_processed(
dict(default_crash_report, uuid=8, process_type='plugin')
)
self.storage.save_processed(
dict(default_crash_report, uuid=9, signature='my_bad')
)
self.storage.save_processed(
dict(
default_crash_report,
uuid=10,
date_processed=last_month,
signature='my_little_signature',
)
)
# for plugin terms test
self.storage.save_processed(
dict(
default_crash_report,
uuid=11,
product='PluginSoft',
process_type='plugin',
PluginFilename='carly.dll',
PluginName='Hey I just met you',
PluginVersion='1.2',
)
)
self.storage.save_processed(
dict(
default_crash_report,
uuid=12,
#.........这里部分代码省略.........
开发者ID:FishingCactus,项目名称:socorro,代码行数:101,代码来源:test_search.py
示例9: test_search_plugin_terms
def test_search_plugin_terms(self, mock_psql_util):
with self.get_config_manager().context() as config:
api = Search(config=config)
base_params = {
'products': 'PluginSoft',
'report_process': 'plugin',
}
# test 'is_exactly' mode
base_params['plugin_search_mode'] = 'is_exactly'
# get all results with filename being exactly 'carly.dll'
# expect 1 signature with 1 crash
params = dict(
base_params,
plugin_terms='carly.dll',
plugin_in='filename',
)
res = api.get(**params)
self.assertEqual(res['total'], 1)
self.assertEqual(res['hits'][0]['count'], 1)
# get all results with name being exactly 'Hey Plugin'
# expect 1 signature with 1 crash
params = dict(
base_params,
plugin_terms='Hey Plugin',
plugin_in='name',
)
res = api.get(**params)
self.assertEqual(res['total'], 1)
self.assertEqual(res['hits'][0]['count'], 1)
# test 'contains' mode
base_params['plugin_search_mode'] = 'contains'
# get all results with filename containing '.dll'
# expect 1 signature with 2 crashes
params = dict(
base_params,
plugin_terms='.dll',
plugin_in='filename',
)
res = api.get(**params)
self.assertEqual(res['total'], 1)
self.assertEqual(res['hits'][0]['count'], 2)
# get all results with name containing 'Hey'
# expect 1 signature with 2 crashes
params = dict(
base_params,
plugin_terms='Hey',
plugin_in='name',
)
res = api.get(**params)
self.assertEqual(res['total'], 1)
self.assertEqual(res['hits'][0]['count'], 2)
# get all results with name containing 'Plugin'
# expect 1 signature with 1 crash
params = dict(
base_params,
plugin_terms='Plugin',
plugin_in='name',
)
res = api.get(**params)
self.assertEqual(res['total'], 1)
self.assertEqual(res['hits'][0]['count'], 1)
# test 'starts_with' mode
base_params['plugin_search_mode'] = 'starts_with'
# get all results with filename starting with 'car'
# expect 1 signature with 1 crash
params = dict(
base_params,
plugin_terms='car',
plugin_in='filename',
)
res = api.get(**params)
self.assertEqual(res['total'], 1)
self.assertEqual(res['hits'][0]['count'], 1)
# get all results with name starting with 'Hey'
# expect 1 signature with 2 crashes
params = dict(
base_params,
plugin_terms='Hey',
plugin_in='name',
)
res = api.get(**params)
self.assertEqual(res['total'], 1)
self.assertEqual(res['hits'][0]['count'], 2)
# test 'default' mode
base_params['plugin_search_mode'] = 'default'
# get all results with name containing the word 'hey'
# expect 1 signature with 2 crashes
#.........这里部分代码省略.........
开发者ID:erikrose,项目名称:socorro,代码行数:101,代码来源:test_search.py
示例10: test_search_single_filters
def test_search_single_filters(self, mock_psql_util):
# verify results show expected numbers
with self.get_config_manager().context() as config:
api = Search(config=config)
# test no filter, get all results
params = {}
res = api.get()
self.assertEqual(res['total'], 2)
self.assertEqual(
res['hits'][0]['signature'],
'js::break_your_browser'
)
self.assertEqual(
res['hits'][1]['signature'],
'my_bad'
)
self.assertEqual(res['hits'][0]['is_linux'], 10)
self.assertEqual(res['hits'][0]['is_windows'], 1)
self.assertEqual(res['hits'][0]['is_mac'], 0)
# test product
params = {
'products': 'EarthRaccoon'
}
res = api.get(**params)
self.assertEqual(res['total'], 1)
self.assertEqual(res['hits'][0]['count'], 1)
# test version
params = {
'versions': 'WaterWolf:2.0'
}
res = api.get(**params)
self.assertEqual(res['total'], 1)
self.assertEqual(res['hits'][0]['count'], 1)
# test release_channel
params = {
'release_channels': 'aurora'
}
res = api.get(**params)
self.assertEqual(res['total'], 1)
self.assertEqual(res['hits'][0]['count'], 1)
# test os_name
params = {
'os': 'Windows'
}
res = api.get(**params)
self.assertEqual(res['total'], 1)
self.assertEqual(res['hits'][0]['count'], 1)
# test short os_name
params = {
'os': 'win'
}
res = api.get(**params)
self.assertEqual(res['total'], 1)
self.assertEqual(res['hits'][0]['count'], 1)
# test build
params = {
'build_ids': '0987654321'
}
res = api.get(**params)
self.assertEqual(res['total'], 1)
self.assertEqual(res['hits'][0]['count'], 1)
# test reason
params = {
'reasons': 'VERY_BAD_EXCEPTION'
}
res = api.get(**params)
self.assertEqual(res['total'], 1)
self.assertEqual(res['hits'][0]['count'], 1)
# test hangid
params = {
'report_type': 'hang'
}
res = api.get(**params)
self.assertEqual(res['total'], 1)
self.assertEqual(res['hits'][0]['count'], 1)
# test process_type
params = {
'report_process': 'plugin'
}
res = api.get(**params)
#.........这里部分代码省略.........
开发者ID:erikrose,项目名称:socorro,代码行数:101,代码来源:test_search.py
示例11: test_get_counts
def test_get_counts():
"""
Test Search.get_counts()
"""
context = get_dummy_context()
signatures = [
{
"signature": "hang",
"count": 12
},
{
"signature": "js",
"count": 4
}
]
count_sign = {
"hang": {
"terms": [
{
"term": "windows",
"count": 3
},
{
"term": "linux",
"count": 4
}
]
},
"js": {
"terms": [
{
"term": "windows",
"count": 2
}
]
},
"hang_hang": {
"count": 0
},
"js_hang": {
"count": 0
},
"hang_plugin": {
"count": 0
},
"js_plugin": {
"count": 0
},
"hang_content": {
"count": 0
},
"js_content": {
"count": 0
}
}
res = Search.get_counts(signatures, count_sign, 0, 2, context.platforms)
assert type(res) is list, "Not a list"
for sign in res:
assert "signature" in sign, "no signature"
assert "count" in sign, "no count"
assert "is_windows" in sign, "no windows"
assert "numhang" in sign, "no hang"
assert "numplugin" in sign, "no plugin"
assert "numcontent" in sign, "no content"
assert "is_linux" in res[0], "no linux"
assert "is_linux" not in res[1], "need no linux"
开发者ID:mattloci,项目名称:socorro,代码行数:68,代码来源:test_search.py
注:本文中的socorro.external.elasticsearch.search.Search类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论