Skip to content

Commit

Permalink
Merge pull request mozilla-services#1045 from AdrianGaudebert/806994-…
Browse files Browse the repository at this point in the history
…functional-tests-middleware

Fixes bug 806994 - Added functional tests where missing in the middleware.
  • Loading branch information
adngdb committed Jan 17, 2013
2 parents 1ac4e5c + 26cd8a1 commit 21a8fba
Show file tree
Hide file tree
Showing 6 changed files with 826 additions and 10 deletions.
10 changes: 6 additions & 4 deletions socorro/external/postgresql/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import psycopg2

from socorro.external import DatabaseError
from socorro.external import DatabaseError, MissingOrBadArgumentError
from socorro.external.postgresql.base import PostgreSQLBase
from socorro.external.postgresql.util import Util
from socorro.lib import datetimeutil, search_common
Expand Down Expand Up @@ -34,8 +34,10 @@ def get_list(self, **kwargs):

params = search_common.get_parameters(kwargs)

if params["signature"] is None:
return None
if not params["signature"]:
raise MissingOrBadArgumentError(
"Mandatory parameter 'signature' is missing or empty"
)

params["terms"] = params["signature"]
params["search_mode"] = "is_exactly"
Expand Down Expand Up @@ -74,7 +76,7 @@ def get_list(self, **kwargs):
# Changing the OS ids to OS names
for i, elem in enumerate(params["os"]):
for platform in context.platforms:
if platform["id"] == elem:
if platform["id"][:3] == elem[:3]:
params["os"][i] = platform["name"]

# Creating the parameters for the sql query
Expand Down
2 changes: 1 addition & 1 deletion socorro/external/postgresql/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def get(self, **kwargs):
# Changing the OS ids to OS names
for i, elem in enumerate(params["os"]):
for platform in context.platforms:
if platform["id"][0:3] == elem[0:3]:
if platform["id"][:3] == elem[:3]:
params["os"][i] = platform["name"]

# Creating the parameters for the sql query
Expand Down
18 changes: 18 additions & 0 deletions socorro/unittest/config/commonconfig.py.dist
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,21 @@ statsdPrefix = cm.Option()
statsdPrefix.doc = ''
statsdPrefix.default = ''

#---------------------------------------------------------------------------
# Platforms
platforms = cm.Option()
platforms.doc = 'Array associating OS ids to full names.'
platforms.default = (
{
"id" : "windows",
"name" : "Windows NT"
},
{
"id" : "mac",
"name" : "Mac OS X"
},
{
"id" : "linux",
"name" : "Linux"
},
)
63 changes: 58 additions & 5 deletions socorro/unittest/external/postgresql/test_crashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,20 @@ def setUp(self):
# Insert data for frequency test
cursor.execute("""
INSERT INTO reports
(id, uuid, build, signature, os_name, date_processed)
(
id,
uuid,
build,
signature,
os_name,
date_processed,
user_comments
)
VALUES
(1, 'abc', '2012033116', 'js', 'Windows NT', '%(now)s'),
(2, 'def', '2012033116', 'js', 'Linux', '%(now)s'),
(3, 'hij', '2012033117', 'js', 'Windows NT', '%(now)s'),
(4, 'klm', '2012033117', 'blah', 'Unknown', '%(now)s')
(1, 'abc', '2012033116', 'js', 'Windows NT', '%(now)s', null),
(2, 'def', '2012033116', 'js', 'Linux', '%(now)s', 'hello'),
(3, 'hij', '2012033117', 'js', 'Windows NT', '%(now)s', 'hah'),
(4, 'klm', '2012033117', 'blah', 'Unknown', '%(now)s', null)
""" % {"now": now})

# Insert data for daily crashes test
Expand Down Expand Up @@ -319,6 +327,51 @@ def tearDown(self):
cursor.close()
super(IntegrationTestCrashes, self).tearDown()

#--------------------------------------------------------------------------
def test_get_comments(self):
crashes = Crashes(config=self.config)
today = datetimeutil.date_to_string(datetimeutil.utc_now())

# Test 1: results
params = {
"signature": "js",
}
res_expected = {
"hits": [
{
"email": None,
"date_processed": today,
"uuid": "def",
"user_comments": "hello"
},
{
"email": None,
"date_processed": today,
"uuid": "hij",
"user_comments": "hah"
}
],
"total": 2
}

res = crashes.get_comments(**params)
self.assertEqual(res, res_expected)

# Test 2: no results
params = {
"signature": "blah",
}
res_expected = {
"hits": [],
"total": 0
}

res = crashes.get_comments(**params)
self.assertEqual(res, res_expected)

# Test 3: missing parameter
self.assertRaises(MissingOrBadArgumentError, crashes.get_comments)

#--------------------------------------------------------------------------
def test_get_daily(self):
crashes = Crashes(config=self.config)
Expand Down
Loading

0 comments on commit 21a8fba

Please sign in to comment.