From aa63a831c628977c9b73a0bdfa4731fe66bc1602 Mon Sep 17 00:00:00 2001 From: Madison May Date: Sat, 20 Dec 2014 15:34:07 -0500 Subject: [PATCH] Fix for texttagging batch support, adding in a few more tests --- indicoio/text/tagging.py | 2 +- indicoio/utils/__init__.py | 5 +++-- tests/remote/test_remote.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/indicoio/text/tagging.py b/indicoio/text/tagging.py index b0e8750..6fabd7b 100644 --- a/indicoio/text/tagging.py +++ b/indicoio/text/tagging.py @@ -22,4 +22,4 @@ def text_tags(api_root, text, batch=False, auth=None, **kwargs): :rtype: Dictionary of class probability pairs """ - return api_handler(text, api_root + "texttags", batch=batch, auth=None, **kwargs) + return api_handler(text, api_root + "texttags", batch=batch, auth=auth, **kwargs) diff --git a/indicoio/utils/__init__.py b/indicoio/utils/__init__.py index c04e378..fb45e0c 100644 --- a/indicoio/utils/__init__.py +++ b/indicoio/utils/__init__.py @@ -26,8 +26,9 @@ def api_handler(arg, url, batch=False, auth=None, **kwargs): json_data = json.dumps(data) if batch: url += "/batch" - if not auth: - auth = auth_query() + # if not auth: + # auth = auth_query() + print auth response = requests.post(url, data=json_data, headers=JSON_HEADERS, auth=auth).json() results = response.get('results', False) if results is False: diff --git a/tests/remote/test_remote.py b/tests/remote/test_remote.py index 43f97f7..dd6331d 100644 --- a/tests/remote/test_remote.py +++ b/tests/remote/test_remote.py @@ -3,11 +3,40 @@ import os import numpy as np import skimage.io +from nose.plugins.skip import Skip, SkipTest 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 DIR = os.path.dirname(os.path.realpath(__file__)) +class BatchAPIRun(unittest.TestCase): + + def setUp(self): + self.username = os.getenv("INDICO_USERNAME") + self.password = os.getenv("INDICO_PASSWORD") + self.auth = (self.username, self.password) + + if not self.username or not self.password: + raise SkipTest + + def test_batch_texttags(self): + test_data = ["On Monday, president Barack Obama will be..."] + response = batch_text_tags(test_data, auth=self.auth) + self.assertTrue(isinstance(response, list)) + + def test_batch_posneg(self): + test_data = ['Worst song ever', 'Best song ever'] + response = batch_sentiment(test_data, auth=self.auth) + 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, auth=self.auth) + self.assertTrue(isinstance(response, list)) + class FullAPIRun(unittest.TestCase):