Permalink
Browse files

Merge pull request #1045 from AdrianGaudebert/806994-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 21a8fbae8d556b479bd54971800aaf6fa6a43c0c
@@ -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
@@ -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"
@@ -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
@@ -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
@@ -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"
+ },
+)
@@ -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
@@ -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)
Oops, something went wrong.

0 comments on commit 21a8fba

Please sign in to comment.