From 91b7bfd45473106f85d77f2f99e746582d142b64 Mon Sep 17 00:00:00 2001 From: Madison May Date: Thu, 11 Jun 2015 17:16:25 -0400 Subject: [PATCH] ADD: informative error message for sentiment_hq API, testing --- indicoio/utils/api.py | 14 ++++++++------ tests/test_remote.py | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/indicoio/utils/api.py b/indicoio/utils/api.py index e11abe3..664e441 100644 --- a/indicoio/utils/api.py +++ b/indicoio/utils/api.py @@ -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: diff --git a/tests/test_remote.py b/tests/test_remote.py index dcb0f81..ef66a96 100644 --- a/tests/test_remote.py +++ b/tests/test_remote.py @@ -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))