Updated api client to do automatic json parsing. Updated tests to reflect that as well

This commit is contained in:
Rudi Grinberg 2012-10-30 15:19:51 -04:00
parent 232bbd2bb7
commit 59c55ae27f
3 changed files with 7 additions and 5 deletions

View file

@ -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()