本文整理汇总了Python中crashstats.supersearch.models.SuperSearch.implementation方法的典型用法代码示例。如果您正苦于以下问题:Python SuperSearch.implementation方法的具体用法?Python SuperSearch.implementation怎么用?Python SuperSearch.implementation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类crashstats.supersearch.models.SuperSearch
的用法示例。
在下文中一共展示了SuperSearch.implementation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_parameters
# 需要导入模块: from crashstats.supersearch.models import SuperSearch [as 别名]
# 或者: from crashstats.supersearch.models.SuperSearch import implementation [as 别名]
def test_parameters(self):
def mocked_supersearch_get(**params):
# Verify that all expected parameters are in the URL.
ok_("product" in params)
ok_("WaterWolf" in params["product"])
ok_("NightTrain" in params["product"])
ok_("address" in params)
ok_("0x0" in params["address"])
ok_("0xa" in params["address"])
ok_("reason" in params)
ok_("^hello" in params["reason"])
ok_("$thanks" in params["reason"])
ok_("java_stack_trace" in params)
ok_("Exception" in params["java_stack_trace"])
return {"hits": [], "facets": "", "total": 0}
SuperSearch.implementation().get.side_effect = mocked_supersearch_get
url = reverse("signature:signature_reports")
response = self.client.get(
url,
{
"signature": DUMB_SIGNATURE,
"product": ["WaterWolf", "NightTrain"],
"address": ["0x0", "0xa"],
"reason": ["^hello", "$thanks"],
"java_stack_trace": "Exception",
},
)
eq_(response.status_code, 200)
示例2: test_assert_supersearch_errors
# 需要导入模块: from crashstats.supersearch.models import SuperSearch [as 别名]
# 或者: from crashstats.supersearch.models.SuperSearch import implementation [as 别名]
def test_assert_supersearch_errors(self):
searches = []
def mocked_supersearch_get(**params):
searches.append(params)
eq_(params['product'], [settings.DEFAULT_PRODUCT])
eq_(params['_results_number'], 1)
eq_(params['_columns'], ['uuid'])
return {
'hits': [
{'uuid': '12345'},
],
'facets': [],
'total': 320,
'errors': ['bad'],
}
SuperSearch.implementation().get.side_effect = (
mocked_supersearch_get
)
assert_raises(
AssertionError,
assert_supersearch_no_errors
)
assert len(searches) == 1
示例3: test_topcrasher_modes
# 需要导入模块: from crashstats.supersearch.models import SuperSearch [as 别名]
# 或者: from crashstats.supersearch.models.SuperSearch import implementation [as 别名]
def test_topcrasher_modes(self, rpost):
rpost.side_effect = mocked_post_123
def mocked_supersearch_get(**params):
return {"hits": [], "facets": {"signature": []}, "total": 0}
SuperSearch.implementation().get.side_effect = mocked_supersearch_get
now = datetime.datetime.utcnow()
today = now.replace(hour=0, minute=0, second=0, microsecond=0)
timestr = "%Y-%m-%d %H:%M:%S"
now = now.strftime(timestr)
today = today.strftime(timestr)
with freezegun.freeze_time(now, tz_offset=0):
# By default, it returns "real-time" data.
response = self.client.get(self.base_url, {"product": "WaterWolf", "version": "19.0"})
eq_(response.status_code, 200)
ok_(now in response.content, now)
ok_(today not in response.content)
# Now test the "day time" data.
response = self.client.get(
self.base_url, {"product": "WaterWolf", "version": "19.0", "_tcbs_mode": "byday"}
)
eq_(response.status_code, 200)
ok_(today in response.content)
ok_(now not in response.content)
示例4: test_healthcheck
# 需要导入模块: from crashstats.supersearch.models import SuperSearch [as 别名]
# 或者: from crashstats.supersearch.models.SuperSearch import implementation [as 别名]
def test_healthcheck(self, mocked_elasticsearch, rget):
searches = []
def mocked_supersearch_get(**params):
searches.append(params)
eq_(params['product'], [settings.DEFAULT_PRODUCT])
eq_(params['_results_number'], 1)
eq_(params['_columns'], ['uuid'])
return {
'hits': [
{'uuid': '12345'},
],
'facets': [],
'total': 30002,
'errors': [],
}
SuperSearch.implementation().get.side_effect = (
mocked_supersearch_get
)
def mocked_requests_get(url, **params):
return Response(True)
rget.side_effect = mocked_requests_get
url = reverse('monitoring:healthcheck')
response = self.client.get(url)
eq_(response.status_code, 200)
eq_(json.loads(response.content)['ok'], True)
assert len(searches) == 1
示例5: test_signature_reports_pagination
# 需要导入模块: from crashstats.supersearch.models import SuperSearch [as 别名]
# 或者: from crashstats.supersearch.models.SuperSearch import implementation [as 别名]
def test_signature_reports_pagination(self):
"""Test that the pagination of results works as expected.
"""
def mocked_supersearch_get(**params):
assert '_columns' in params
# Make sure a negative page does not lead to negative offset value.
# But instead it is considered as the page 1 and thus is not added.
eq_(params.get('_results_offset'), 0)
hits = []
for i in range(140):
hits.append({
"signature": "nsASDOMWindowEnumerator::GetNext()",
"date": "2017-01-31T23:12:57",
"uuid": i,
"product": "WaterWolf",
"version": "1.0",
"platform": "Linux",
"build_id": 888981
})
return {
"hits": self.only_certain_columns(hits, params['_columns']),
"facets": "",
"total": len(hits)
}
SuperSearch.implementation().get.side_effect = mocked_supersearch_get
url = reverse('signature:signature_reports')
response = self.client.get(
url,
{
'signature': DUMB_SIGNATURE,
'product': ['WaterWolf'],
'_columns': ['platform']
}
)
eq_(response.status_code, 200)
ok_('140' in response.content)
# Check that the pagination URL contains all three expected parameters.
doc = pyquery.PyQuery(response.content)
next_page_url = str(doc('.pagination a').eq(0))
ok_('product=WaterWolf' in next_page_url)
ok_('_columns=platform' in next_page_url)
ok_('page=2' in next_page_url)
# Test that a negative page value does not break it.
response = self.client.get(url, {
'signature': DUMB_SIGNATURE,
'page': '-1',
})
eq_(response.status_code, 200)
示例6: test_signature_graphs
# 需要导入模块: from crashstats.supersearch.models import SuperSearch [as 别名]
# 或者: from crashstats.supersearch.models.SuperSearch import implementation [as 别名]
def test_signature_graphs(self):
def mocked_supersearch_get(**params):
ok_("signature" in params)
eq_(params["signature"], ["=" + DUMB_SIGNATURE])
ok_("_histogram.date" in params)
ok_("_facets" in params)
if "product" in params["_facets"]:
return {
"hits": [],
"total": 4,
"facets": {
"product": [{"count": 4, "term": "WaterWolf"}],
"histogram_date": [
{
"count": 2,
"term": "2015-08-05T00:00:00+00:00",
"facets": {"product": [{"count": 2, "term": "WaterWolf"}]},
},
{
"count": 2,
"term": "2015-08-06T00:00:00+00:00",
"facets": {"product": [{"count": 2, "term": "WaterWolf"}]},
},
],
},
}
return {"hits": [], "total": 0, "facets": {"platform": [], "signature": [], "histogram_date": []}}
SuperSearch.implementation().get.side_effect = mocked_supersearch_get
# Test with no results
url = reverse("signature:signature_graphs", args=("platform",))
response = self.client.get(url, {"signature": DUMB_SIGNATURE})
eq_(response.status_code, 200)
ok_("application/json" in response["content-type"])
struct = json.loads(response.content)
ok_("aggregates" in struct)
eq_(len(struct["aggregates"]), 0)
ok_("term_counts" in struct)
eq_(len(struct["term_counts"]), 0)
# Test with results
url = reverse("signature:signature_graphs", args=("product",))
response = self.client.get(url, {"signature": DUMB_SIGNATURE})
eq_(response.status_code, 200)
ok_("application/json" in response["content-type"])
struct = json.loads(response.content)
ok_("aggregates" in struct)
eq_(len(struct["aggregates"]), 2)
ok_("term_counts" in struct)
eq_(len(struct["term_counts"]), 1)
示例7: test_signature_comments_pagination
# 需要导入模块: from crashstats.supersearch.models import SuperSearch [as 别名]
# 或者: from crashstats.supersearch.models.SuperSearch import implementation [as 别名]
def test_signature_comments_pagination(self):
"""Test that the pagination of comments works as expected. """
def mocked_supersearch_get(**params):
assert '_columns' in params
if params.get('_results_offset') != 0:
hits_range = range(100, 140)
else:
hits_range = range(100)
hits = []
for i in hits_range:
hits.append({
"date": "2017-01-31T23:12:57",
"uuid": i,
"user_comments": "hi",
})
return {
"hits": self.only_certain_columns(hits, params['_columns']),
"total": 140
}
SuperSearch.implementation().get.side_effect = mocked_supersearch_get
url = reverse('signature:signature_comments')
response = self.client.get(
url,
{
'signature': DUMB_SIGNATURE,
'product': ['WaterWolf'],
}
)
eq_(response.status_code, 200)
ok_('140' in response.content)
ok_('99' in response.content)
ok_('139' not in response.content)
# Check that the pagination URL contains all expected parameters.
doc = pyquery.PyQuery(response.content)
next_page_url = str(doc('.pagination a').eq(0))
ok_('product=WaterWolf' in next_page_url)
ok_('page=2' in next_page_url)
response = self.client.get(url, {
'signature': DUMB_SIGNATURE,
'page': '2',
})
eq_(response.status_code, 200)
ok_('140' in response.content)
ok_('99' not in response.content)
ok_('139' in response.content)
示例8: test_search_custom
# 需要导入模块: from crashstats.supersearch.models import SuperSearch [as 别名]
# 或者: from crashstats.supersearch.models.SuperSearch import implementation [as 别名]
def test_search_custom(self):
def mocked_supersearch_get(**params):
return None
SuperSearch.implementation().get.side_effect = mocked_supersearch_get
self.create_custom_query_perm()
url = reverse('supersearch.search_custom')
response = self.client.get(url)
eq_(response.status_code, 200)
ok_('Run a search to get some results' in response.content)
示例9: test_search_results_parameters
# 需要导入模块: from crashstats.supersearch.models import SuperSearch [as 别名]
# 或者: from crashstats.supersearch.models.SuperSearch import implementation [as 别名]
def test_search_results_parameters(self, rpost):
def mocked_post(**options):
assert 'bugs' in options['url'], options['url']
return Response({
"hits": [],
"total": 0
})
rpost.side_effect = mocked_post
def mocked_supersearch_get(**params):
# Verify that all expected parameters are in the URL.
ok_('product' in params)
ok_('WaterWolf' in params['product'])
ok_('NightTrain' in params['product'])
ok_('address' in params)
ok_('0x0' in params['address'])
ok_('0xa' in params['address'])
ok_('reason' in params)
ok_('^hello' in params['reason'])
ok_('$thanks' in params['reason'])
ok_('java_stack_trace' in params)
ok_('Exception' in params['java_stack_trace'])
return {
"hits": [],
"facets": "",
"total": 0
}
SuperSearch.implementation().get.side_effect = mocked_supersearch_get
url = reverse('supersearch.search_results')
response = self.client.get(
url, {
'product': ['WaterWolf', 'NightTrain'],
'address': ['0x0', '0xa'],
'reason': ['^hello', '$thanks'],
'java_stack_trace': 'Exception',
}
)
eq_(response.status_code, 200)
示例10: test_topcrasher_without_any_signatures
# 需要导入模块: from crashstats.supersearch.models import SuperSearch [as 别名]
# 或者: from crashstats.supersearch.models.SuperSearch import implementation [as 别名]
def test_topcrasher_without_any_signatures(self, rget, rpost):
url = self.base_url + '?product=WaterWolf&version=19.0'
response = self.client.get(self.base_url, {
'product': 'WaterWolf',
})
ok_(url in response['Location'])
rpost.side_effect = mocked_post_123
def mocked_get(url, params, **options):
if '/products' in url:
return Response("""
{
"hits": [
{
"is_featured": true,
"throttle": 1.0,
"end_date": "string",
"start_date": "integer",
"build_type": "string",
"product": "WaterWolf",
"version": "19.0",
"has_builds": true
}],
"total": "1"
}
""")
raise NotImplementedError(url)
rget.side_effect = mocked_get
def mocked_supersearch_get(**params):
return {
'hits': [],
'facets': {
'signature': []
},
'total': 0
}
SuperSearch.implementation().get.side_effect = mocked_supersearch_get
response = self.client.get(self.base_url, {
'product': 'WaterWolf',
'version': '19.0',
})
eq_(response.status_code, 200)
示例11: test_signature_aggregation
# 需要导入模块: from crashstats.supersearch.models import SuperSearch [as 别名]
# 或者: from crashstats.supersearch.models.SuperSearch import implementation [as 别名]
def test_signature_aggregation(self):
def mocked_supersearch_get(**params):
ok_("signature" in params)
eq_(params["signature"], ["=" + DUMB_SIGNATURE])
ok_("_facets" in params)
if "product" in params["_facets"]:
return {
"hits": [],
"facets": {
"product": [
{"term": "windows", "count": 42},
{"term": "linux", "count": 1337},
{"term": "mac", "count": 3},
]
},
"total": 1382,
}
# the default
return {"hits": [], "facets": {"platform": []}, "total": 0}
SuperSearch.implementation().get.side_effect = mocked_supersearch_get
# Test with no results.
url = reverse("signature:signature_aggregation", args=("platform",))
response = self.client.get(url, {"signature": DUMB_SIGNATURE})
eq_(response.status_code, 200)
ok_("Product" not in response.content)
ok_("No results were found" in response.content)
# Test with results.
url = reverse("signature:signature_aggregation", args=("product",))
response = self.client.get(url, {"signature": DUMB_SIGNATURE})
eq_(response.status_code, 200)
ok_("Product" in response.content)
ok_("1337" in response.content)
ok_("linux" in response.content)
ok_(str(1337 / 1382 * 100) in response.content)
ok_("windows" in response.content)
ok_("mac" in response.content)
示例12: test_search_results_ratelimited
# 需要导入模块: from crashstats.supersearch.models import SuperSearch [as 别名]
# 或者: from crashstats.supersearch.models.SuperSearch import implementation [as 别名]
def test_search_results_ratelimited(self):
def mocked_supersearch_get(**params):
return {"hits": [], "facets": [], "total": 0}
SuperSearch.implementation().get.side_effect = mocked_supersearch_get
url = reverse('supersearch.search_results')
limit = int(re.findall('(\d+)', settings.RATELIMIT_SUPERSEARCH)[0])
params = {'product': 'WaterWolf'}
# double to avoid https://bugzilla.mozilla.org/show_bug.cgi?id=1148470
for i in range(limit * 2):
self.client.get(url, params)
response = self.client.get(
url,
params,
HTTP_X_REQUESTED_WITH='XMLHttpRequest'
)
eq_(response.status_code, 429)
eq_(response.content, 'Too Many Requests')
eq_(response['content-type'], 'text/plain')
示例13: test_change_certain_exceptions_to_bad_request
# 需要导入模块: from crashstats.supersearch.models import SuperSearch [as 别名]
# 或者: from crashstats.supersearch.models.SuperSearch import implementation [as 别名]
def test_change_certain_exceptions_to_bad_request(self):
# It actually doesn't matter so much which service we use
# because we're heavily mocking it.
# Here we use the SuperSearch model.
def mocked_supersearch_get(**params):
if params.get('product'):
raise MissingArgumentError(params['product'])
else:
raise BadArgumentError('That was a bad thing to do')
SuperSearch.implementation().get.side_effect = mocked_supersearch_get
url = reverse('api:model_wrapper', args=('SuperSearch',))
response = self.client.get(url)
eq_(response.status_code, 400)
ok_('That was a bad thing to do' in response.content)
response = self.client.get(url, {'product': 'foobaz'})
eq_(response.status_code, 400)
ok_('foobaz' in response.content)
示例14: test_parameters
# 需要导入模块: from crashstats.supersearch.models import SuperSearch [as 别名]
# 或者: from crashstats.supersearch.models.SuperSearch import implementation [as 别名]
def test_parameters(self):
def mocked_supersearch_get(**params):
# Verify that all expected parameters are in the URL.
ok_('product' in params)
ok_('WaterWolf' in params['product'])
ok_('NightTrain' in params['product'])
ok_('address' in params)
ok_('0x0' in params['address'])
ok_('0xa' in params['address'])
ok_('reason' in params)
ok_('^hello' in params['reason'])
ok_('$thanks' in params['reason'])
ok_('java_stack_trace' in params)
ok_('Exception' in params['java_stack_trace'])
return {
"hits": [],
"facets": "",
"total": 0
}
SuperSearch.implementation().get.side_effect = mocked_supersearch_get
url = reverse('signature:signature_reports')
response = self.client.get(
url, {
'signature': DUMB_SIGNATURE,
'product': ['WaterWolf', 'NightTrain'],
'address': ['0x0', '0xa'],
'reason': ['^hello', '$thanks'],
'java_stack_trace': 'Exception',
}
)
eq_(response.status_code, 200)
示例15: test_signature_comments_pagination
# 需要导入模块: from crashstats.supersearch.models import SuperSearch [as 别名]
# 或者: from crashstats.supersearch.models.SuperSearch import implementation [as 别名]
def test_signature_comments_pagination(self):
"""Test that the pagination of comments works as expected. """
def mocked_supersearch_get(**params):
assert "_columns" in params
if params.get("_results_offset") != 0:
hits_range = range(100, 140)
else:
hits_range = range(100)
hits = []
for i in hits_range:
hits.append({"date": "2017-01-31T23:12:57", "uuid": i, "user_comments": "hi"})
return {"hits": self.only_certain_columns(hits, params["_columns"]), "total": 140}
SuperSearch.implementation().get.side_effect = mocked_supersearch_get
url = reverse("signature:signature_comments")
response = self.client.get(url, {"signature": DUMB_SIGNATURE, "product": ["WaterWolf"]})
eq_(response.status_code, 200)
ok_("140" in response.content)
ok_("99" in response.content)
ok_("139" not in response.content)
# Check that the pagination URL contains all expected parameters.
doc = pyquery.PyQuery(response.content)
next_page_url = str(doc(".pagination a").eq(0))
ok_("product=WaterWolf" in next_page_url)
ok_("page=2" in next_page_url)
response = self.client.get(url, {"signature": DUMB_SIGNATURE, "page": "2"})
eq_(response.status_code, 200)
ok_("140" in response.content)
ok_("99" not in response.content)
ok_("139" in response.content)