Skip to content

Commit

Permalink
fixed a few issues and added tests. bumped package to v0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mgan59 committed Oct 7, 2011
1 parent c2fc076 commit 6de4a46
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
*.pyc
tests/test_settings_local.py
12 changes: 12 additions & 0 deletions ChangeLog
@@ -0,0 +1,12 @@
# Changelog

## 0.2 - Tests & Fixes

Added in the tests to ensure data is coming back for each api endpoint. Also added exception handling to URL open
and to simplejson.load. API calls now convert the json-string to a python dictionary.

Fixed a parameter/endpoint issue with connections

## 0.1 - Initial Release

Created first round of api endpoints and calls to get a string of json text
13 changes: 8 additions & 5 deletions eqentia_client/client.py
Expand Up @@ -7,13 +7,14 @@
Total Eqentia API Request: 1 request every 10 seconds
Identical API Requests: 1 request every 5 minutes
"""
__version__ = "0.1"
__version__ = "0.2"


import urllib
import urllib2
import sys
import logging
import simplejson

# The user agent string sent to eqentias api when making requests. If you are
# using this module in your own application, you should probably fork the library
Expand Down Expand Up @@ -45,10 +46,11 @@ def _request(self, end_point='', **kwargs):
request = urllib2.Request(url=url)
request.add_header("User-agent",USER_AGENT)
response = urllib2.urlopen(request)
json_dict = simplejson.loads(response.read())
except urllib2.URLError:
logging.error('Invalid URL for API connection')
return
return response.read()
return False
return json_dict


def headlines(self, **kwargs):
Expand All @@ -58,8 +60,9 @@ def entities(self, entity_id=None, **kwargs):
end_point = 'entity/%d' % entity_id
return self._request(end_point=end_point, **kwargs)

def connections(self, **kwargs):
return self._request(end_point='connection', **kwargs)
def connections(self, connection_id=None, **kwargs):
end_point = 'connection/%d' % connection_id
return self._request(end_point=end_point, **kwargs)

def connection_maps(self, **kwargs):
return self._request(end_point='connections_map', **kwargs)
Expand Down
Empty file added tests/__init__.py
Empty file.
85 changes: 85 additions & 0 deletions tests/test_client.py
@@ -0,0 +1,85 @@
import unittest
import logging
import test_settings
from eqentia_client.client import EqentiaRestClient

'''
Currently low level tests to ensure the API responds without Exception for each endpoint and that the
response-key in data is set to True for valid response.
In order to enable the test-harnass please define an api_token and portal in the test_settings
'''

class ClientTestCase(unittest.TestCase):

def setUp(self):
self.api_token = test_settings.api_token
self.portal = test_settings.portal
self.cl = EqentiaRestClient(api_token=self.api_token,portal=self.portal)

def test_headine(self):
print 'Running test_headline'
headlines = self.cl.headlines()
if headlines:
self.assertTrue(headlines['response'], msg='A response was returned but the field response was False')
else:
self.assertTrue(headlines, msg='The API request failed due to an exception')

def test_connections(self):
print 'Running test_connections'
connections = self.cl.connections(connection_id=50901)
if connections:
self.assertTrue(connections['response'], msg='A response was returned but the field response was False')
else:
self.assertTrue(connections, msg='The API request failed due to an exception')

def test_connection_maps(self):
print 'Running test_connection_maps'
connection_maps = self.cl.connection_maps()
if connection_maps:
self.assertTrue(connection_maps['response'], msg='A response was returned but the field response was False')
else:
self.assertTrue(connection_maps, msg='The API request failed due to an exception')

def test_curation(self):
print 'Running test_curation'
curation = self.cl.curation()
if curation:
self.assertTrue(curation['response'], msg='A response was returned but the field response was False')
else:
self.assertTrue(curation, msg='The API request failed due to an exception')

def test_news_groups(self):
print 'Running test_news_groups'
news_groups = self.cl.news_groups()
if news_groups:
self.assertTrue(news_groups['response'], msg='A response was returned but the field response was False')
else:
self.assertTrue(news_groups, msg='The API request failed due to an exception')

def test_navigation(self):
print 'Running test_navigation'
navigation = self.cl.navigation()
if navigation:
self.assertTrue(navigation['response'], msg='A response was returned but the field response was False')
else:
self.assertTrue(navigation, msg='The API request failed due to an exception')

def test_hot_companies(self):
print 'Running test_hot_companies'
hot_companies = self.cl.hot_companies()
if hot_companies:
self.assertTrue(hot_companies['response'], msg='A response was returned but the field response was False')
else:
self.assertTrue(hot_companies, msg='The API request failed due to an exception')

def test_hot_connections(self):
print 'Running test_hot_connections'
hot_connections = self.cl.hot_connections()
if hot_connections:
self.assertTrue(hot_connections['response'], msg='A response was returned but the field response was False')
else:
self.assertTrue(hot_connections, msg='The API request failed due to an exception')

if __name__ == '__main__':
unittest.main()
7 changes: 7 additions & 0 deletions tests/test_settings.py
@@ -0,0 +1,7 @@
# Import local settings if there are any
# create your own local settings or put your api/portal here
try:
from test_settings_local import *
except ImportError:
api_token = 'api_token_here'
portal = 'portal_here'

0 comments on commit 6de4a46

Please sign in to comment.