Skip to content

Commit

Permalink
Fixes bug 864752 - Excluded channels now begin with the value in conf…
Browse files Browse the repository at this point in the history
…iguration.
  • Loading branch information
adngdb committed May 13, 2013
1 parent ab198c2 commit 2dc2dd6
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 16 deletions.
11 changes: 6 additions & 5 deletions socorro/external/elasticsearch/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,14 @@ def build_query_from_params(params, config):
continue

and_filter = []
channel = None
key = ":".join((v["product"], v["version"]))
if key in versions_info:
channel = versions_info[key]["release_channel"].lower()
else:
channel = None
version_info = versions_info[key]
if version_info["release_channel"]:
channel = version_info["release_channel"].lower()

if channel in config.channels:
if channel and channel.startswith(tuple(config.channels)):
# this version is not a release
# first use the major version instead
v["version"] = versions_info[key]["major_version"]
Expand All @@ -235,7 +236,7 @@ def build_query_from_params(params, config):
)
)

if channel in config.restricted_channels:
if channel.startswith(tuple(config.restricted_channels)):
# if it's a beta, verify the build id
and_filter.append(
ElasticSearchBase.build_terms_query(
Expand Down
4 changes: 2 additions & 2 deletions socorro/external/postgresql/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,12 @@ def build_reports_sql_version_where(key, params, config, x, sql_params,

if version_info and version_info["release_channel"]:
channel = version_info["release_channel"].lower()
if channel in context.channels:
if channel.startswith(tuple(context.channels)):
# Use major_version instead of full version
sql_params[version_param] = version_info["major_version"]
# Restrict by release_channel
version_where.append("r.release_channel ILIKE '%s'" % channel)
if channel in context.restricted_channels:
if channel.startswith(tuple(context.restricted_channels)):
# Restrict to a list of build_id
version_where.append("r.build IN ('%s')" % (
"', '".join([
Expand Down
53 changes: 50 additions & 3 deletions socorro/unittest/external/elasticsearch/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import datetime
import json
import mock
import unittest

Expand Down Expand Up @@ -86,9 +87,8 @@ def get_dummy_context(self):
"name": "Linux"
}
)
context.channels = ['Beta', 'Aurora', 'Nightly', 'beta', 'aurora',
'nightly']
context.restricted_channels = ['Beta', 'beta']
context.channels = ['beta', 'aurora', 'nightly']
context.restricted_channels = ['beta']
return context

#--------------------------------------------------------------------------
Expand Down Expand Up @@ -126,6 +126,53 @@ def test_build_query_from_params(self):
self.assertTrue("filter" in filtered)
self.assertTrue("and" in filtered["filter"])

# Test versions
params = {
"products": "WaterWolf",
"versions": "WaterWolf:1.0a1"
}
params = scommon.get_parameters(params)
params['versions_info'] = {
'WaterWolf:1.0a1': {
"version_string": "1.0a1",
"product_name": "WaterWolf",
"major_version": "1.0a1",
"release_channel": "nightly-water",
"build_id": None
}
}
query = ElasticSearchBase.build_query_from_params(params, config)
filtered = query["query"]["filtered"]

self.assertTrue("and" in filtered["filter"])
and_filter_str = json.dumps(filtered["filter"]['and'])
self.assertTrue('WaterWolf' in and_filter_str)
self.assertTrue('1.0a1' in and_filter_str)
self.assertTrue('nightly-water' in and_filter_str)

# Test versions with an empty release channel in versions_info
params = {
"products": "WaterWolf",
"versions": "WaterWolf:2.0"
}
params = scommon.get_parameters(params)
params['versions_info'] = {
'WaterWolf:2.0': {
"version_string": "2.0",
"product_name": "WaterWolf",
"major_version": "2.0",
"release_channel": None,
"build_id": None
}
}
query = ElasticSearchBase.build_query_from_params(params, config)
filtered = query["query"]["filtered"]

self.assertTrue("and" in filtered["filter"])
and_filter_str = json.dumps(filtered["filter"]['and'])
self.assertTrue('WaterWolf' in and_filter_str)
self.assertTrue('2.0' in and_filter_str)

#--------------------------------------------------------------------------
def test_build_terms_query(self):
# Empty query
Expand Down
81 changes: 75 additions & 6 deletions socorro/unittest/external/postgresql/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ def get_dummy_context(self):
"name": "Linux"
}
)
context.channels = ['Beta', 'Aurora', 'Nightly', 'beta', 'aurora',
'nightly']
context.restricted_channels = ['Beta', 'beta']
context.channels = ['beta', 'aurora', 'nightly']
context.restricted_channels = ['beta']
return context

#--------------------------------------------------------------------------
Expand Down Expand Up @@ -422,9 +421,7 @@ def test_build_reports_sql_version_where(self):
config = self.get_dummy_context()
pgbase = self.get_instance()

key = "Firefox:13.0(beta)"
params = util.DotDict()
params["versions"] = ["Firefox", "13.0(beta)"]
params["versions_info"] = {
"Firefox:12.0a1": {
"version_string": "12.0a1",
Expand All @@ -444,10 +441,28 @@ def test_build_reports_sql_version_where(self):
"version_string": "13.0(beta)",
"product_name": "Firefox",
"major_version": "13.0",
"release_channel": "Beta",
"release_channel": "beta",
"build_id": ["20120101123456", "20120101098765"]
},
"WaterWolf:1.0a1": {
"version_string": "1.0a1",
"product_name": "WaterWolf",
"major_version": "1.0a1",
"release_channel": "nightly-water",
"build_id": None
},
"WaterWolf:2.0": {
"version_string": "2.0",
"product_name": "WaterWolf",
"major_version": "2.0",
"release_channel": None,
"build_id": None
}
}

# test 1
params["versions"] = ["Firefox", "13.0(beta)"]
key = "Firefox:13.0(beta)"
x = 0
sql_params = {
"version0": "Firefox",
Expand All @@ -473,6 +488,60 @@ def test_build_reports_sql_version_where(self):
self.assertEqual(version_where, version_where_exp)
self.assertEqual(sql_params, sql_params_exp)

# test 2, verify release channels get added as expected
params["versions"] = ["WaterWolf", "1.0a1"]
key = "WaterWolf:1.0a1"
x = 0
sql_params = {
"version0": "WaterWolf",
"version1": "1.0a1"
}
sql_params_exp = {
"version0": "WaterWolf",
"version1": "1.0a1"
}
version_where = []
version_where_exp = ["r.release_channel ILIKE 'nightly-water'"]

version_where = pgbase.build_reports_sql_version_where(
key,
params,
config,
x,
sql_params,
version_where
)

self.assertEqual(version_where, version_where_exp)
self.assertEqual(sql_params, sql_params_exp)

# test 3, what if a release channel is "null"
params["versions"] = ["WaterWolf", "2.0"]
key = "WaterWolf:2.0"
x = 0
sql_params = {
"version0": "WaterWolf",
"version1": "2.0"
}
sql_params_exp = {
"version0": "WaterWolf",
"version1": "2.0"
}
version_where = []
version_where_exp = []

version_where = pgbase.build_reports_sql_version_where(
key,
params,
config,
x,
sql_params,
version_where
)

self.assertEqual(version_where, version_where_exp)
self.assertEqual(sql_params, sql_params_exp)


#==============================================================================
@attr(integration='postgres') # for nosetests
Expand Down

0 comments on commit 2dc2dd6

Please sign in to comment.