Updated api client to do automatic json parsing. Updated tests to reflect that as well
This commit is contained in:
parent
232bbd2bb7
commit
59c55ae27f
|
@ -82,7 +82,7 @@ class ApiRequest(object):
|
|||
def __call__(self, **kwargs):
|
||||
final_url = self.url.params(**kwargs).url()
|
||||
response = urllib2.urlopen(final_url).read()
|
||||
return response
|
||||
return json.loads(response)
|
||||
|
||||
class RequestProvider(object):
|
||||
""" Creates the available ApiRequest instance that can be read from
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import unittest
|
||||
import json
|
||||
from mock import MagicMock, patch
|
||||
from .. api_client import ApcUrl, ApiRequest
|
||||
|
||||
|
@ -8,14 +9,14 @@ class TestApiRequest(unittest.TestCase):
|
|||
self.assertEquals(u.name, "request_name")
|
||||
|
||||
def test_call(self):
|
||||
ret = 'ok'
|
||||
ret = json.dumps( {u'ok':u'ok'} )
|
||||
read = MagicMock()
|
||||
read.read = MagicMock(return_value=ret)
|
||||
u = '/testing'
|
||||
with patch('urllib2.urlopen') as mock_method:
|
||||
mock_method.return_value = read
|
||||
request = ApiRequest('mm', ApcUrl(u))()
|
||||
self.assertEquals(request, ret)
|
||||
self.assertEquals(request, json.loads(ret))
|
||||
mock_method.assert_called_once_with(u)
|
||||
|
||||
if __name__ == '__main__': unittest.main()
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import unittest
|
||||
import json
|
||||
from mock import patch, MagicMock
|
||||
from configobj import ConfigObj
|
||||
from .. api_client import RequestProvider
|
||||
|
@ -18,7 +19,7 @@ class TestRequestProvider(unittest.TestCase):
|
|||
self.assertTrue( meth in rp )
|
||||
|
||||
def test_notify_webstream_data(self):
|
||||
ret = 'testing'
|
||||
ret = json.dumps( {u'testing' : u'123' } )
|
||||
rp = RequestProvider(self.cfg)
|
||||
read = MagicMock()
|
||||
read.read = MagicMock(return_value=ret)
|
||||
|
@ -26,6 +27,6 @@ class TestRequestProvider(unittest.TestCase):
|
|||
mock_method.return_value = read
|
||||
response = rp.notify_webstream_data(media_id=123)
|
||||
mock_method.called_once_with(media_id=123)
|
||||
self.assertEquals(ret, response)
|
||||
self.assertEquals(json.loads(ret), response)
|
||||
|
||||
if __name__ == '__main__': unittest.main()
|
||||
|
|
Loading…
Reference in New Issue