ADD: informative error message for sentiment_hq API, testing

This commit is contained in:
Madison May
2015-06-11 17:16:25 -04:00
parent 47133c956f
commit 91b7bfd454
2 changed files with 29 additions and 6 deletions
+8 -6
View File
@@ -22,15 +22,17 @@ def api_handler(arg, cloud, api, url_params = {"batch":False, "api_key":None}, *
# default to indico public cloud
host = config.PUBLIC_API_HOST
# error message for public cloud
if api == 'sentimenthq':
raise IndicoError("The high quality sentiment API is currently in private beta.")
url = config.url_protocol + "//%s/%s" % (host, api)
url = url + "/batch" if url_params.get("batch", False) else url
url += "?key=%s" % (url_params.get("api_key", None) or config.api_key)
if "apis" in url_params:
url += "&apis=%s" % ",".join(url_params["apis"])
apis = url_params.get("apis", [])
if apis:
url += "&apis=%s" % ",".join(apis)
# private beta
if host == config.PUBLIC_API_HOST:
if (api == 'sentimenthq') or ('sentimenthq' in apis):
raise IndicoError("The high quality sentiment API is currently in private beta.")
response = requests.post(url, data=json_data, headers=JSON_HEADERS)
if response.status_code == 503 and cloud != None:
+21
View File
@@ -9,6 +9,7 @@ from indicoio import config
from indicoio import political, sentiment, fer, facial_features, language, image_features, text_tags
from indicoio import batch_political, batch_sentiment, batch_fer, batch_facial_features
from indicoio import batch_language, batch_image_features, batch_text_tags
from indicoio import sentiment_hq, batch_sentiment_hq
from indicoio import predict_image, predict_text, batch_predict_image, batch_predict_text
from indicoio.utils.errors import IndicoError
@@ -37,6 +38,13 @@ class BatchAPIRun(unittest.TestCase):
self.assertTrue(isinstance(response, list))
self.assertTrue(response[0] < 0.5)
# TODO: uncomment once the high quality sentiment API is publicly released
# def test_batch_sentiment_hq(self):
# test_data = ['Worst song ever', 'Best song ever']
# response = batch_sentiment_hq(test_data, api_key=self.api_key)
# self.assertTrue(isinstance(response, list))
# self.assertTrue(response[0] < 0.5)
def test_batch_political(self):
test_data = ["Guns don't kill people, people kill people."]
response = batch_political(test_data, api_key=self.api_key)
@@ -220,6 +228,19 @@ class FullAPIRun(unittest.TestCase):
self.assertTrue(isinstance(response, float))
self.assertTrue(response > 0.5)
# TODO: uncomment when the high quality sentiment API is publicly released
# def test_sentiment_hq(self):
# test_string = "Worst song ever."
# response = sentiment_hq(test_string)
# self.assertTrue(isinstance(response, float))
# self.assertTrue(response < 0.5)
# test_string = "Best song ever."
# response = sentiment_hq(test_string)
# self.assertTrue(isinstance(response, float))
# self.assertTrue(response > 0.5)
def test_good_fer(self):
fer_set = set(['Angry', 'Sad', 'Neutral', 'Surprise', 'Fear', 'Happy'])
test_face = generate_array((48,48))